Skip to content

Commit 000402e

Browse files
committed
[LLD][COFF] Preserve all attributes from forwarding exports from parsed .def files.
1 parent 9d242f5 commit 000402e

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

lld/COFF/Driver.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,19 +1032,18 @@ void LinkerDriver::parseModuleDefs(StringRef path) {
10321032

10331033
for (COFFShortExport e1 : m.Exports) {
10341034
Export e2;
1035-
// In simple cases, only Name is set. Renamed exports are parsed
1036-
// and set as "ExtName = Name". If Name has the form "OtherDll.Func",
1037-
// it shouldn't be a normal exported function but a forward to another
1038-
// DLL instead. This is supported by both MS and GNU linkers.
1035+
// Renamed exports are parsed and set as "ExtName = Name". If Name has
1036+
// the form "OtherDll.Func", it shouldn't be a normal exported
1037+
// function but a forward to another DLL instead. This is supported
1038+
// by both MS and GNU linkers.
10391039
if (!e1.ExtName.empty() && e1.ExtName != e1.Name &&
10401040
StringRef(e1.Name).contains('.')) {
10411041
e2.name = saver().save(e1.ExtName);
10421042
e2.forwardTo = saver().save(e1.Name);
1043-
ctx.config.exports.push_back(e2);
1044-
continue;
1043+
} else {
1044+
e2.name = saver().save(e1.Name);
1045+
e2.extName = saver().save(e1.ExtName);
10451046
}
1046-
e2.name = saver().save(e1.Name);
1047-
e2.extName = saver().save(e1.ExtName);
10481047
e2.aliasTarget = saver().save(e1.AliasTarget);
10491048
e2.ordinal = e1.Ordinal;
10501049
e2.noname = e1.Noname;

lld/test/COFF/export.test

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,27 @@ SYMTAB-FWD-PRIV-NOT: __imp_foo
104104
SYMTAB-FWD-PRIV: exportfn3 in export.test.tmp-fwd-priv
105105
SYMTAB-FWD-PRIV-NOT: foo
106106

107+
# RUN: echo "EXPORTS foo=kernel32.foobar DATA PRIVATE" > %t-fwd-priv.def
108+
# RUN: lld-link /out:%t-fwd-priv-def.dll /dll %t.obj /def:%t-fwd-priv.def
109+
# RUN: llvm-objdump -p %t-fwd-priv-def.dll | FileCheck --check-prefix=FORWARDER %s
110+
# RUN: llvm-nm -M %t-fwd-priv-def.lib | FileCheck --check-prefix=SYMTAB-FWD-PRIV %s
111+
107112
# RUN: lld-link /out:%t-fwd-ord.dll /dll %t.obj /export:foo=kernel32.foobar,@3,NONAME
108113
# RUN: llvm-objdump -p %t-fwd-ord.dll | FileCheck --check-prefix=FORWARDER-ORD %s
109114
# RUN: llvm-nm -M %t-fwd-ord.lib | FileCheck --check-prefix=SYMTAB-FWD %s
110115

111116
FORWARDER-ORD: Export Table:
112-
FORWARDER-ORD: DLL name: export.test.tmp-fwd-ord.dll
117+
FORWARDER-ORD: DLL name: export.test.tmp-fwd-ord
113118
FORWARDER-ORD: Ordinal base: 3
114119
FORWARDER-ORD: Ordinal RVA Name
115120
FORWARDER-ORD: 3 (forwarded to kernel32.foobar)
116121
FORWARDER-ORD: 4 0x1010 exportfn3
117122

123+
# RUN: echo "EXPORTS foo=kernel32.foobar @3 NONAME" > %t-fwd-ord.def
124+
# RUN: lld-link /out:%t-fwd-ord-def.dll /dll %t.obj /def:%t-fwd-ord.def
125+
# RUN: llvm-objdump -p %t-fwd-ord-def.dll | FileCheck --check-prefix=FORWARDER-ORD %s
126+
# RUN: llvm-nm -M %t-fwd-ord-def.lib | FileCheck --check-prefix=SYMTAB-FWD %s
127+
118128
# RUN: lld-link /out:%t.dll /dll %t.obj /merge:.rdata=.text /export:exportfn1 /export:exportfn2
119129
# RUN: llvm-objdump -p %t.dll | FileCheck --check-prefix=MERGE --match-full-lines %s
120130

0 commit comments

Comments
 (0)