[lld] r242078 - COFF: Fix x86 delay-load helper function name.
Rui Ueyama
ruiu at google.com
Mon Jul 13 15:31:45 PDT 2015
Author: ruiu
Date: Mon Jul 13 17:31:45 2015
New Revision: 242078
URL: http://llvm.org/viewvc/llvm-project?rev=242078&view=rev
Log:
COFF: Fix x86 delay-load helper function name.
If /delayload option is given, we have to resolve __delayLoadHelper2
since the function is the dynamic loader to delay-load DLLs.
The function name is mangled in x86 as ___delayLoadHelper2 at 8.
Added:
lld/trunk/test/COFF/delayimports32.test
Modified:
lld/trunk/COFF/Config.h
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/Writer.cpp
Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=242078&r1=242077&r2=242078&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Mon Jul 13 17:31:45 2015
@@ -70,6 +70,7 @@ struct Configuration {
StringRef Implib;
std::vector<Export> Exports;
std::set<std::string> DelayLoads;
+ Undefined *DelayLoadHelper = nullptr;
// Used for /opt:icf
bool ICF = false;
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=242078&r1=242077&r2=242078&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Mon Jul 13 17:31:45 2015
@@ -418,12 +418,6 @@ bool LinkerDriver::link(llvm::ArrayRef<c
}
}
- // Handle /delayload
- for (auto *Arg : Args.filtered(OPT_delayload)) {
- Config->DelayLoads.insert(StringRef(Arg->getValue()).lower());
- addUndefined("__delayLoadHelper2");
- }
-
// Handle /failifmismatch
for (auto *Arg : Args.filtered(OPT_failifmismatch))
if (checkFailIfMismatch(Arg->getValue()))
@@ -598,6 +592,16 @@ bool LinkerDriver::link(llvm::ArrayRef<c
return false;
}
+ // Handle /delayload
+ for (auto *Arg : Args.filtered(OPT_delayload)) {
+ Config->DelayLoads.insert(StringRef(Arg->getValue()).lower());
+ if (Config->is64()) {
+ Config->DelayLoadHelper = addUndefined("__delayLoadHelper2");
+ } else {
+ Config->DelayLoadHelper = addUndefined("___delayLoadHelper2 at 8");
+ }
+ }
+
Symtab.addAbsolute(mangle("__ImageBase"), Config->ImageBase);
// Read as much files as we can from directives sections.
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=242078&r1=242077&r2=242078&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Mon Jul 13 17:31:45 2015
@@ -248,8 +248,7 @@ void Writer::createImportTables() {
Sec->addChunk(C);
}
if (!DelayIdata.empty()) {
- Symbol *Sym = Symtab->find("__delayLoadHelper2");
- Defined *Helper = cast<Defined>(Sym->Body);
+ Defined *Helper = cast<Defined>(Config->DelayLoadHelper->repl());
DelayIdata.create(Helper);
OutputSection *Sec = createSection(".didat");
for (Chunk *C : DelayIdata.getChunks())
Added: lld/trunk/test/COFF/delayimports32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/delayimports32.test?rev=242078&view=auto
==============================================================================
--- lld/trunk/test/COFF/delayimports32.test (added)
+++ lld/trunk/test/COFF/delayimports32.test Mon Jul 13 17:31:45 2015
@@ -0,0 +1,15 @@
+# RUN: yaml2obj < %p/Inputs/hello32.yaml > %t.obj
+# RUN: lld -flavor link2 %t.obj %p/Inputs/std32.lib /subsystem:console \
+# RUN: /entry:main at 0 /alternatename:___delayLoadHelper2 at 8=main at 0 /out:%t.exe
+# RUN: llvm-readobj -coff-imports %t.exe | FileCheck %s
+
+CHECK: Format: COFF-i386
+CHECK: Arch: i386
+CHECK: AddressSize: 32bit
+CHECK: Import {
+CHECK: Name: std32.dll
+CHECK: ImportLookupTableRVA: 0x3028
+CHECK: ImportAddressTableRVA: 0x3034
+CHECK: Symbol: ExitProcess (0)
+CHECK: Symbol: MessageBoxA (1)
+CHECK: }
More information about the llvm-commits
mailing list