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

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Sun May 12 11:17:40 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) {
----------------
efriedma-quic wrote:

Looking at the code again, I guess the ultimate question is whether we want to emit debug info for all external functions/variables, or only functions/variables that are actually referenced.

If we want all functions/variables, we want to extend ExternalDeclarations to include them.  Maybe put the code in Sema::ActOnFunctionDeclarator, or something like that.

If you just want referenced functions/variables, probably the code should be in GetAddrOfFunction() (and something similar for variables).

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


More information about the cfe-commits mailing list