[lld] 49279ca - [ELF] Improve --export-dynamic-symbol performance by checking whether wildcard is really used

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 17 17:13:14 PDT 2020


Author: Fangrui Song
Date: 2020-06-17T17:12:10-07:00
New Revision: 49279ca160183c1567e2637f88f3e92eb458c3e7

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

LOG: [ELF] Improve --export-dynamic-symbol performance by checking whether wildcard is really used

A hasWildcard pattern iterates over symVector, which can be slow when there
are many --export-dynamic-symbol. In optimistic cases, most patterns don't use
a wildcard character. hasWildcard: false can avoid a symbol table iteration.

While here, add two tests using `[` and `?`, respectively.

Added: 
    

Modified: 
    lld/ELF/Driver.cpp
    lld/ELF/ScriptParser.cpp
    lld/ELF/ScriptParser.h
    lld/test/ELF/export-dynamic-symbol.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 78a60147613d..7430e0d1099d 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1188,7 +1188,8 @@ static void readConfigs(opt::InputArgList &args) {
   // -Bsymbolic-functions (if STT_FUNC), --dynamic-list.
   for (auto *arg : args.filtered(OPT_export_dynamic_symbol))
     config->dynamicList.push_back(
-        {arg->getValue(), /*isExternCpp=*/false, /*hasWildcard=*/true});
+        {arg->getValue(), /*isExternCpp=*/false,
+         /*hasWildcard=*/hasWildcard(arg->getValue())});
 
   for (auto *arg : args.filtered(OPT_version_script))
     if (Optional<std::string> path = searchScript(arg->getValue())) {

diff  --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index d23a46d250e4..fea6b7a274e7 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1474,7 +1474,7 @@ void ScriptParser::readVersionDeclaration(StringRef verStr) {
     expect(";");
 }
 
-static bool hasWildcard(StringRef s) {
+bool elf::hasWildcard(StringRef s) {
   return s.find_first_of("?*[") != StringRef::npos;
 }
 

diff  --git a/lld/ELF/ScriptParser.h b/lld/ELF/ScriptParser.h
index c953fb302b9a..eed1958647f8 100644
--- a/lld/ELF/ScriptParser.h
+++ b/lld/ELF/ScriptParser.h
@@ -27,6 +27,8 @@ void readDynamicList(MemoryBufferRef mb);
 // Parses the defsym expression.
 void readDefsym(StringRef name, MemoryBufferRef mb);
 
+bool hasWildcard(StringRef s);
+
 } // namespace elf
 } // namespace lld
 

diff  --git a/lld/test/ELF/export-dynamic-symbol.s b/lld/test/ELF/export-dynamic-symbol.s
index 886a4cd59595..efd46112435e 100644
--- a/lld/test/ELF/export-dynamic-symbol.s
+++ b/lld/test/ELF/export-dynamic-symbol.s
@@ -41,8 +41,12 @@
 # RUN: llvm-objdump -d %t.preempt3 | FileCheck --check-prefix=PLT %s
 
 ## The option value is a glob.
-# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f*' %t.o -o %t.preempt4
-# RUN: llvm-objdump -d %t.preempt4 | FileCheck --check-prefix=PLT %s
+# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f*' %t.o -o - | \
+# RUN:   llvm-objdump -d - | FileCheck --check-prefix=PLT %s
+# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol '[f]o[o]' %t.o -o - | \
+# RUN:   llvm-objdump -d - | FileCheck --check-prefix=PLT %s
+# RUN: ld.lld -shared -Bsymbolic --export-dynamic-symbol 'f?o' %t.o -o - | \
+# RUN:   llvm-objdump -d - | FileCheck --check-prefix=PLT %s
 
 # PLT:       <foo at plt>
 # NOPLT-NOT: <foo at plt>


        


More information about the llvm-commits mailing list