[lld] [ELF] Fix unnecessary inclusion of unreferenced provide symbols (PR #84512)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 25 13:11:47 PDT 2024


================
@@ -1518,3 +1513,50 @@ void LinkerScript::checkFinalScriptConditions() const {
       checkMemoryRegion(lmaRegion, sec, sec->getLMA());
   }
 }
+
+// Add symbols referred by the provide symbol to the symbol table.
+// This function must only be called for provide symbols that should be added
+// to the link.
+static void
+addProvideSymReferences(StringRef provideSym,
+                        llvm::StringSet<> &addedRefsFromProvideSym) {
+  assert(LinkerScript::shouldAddProvideSym(provideSym) &&
----------------
partaror wrote:

This static function is recursive. Lambdas cannot be recursive without using more complicated mechanism such as `std::function` or adding an explicit parameter that would refer to the lambda in the lambda call operator. These techniques are explained here: [Recursive lambda functions in C++14](https://stackoverflow.com/questions/18085331/recursive-lambda-functions-in-c14)

Please give your suggestion regarding what should we do here. `std::function` has performance cost due to the use of type-erasure and passing the lambda to the lambda call (for ex, `L(L, x, ...)`) leads to (slightly) ugly code.

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


More information about the llvm-commits mailing list