[lld] Don't create hints-section if Hint/Name Table is empty
authorRui Ueyama <ruiu@google.com>
Wed, 9 Oct 2019 06:48:24 +0000 (06:48 +0000)
committerRui Ueyama <ruiu@google.com>
Wed, 9 Oct 2019 06:48:24 +0000 (06:48 +0000)
Fixes assert in addLinkerModuleCoffGroup() when using by-ordinal imports
only.

Patch by Stefan Schmidt.

Differential revision: https://reviews.llvm.org/D68352

llvm-svn: 374140

lld/COFF/Writer.cpp
lld/test/COFF/Inputs/ordinal-only-implib.def [new file with mode: 0644]
lld/test/COFF/imports-ordinal-only.s [new file with mode: 0644]

index a98af43..8387361 100644 (file)
@@ -743,7 +743,8 @@ void Writer::addSyntheticIdata() {
   add(".idata$2", idata.dirs);
   add(".idata$4", idata.lookups);
   add(".idata$5", idata.addresses);
-  add(".idata$6", idata.hints);
+  if (!idata.hints.empty())
+    add(".idata$6", idata.hints);
   add(".idata$7", idata.dllNames);
 }
 
diff --git a/lld/test/COFF/Inputs/ordinal-only-implib.def b/lld/test/COFF/Inputs/ordinal-only-implib.def
new file mode 100644 (file)
index 0000000..d913ef4
--- /dev/null
@@ -0,0 +1,3 @@
+LIBRARY test.dll
+EXPORTS
+ByOrdinalFunction @ 1 NONAME
diff --git a/lld/test/COFF/imports-ordinal-only.s b/lld/test/COFF/imports-ordinal-only.s
new file mode 100644 (file)
index 0000000..d4f5c44
--- /dev/null
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+#
+# RUN: llvm-dlltool -k -m i386 --input-def %p/Inputs/ordinal-only-implib.def --output-lib %t-implib.a
+# RUN: llvm-mc -triple=i386-pc-win32 %s -filetype=obj -o %t.obj
+# RUN: lld-link -out:%t.exe -entry:main -subsystem:console -safeseh:no -debug %t.obj %t-implib.a
+# RUN: llvm-objdump -private-headers %t.exe | FileCheck --match-full-lines %s
+
+.text
+.global _main
+_main:
+call _ByOrdinalFunction
+ret
+
+# CHECK: The Import Tables:
+# CHECK:     DLL Name: test.dll
+# CHECK-NEXT:     Hint/Ord  Name
+# CHECK-NEXT:            1
+# CHECK-EMPTY: