[clang] [llvm] [BPF] Load a 32-bit relocated enum value with a 32-bit immediate (PR #246702)

via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 3 21:19:06 PST 2026


================
@@ -1062,15 +1064,18 @@ DIType *BPFAbstractMemberAccess::computeTypeAccess(CallInst *Call,
 
 static GlobalVariable *getOrCreateAmaGlobal(Module &M, DIType *Root,
                                             IntegerType *ValueType,
-                                            StringRef RelocSuffix) {
+                                            StringRef RelocSuffix,
+                                            StringRef Imm32) {
   const std::string Prefix = ("llvm." + Root->getName()).str();
----------------
4ast wrote:

The attribute is not part of the name, so two modules can use one name for two different insns. With `clang -O2 -g -emit-llvm` for each file:

```
  step                  global llvm.E:11:10$0
  --------------------  --------------------------------------
  a.c: return N;        has btf_enum_value_imm32="signed"
  b.c: explicit call    has no btf_enum_value_imm32
  llvm-link a.bc b.bc   one global, attributes come from a.bc
  llc                   b.c gets r0 = 10 instead of r0 = 10 ll
```

`bpf_core_enum_value()` in b.c then loses the upper 32 bits of the target value. can we put `Imm32` into the name ? Then the compare in the loop below can go.

I never compiled this change:

```suggestion
  std::string Prefix = ("llvm." + Root->getName()).str();
  if (!Imm32.empty())
    Prefix += ("." + Imm32).str();
```

https://github.com/llvm/llvm-project/pull/246702


More information about the cfe-commits mailing list