[lld] 603db74 - [LLD][COFF] Preserve all attributes from forwarding exports from parsed .def files. (#86564)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 26 05:18:13 PDT 2024


Author: Jacek Caban
Date: 2024-03-26T13:18:09+01:00
New Revision: 603db7425ffa96915854f425b027cc8403ab333d

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

LOG: [LLD][COFF] Preserve all attributes from forwarding exports from parsed .def files. (#86564)

It's similar to #86535, but for export specified in .def files.

Added: 
    

Modified: 
    lld/COFF/Driver.cpp
    lld/test/COFF/export.test

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 1b075389325a91..181492913c0d98 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1032,19 +1032,18 @@ void LinkerDriver::parseModuleDefs(StringRef path) {
 
   for (COFFShortExport e1 : m.Exports) {
     Export e2;
-    // In simple cases, only Name is set. Renamed exports are parsed
-    // 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.
+    // Renamed exports are parsed 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.empty() && e1.ExtName != e1.Name &&
         StringRef(e1.Name).contains('.')) {
       e2.name = saver().save(e1.ExtName);
       e2.forwardTo = saver().save(e1.Name);
-      ctx.config.exports.push_back(e2);
-      continue;
+    } else {
+      e2.name = saver().save(e1.Name);
+      e2.extName = saver().save(e1.ExtName);
     }
-    e2.name = saver().save(e1.Name);
-    e2.extName = saver().save(e1.ExtName);
     e2.aliasTarget = saver().save(e1.AliasTarget);
     e2.ordinal = e1.Ordinal;
     e2.noname = e1.Noname;

diff  --git a/lld/test/COFF/export.test b/lld/test/COFF/export.test
index b91fdcfeebb0aa..041b328dec9ca7 100644
--- a/lld/test/COFF/export.test
+++ b/lld/test/COFF/export.test
@@ -104,6 +104,11 @@ SYMTAB-FWD-PRIV-NOT:  __imp_foo
 SYMTAB-FWD-PRIV-NEXT: exportfn3 in export.test.tmp-fwd-priv
 SYMTAB-FWD-PRIV-NOT:  foo
 
+# RUN: echo "EXPORTS foo=kernel32.foobar DATA PRIVATE" > %t-fwd-priv.def
+# RUN: lld-link /out:%t-fwd-priv-def.dll /dll %t.obj /def:%t-fwd-priv.def
+# RUN: llvm-objdump -p %t-fwd-priv-def.dll | FileCheck --check-prefix=FORWARDER %s
+# RUN: llvm-nm -M %t-fwd-priv-def.lib | FileCheck --check-prefix=SYMTAB-FWD-PRIV %s
+
 # RUN: lld-link /out:%t-fwd-ord.dll /dll %t.obj /export:foo=kernel32.foobar, at 3,NONAME
 # RUN: llvm-objdump -p %t-fwd-ord.dll | FileCheck --check-prefix=FORWARDER-ORD %s
 # RUN: llvm-nm -M %t-fwd-ord.lib | FileCheck --check-prefix=SYMTAB-FWD %s
@@ -115,6 +120,11 @@ FORWARDER-ORD-NEXT:  Ordinal      RVA  Name
 FORWARDER-ORD-NEXT:        3           (forwarded to kernel32.foobar)
 FORWARDER-ORD-NEXT:        4   0x1010  exportfn3
 
+# RUN: echo "EXPORTS foo=kernel32.foobar @3 NONAME" > %t-fwd-ord.def
+# RUN: lld-link /out:%t-fwd-ord-def.dll /dll %t.obj /def:%t-fwd-ord.def
+# RUN: llvm-objdump -p %t-fwd-ord-def.dll | FileCheck --check-prefix=FORWARDER-ORD %s
+# RUN: llvm-nm -M %t-fwd-ord-def.lib | FileCheck --check-prefix=SYMTAB-FWD %s
+
 # RUN: lld-link /out:%t.dll /dll %t.obj /merge:.rdata=.text /export:exportfn1 /export:exportfn2
 # RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=MERGE --match-full-lines %s
 


        


More information about the llvm-commits mailing list