Skip to content

Commit eabc885

Browse files
authored
[BPF] make __BPF_FEATURE_MAY_GOTO available for cpuv1 (#108071)
For some reason `__BPF_FEATURE_MAY_GOTO` is available for CPUs v{2,3,4} but is not available for CPU v1. This limitation is arbitrary: - the instruction is never produced by LLVM backend; - on Linux Kernel side this instruction is available in kernels that also support CPUv4. Hence, it is more consistent to either always allow `__BPF_FEATURE_MAY_GOTO` or only allow it for CPUv4.
1 parent b75174d commit eabc885

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Basic/Targets/BPF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
3737
}
3838

3939
Builder.defineMacro("__BPF_FEATURE_ADDR_SPACE_CAST");
40+
Builder.defineMacro("__BPF_FEATURE_MAY_GOTO");
4041

4142
if (CPU.empty())
4243
CPU = "v3";
@@ -48,7 +49,6 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
4849

4950
std::string CpuVerNumStr = CPU.substr(1);
5051
Builder.defineMacro("__BPF_CPU_VERSION__", CpuVerNumStr);
51-
Builder.defineMacro("__BPF_FEATURE_MAY_GOTO");
5252

5353
int CpuVerNum = std::stoi(CpuVerNumStr);
5454
if (CpuVerNum >= 2)

clang/test/Preprocessor/bpf-predefined-macros.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ int s;
6464
#ifdef __BPF_FEATURE_ADDR_SPACE_CAST
6565
int t;
6666
#endif
67+
#ifdef __BPF_FEATURE_MAY_GOTO
68+
int u;
69+
#endif
6770

6871
// CHECK: int b;
6972
// CHECK: int c;
@@ -98,6 +101,11 @@ int t;
98101
// CPU_V3: int t;
99102
// CPU_V4: int t;
100103

104+
// CPU_V1: int u;
105+
// CPU_V2: int u;
106+
// CPU_V3: int u;
107+
// CPU_V4: int u;
108+
101109
// CPU_GENERIC: int g;
102110

103111
// CPU_PROBE: int f;

0 commit comments

Comments
 (0)