Skip to content

Commit

Permalink
[BPF] make __BPF_FEATURE_MAY_GOTO available for cpuv1 (llvm#108071)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eddyz87 authored Sep 24, 2024
1 parent b75174d commit eabc885
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/BPF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
}

Builder.defineMacro("__BPF_FEATURE_ADDR_SPACE_CAST");
Builder.defineMacro("__BPF_FEATURE_MAY_GOTO");

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

std::string CpuVerNumStr = CPU.substr(1);
Builder.defineMacro("__BPF_CPU_VERSION__", CpuVerNumStr);
Builder.defineMacro("__BPF_FEATURE_MAY_GOTO");

int CpuVerNum = std::stoi(CpuVerNumStr);
if (CpuVerNum >= 2)
Expand Down
8 changes: 8 additions & 0 deletions clang/test/Preprocessor/bpf-predefined-macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ int s;
#ifdef __BPF_FEATURE_ADDR_SPACE_CAST
int t;
#endif
#ifdef __BPF_FEATURE_MAY_GOTO
int u;
#endif

// CHECK: int b;
// CHECK: int c;
Expand Down Expand Up @@ -98,6 +101,11 @@ int t;
// CPU_V3: int t;
// CPU_V4: int t;

// CPU_V1: int u;
// CPU_V2: int u;
// CPU_V3: int u;
// CPU_V4: int u;

// CPU_GENERIC: int g;

// CPU_PROBE: int f;

0 comments on commit eabc885

Please sign in to comment.