[COFF] Avoid loading objects for mingw autoimport, when a defined alias exists
authorMartin Storsjo <martin@martin.st>
Fri, 2 Aug 2019 11:02:34 +0000 (11:02 +0000)
committerMartin Storsjo <martin@martin.st>
Fri, 2 Aug 2019 11:02:34 +0000 (11:02 +0000)
This avoids a spurious and confusing log message in cases where
both e.g. "alias" and "__imp_alias" exist.

Differential Revision: https://reviews.llvm.org/D65598

llvm-svn: 367673

lld/COFF/SymbolTable.cpp
lld/test/COFF/Inputs/alias-implib.lib [new file with mode: 0644]
lld/test/COFF/alias-implib.s [new file with mode: 0644]

index 415da9da8ab753de2e2a5a567a7634b3165b5e25..13220ed498918da0e05be30919693675ad665bcb 100644 (file)
@@ -185,6 +185,8 @@ void SymbolTable::loadMinGWAutomaticImports() {
       continue;
     if (!sym->isUsedInRegularObj)
       continue;
+    if (undef->getWeakAlias())
+      continue;
 
     StringRef name = undef->getName();
 
diff --git a/lld/test/COFF/Inputs/alias-implib.lib b/lld/test/COFF/Inputs/alias-implib.lib
new file mode 100644 (file)
index 0000000..7bc18d0
Binary files /dev/null and b/lld/test/COFF/Inputs/alias-implib.lib differ
diff --git a/lld/test/COFF/alias-implib.s b/lld/test/COFF/alias-implib.s
new file mode 100644 (file)
index 0000000..22c0895
--- /dev/null
@@ -0,0 +1,23 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-mingw32 -o %t.o %s
+# RUN: lld-link -lldmingw -entry:main -out:%t.exe %t.o %S/Inputs/alias-implib.lib -verbose 2>&1 | FileCheck %s
+
+# Check that the undefined (weak) alias symbol (with an existing lazy
+# __imp_alias) doesn't trigger trying to load __imp_alias for autoimport,
+# when the weak alias target actually does exist.
+
+# CHECK-NOT: Loading lazy{{.*}}for automatic import
+
+    .text
+    .globl main
+main:
+    call alias
+    ret
+
+# alias-implib.lib was created with "llvm-dlltool -m i386:x86-64
+# -l alias-implib.lib -d alias-implib.def" with this def snippet:
+# LIBRARY lib.dll
+# EXPORTS
+# realfunc
+# alias == realfunc