[clang] [BPF] make __BPF_FEATURE_MAY_GOTO available for cpuv1 (PR #108071)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 10 12:35:29 PDT 2024
https://github.com/eddyz87 updated https://github.com/llvm/llvm-project/pull/108071
>From 170f6a604b041bb33c5089dd84fd26de7bd2292e Mon Sep 17 00:00:00 2001
From: Eduard Zingerman <eddyz87 at gmail.com>
Date: Tue, 10 Sep 2024 11:11:58 -0700
Subject: [PATCH 1/2] [BPF] make __BPF_FEATURE_MAY_GOTO available for cpuv1
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.
---
clang/lib/Basic/Targets/BPF.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Basic/Targets/BPF.cpp b/clang/lib/Basic/Targets/BPF.cpp
index a94ceee5a6a5e7..931f407ecb0d7e 100644
--- a/clang/lib/Basic/Targets/BPF.cpp
+++ b/clang/lib/Basic/Targets/BPF.cpp
@@ -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";
@@ -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)
>From 5c025e2fec3288f55e7ebb537356b49052b0ce63 Mon Sep 17 00:00:00 2001
From: Eduard Zingerman <eddyz87 at gmail.com>
Date: Tue, 10 Sep 2024 12:33:02 -0700
Subject: [PATCH 2/2] [BPF] update bpf-predefined-macros.c to test
__BPF_FEATURE_MAY_GOTO
<commit message would be squashed and is not relevant>
---
clang/test/Preprocessor/bpf-predefined-macros.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/clang/test/Preprocessor/bpf-predefined-macros.c b/clang/test/Preprocessor/bpf-predefined-macros.c
index 360b9330b75fef..8c2143f767c40c 100644
--- a/clang/test/Preprocessor/bpf-predefined-macros.c
+++ b/clang/test/Preprocessor/bpf-predefined-macros.c
@@ -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;
@@ -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;
More information about the cfe-commits
mailing list