[clang] [llvm] [BPF] Fix linking issues in static map initializers (PR #91310)

via llvm-commits llvm-commits at lists.llvm.org
Sat May 18 19:03:25 PDT 2024


================
@@ -1950,8 +1950,22 @@ ConstantLValueEmitter::tryEmitBase(const APValue::LValueBase &base) {
     if (D->hasAttr<WeakRefAttr>())
       return CGM.GetWeakRefReference(D).getPointer();
 
-    if (auto FD = dyn_cast<FunctionDecl>(D))
-      return CGM.GetAddrOfFunction(FD);
+    if (auto FD = dyn_cast<FunctionDecl>(D)) {
+      auto *C = CGM.GetAddrOfFunction(FD);
+
+      // we don't normally emit debug info for extern fns referenced via
+      // variable initialisers; BPF needs it since it generates BTF from
+      // debug info and bpftool demands BTF for every symbol linked
+      if (CGM.getTarget().getTriple().isBPF() && FD->getStorageClass() == SC_Extern) {
----------------
yonghong-song wrote:

Thanks @mejedi I think we do not need to worry about cases where external functions are in the code but removed by optimizer later as this should not that frequent. Your patch looks good to me, which follows what we did for VarDecl so adding FunctionDecl is a natural addition. BPF side of the change looks good to me too. @efriedma-quic could you take a look as well?

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


More information about the llvm-commits mailing list