[lld] e694180 - [ELF] Optimize --wrap to only check non-local symbols

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 24 12:29:05 PST 2021


Author: Fangrui Song
Date: 2021-12-24T12:28:59-08:00
New Revision: e694180033d1e9d6e215bbc2f956092d30c1e3cd

URL: https://github.com/llvm/llvm-project/commit/e694180033d1e9d6e215bbc2f956092d30c1e3cd
DIFF: https://github.com/llvm/llvm-project/commit/e694180033d1e9d6e215bbc2f956092d30c1e3cd.diff

LOG: [ELF] Optimize --wrap to only check non-local symbols

Added: 
    

Modified: 
    lld/ELF/Driver.cpp
    lld/ELF/InputFiles.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 7d01b7f33dec..e4d3e1d50b0f 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -2120,11 +2120,10 @@ static void redirectSymbols(ArrayRef<WrappedSymbol> wrapped) {
     return;
 
   // Update pointers in input files.
-  parallelForEach(objectFiles, [&](InputFile *file) {
-    MutableArrayRef<Symbol *> syms = file->getMutableSymbols();
-    for (size_t i = 0, e = syms.size(); i != e; ++i)
-      if (Symbol *s = map.lookup(syms[i]))
-        syms[i] = s;
+  parallelForEach(objectFiles, [&](ELFFileBase *file) {
+    for (Symbol *&sym : file->getMutableGlobalSymbols())
+      if (Symbol *s = map.lookup(sym))
+        sym = s;
   });
 
   // Update pointers in the symbol table.

diff  --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index a031ef94c14d..6111df521840 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -91,9 +91,7 @@ class InputFile {
 
   // Returns object file symbols. It is a runtime error to call this
   // function on files of other types.
-  ArrayRef<Symbol *> getSymbols() { return getMutableSymbols(); }
-
-  MutableArrayRef<Symbol *> getMutableSymbols() {
+  ArrayRef<Symbol *> getSymbols() const {
     assert(fileKind == BinaryKind || fileKind == ObjKind ||
            fileKind == BitcodeKind);
     return symbols;
@@ -186,6 +184,10 @@ class ELFFileBase : public InputFile {
   ArrayRef<Symbol *> getGlobalSymbols() {
     return llvm::makeArrayRef(symbols).slice(firstGlobal);
   }
+  MutableArrayRef<Symbol *> getMutableGlobalSymbols() {
+    return llvm::makeMutableArrayRef(symbols.data(), symbols.size())
+        .slice(firstGlobal);
+  }
 
   template <typename ELFT> typename ELFT::SymRange getELFSyms() const {
     return typename ELFT::SymRange(


        


More information about the llvm-commits mailing list