[lld] ed0a57f - [LLD] [COFF] Fix def file exporting of symbols containing periods

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Sun May 10 13:30:41 PDT 2020


Author: Martin Storsjö
Date: 2020-05-10T23:30:14+03:00
New Revision: ed0a57f753a312bc0433480ef0bfad338e56b19e

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

LOG: [LLD] [COFF] Fix def file exporting of symbols containing periods

This fixes an accidental breakage of exporting symbols using def
files, when the symbol name contains a period, since commit
0ca06f7950e5, mixing up a symbol name containing a period with
the case of exporting a symbol as a forward to another dll.

Differential Revision: https://reviews.llvm.org/D79619

Added: 
    lld/test/COFF/export-tricky-names.s

Modified: 
    lld/COFF/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 5d99a4cd17cf..07132345f135 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -848,7 +848,8 @@ static void parseModuleDefs(StringRef path) {
     // and set as "ExtName = Name". If Name has the form "OtherDll.Func",
     // it shouldn't be a normal exported function but a forward to another
     // DLL instead. This is supported by both MS and GNU linkers.
-    if (e1.ExtName != e1.Name && StringRef(e1.Name).contains('.')) {
+    if (!e1.ExtName.empty() && e1.ExtName != e1.Name &&
+        StringRef(e1.Name).contains('.')) {
       e2.name = saver.save(e1.ExtName);
       e2.forwardTo = saver.save(e1.Name);
       config->exports.push_back(e2);

diff  --git a/lld/test/COFF/export-tricky-names.s b/lld/test/COFF/export-tricky-names.s
new file mode 100644
index 000000000000..bd39d68c637d
--- /dev/null
+++ b/lld/test/COFF/export-tricky-names.s
@@ -0,0 +1,29 @@
+# REQUIRES: x86
+
+# RUN: echo -e "EXPORTS\n  foo.bar" > %t.def
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc -defsym drectve=0 %s -o %t.obj
+# RUN: lld-link -entry:dllmain -dll -def:%t.def %t.obj -out:%t.1.dll
+# RUN: llvm-readobj --coff-exports %t.1.dll | FileCheck %s
+
+# RUN: lld-link -entry:dllmain -dll %t.obj -out:%t.2.dll -export:foo.bar
+# RUN: llvm-readobj --coff-exports %t.2.dll | FileCheck %s
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-windows-msvc -defsym drectve=1 %s -o %t.drectve.obj
+# RUN: lld-link -entry:dllmain -dll %t.drectve.obj -out:%t.3.dll
+# RUN: llvm-readobj --coff-exports %t.3.dll | FileCheck %s
+
+# CHECK: Name: foo.bar
+
+        .text
+        .globl  dllmain
+        .globl  foo.bar
+dllmain:
+        ret
+foo.bar:
+        ret
+
+.if drectve==1
+        .section .drectve
+        .ascii "-export:foo.bar"
+.endif


        


More information about the llvm-commits mailing list