[PATCH] D70166: [LLD] [COFF] Fix automatically importing data symbols from DLLs with LTO

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 12 23:56:44 PST 2019


mstorsjo created this revision.
mstorsjo added reviewers: ruiu, rnk, inglorion.
Herald added subscribers: dexonsmith, steven_wu, hiraditya, mehdi_amini.
Herald added a project: LLVM.

This broke in 51dcb292cc002, "[lld-link] diagnose undefined symbols before LTO when possible" (very soon after the 9.0 branch, so luckily the 9.0 release is unaffected).

The code for loading objects we believe might be needed for autoimport (loadMinGWAutomaticImports()) does run before the new reportUnresolvable() function, but it had a condition to only operate on symbols from regular object files. This condition came from resolveRemainingUndefines(), but as loadMinGWAutomaticImports() now has to operate before the LTO, it has to operate on undefineds from LTO objects as well.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D70166

Files:
  lld/COFF/SymbolTable.cpp
  lld/test/COFF/autoimport-lto.ll


Index: lld/test/COFF/autoimport-lto.ll
===================================================================
--- /dev/null
+++ lld/test/COFF/autoimport-lto.ll
@@ -0,0 +1,28 @@
+; REQUIRES: x86
+
+; RUN: echo -e ".global variable\n.global DllMainCRTStartup\n.text\nDllMainCRTStartup:\nret\n.data\nvariable:\n.long 42" > %t-lib.s
+; RUN: llvm-mc -triple=x86_64-windows-gnu %t-lib.s -filetype=obj -o %t-lib.obj
+; RUN: lld-link -out:%t-lib.dll -dll -entry:DllMainCRTStartup %t-lib.obj -lldmingw -implib:%t-lib.lib
+
+; RUN: llvm-as -o %t.obj %s
+; RUN: lld-link -lldmingw -out:%t.exe -entry:entry %t.obj %t-lib.lib
+
+; RUN: llvm-readobj --coff-imports %t.exe | FileCheck -check-prefix=IMPORTS %s
+
+; IMPORTS: Import {
+; IMPORTS-NEXT: Name: autoimport-lto.ll.tmp-lib.dll
+; IMPORTS-NEXT: ImportLookupTableRVA:
+; IMPORTS-NEXT: ImportAddressTableRVA:
+; IMPORTS-NEXT: Symbol: variable (0)
+; IMPORTS-NEXT: }
+
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-w64-windows-gnu"
+
+ at variable = external global i32
+
+define i32 @entry() {
+entry:
+  %0 = load i32, i32* @variable
+  ret i32 %0
+}
Index: lld/COFF/SymbolTable.cpp
===================================================================
--- lld/COFF/SymbolTable.cpp
+++ lld/COFF/SymbolTable.cpp
@@ -227,8 +227,6 @@
     auto *undef = dyn_cast<Undefined>(sym);
     if (!undef)
       continue;
-    if (!sym->isUsedInRegularObj)
-      continue;
     if (undef->getWeakAlias())
       continue;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70166.229018.patch
Type: text/x-patch
Size: 1520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191113/9a3962b4/attachment.bin>


More information about the llvm-commits mailing list