[lld] r218943 - [PECOFF] Resolve __delayLoadHelper2 if /delayload is given

Rui Ueyama ruiu at google.com
Thu Oct 2 18:14:50 PDT 2014


Author: ruiu
Date: Thu Oct  2 20:14:50 2014
New Revision: 218943

URL: http://llvm.org/viewvc/llvm-project?rev=218943&view=rev
Log:
[PECOFF] Resolve __delayLoadHelper2 if /delayload is given

DLL delay importing is a feature to load a DLL lazily, instead of
at program start-up time.

If the feature is turned on with the /delayload flag, the linker
resolves the delay-load helper function. All function pointer table
entries for the DLL are initially pointing to the helper function.
When called, the function loads and resolves the DLL symbols using
dlopen-ish Windows system calls and then write the reuslts to the
function pointer table. The helper function is in "delayimp.lib".

Note that this feature is not completely implemented yet. LLD
also needs to emit the table that's consumed by the delay-load
helper function. That'll be done in another patch.

Added:
    lld/trunk/test/pecoff/delayimport.test
Modified:
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/lib/Driver/WinLinkOptions.td

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=218943&r1=218942&r2=218943&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Thu Oct  2 20:14:50 2014
@@ -1189,6 +1189,11 @@ bool WinLinkDriver::parse(int argc, cons
       ctx.setOutputImportLibraryPath(inputArg->getValue());
       break;
 
+    case OPT_delayload:
+      ctx.addInitialUndefinedSymbol(
+          ctx.is64Bit() ? "__delayLoadHelper2" : "___delayLoadHelper2 at 8");
+      break;
+
     case OPT_stub: {
       ArrayRef<uint8_t> contents;
       if (!readFile(ctx, inputArg->getValue(), contents)) {

Modified: lld/trunk/lib/Driver/WinLinkOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkOptions.td?rev=218943&r1=218942&r2=218943&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkOptions.td (original)
+++ lld/trunk/lib/Driver/WinLinkOptions.td Thu Oct  2 20:14:50 2014
@@ -38,6 +38,7 @@ def subsystem : P<"subsystem", "Specify
 def stub    : P<"stub", "Specify DOS stub file">;
 def opt     : P<"opt", "Control optimizations">;
 def implib  : P<"implib", "Import library name">;
+def delayload : P<"delayload", "Delay loaded DLL name">;
 
 def manifest : F<"manifest">;
 def manifest_colon : P<"manifest", "Create manifest file">;
@@ -106,7 +107,6 @@ def no_incremental : F<"incremental:no">
 def nologo : F<"nologo">;
 
 def delay : QF<"delay">;
-def delayload : QF<"delayload">;
 def errorreport : QF<"errorreport">;
 def idlout : QF<"idlout">;
 def ignore : QF<"ignore">;

Added: lld/trunk/test/pecoff/delayimport.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/delayimport.test?rev=218943&view=auto
==============================================================================
--- lld/trunk/test/pecoff/delayimport.test (added)
+++ lld/trunk/test/pecoff/delayimport.test Thu Oct  2 20:14:50 2014
@@ -0,0 +1,12 @@
+# RUN: yaml2obj %p/Inputs/vars-main.obj.yaml > %t.obj
+#
+# RUN: not lld -flavor link /out:%t1.exe /subsystem:console /entry:main \
+# RUN:   /delayload:vars.dll -- %t.obj %p/Inputs/vars.lib >& %t.log
+# RUN: FileCheck -check-prefix=X86 %s < %t.log
+#
+# RUN: not lld -flavor link /out:%t1.exe /subsystem:console /entry:main \
+# RUN:   /machine:x64 /delayload:vars.dll -- %t.obj %p/Inputs/vars.lib >& %t.log
+# RUN: FileCheck -check-prefix=X64 %s < %t.log
+
+X86: Undefined symbol: {{.*}} ___delayLoadHelper2 at 8
+X64: Undefined symbol: {{.*}} __delayLoadHelper2





More information about the llvm-commits mailing list