Object: Prepend __imp_ when mangling a dllimport symbol in IRObjectFile.
authorPeter Collingbourne <peter@pcc.me.uk>
Thu, 11 Jun 2015 21:42:18 +0000 (21:42 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Thu, 11 Jun 2015 21:42:18 +0000 (21:42 +0000)
We cannot prepend __imp_ in the IR mangler because a function reference may
be emitted unmangled in a constant initializer. The linker is expected to
resolve such references to thunks. This is covered by the new test case.

Strictly speaking we ought to emit two undefined symbols, one with __imp_ and
one without, as we cannot know which symbol the final object file will refer
to. However, this would require rather intrusive changes to IRObjectFile,
and lld works fine without it for now.

This reimplements r239437, which was reverted in r239502.

Differential Revision: http://reviews.llvm.org/D10400

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239560 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/IRObjectFile.cpp
test/CodeGen/X86/dllimport.ll
test/Object/dllimport.ll [new file with mode: 0644]

index e89cb8ead36d08eca9f5336cbae008863fff2095..b3d5db85ed5283b82e3767955fcc2d66ecfdf0b3 100644 (file)
@@ -198,6 +198,9 @@ std::error_code IRObjectFile::printSymbolName(raw_ostream &OS,
     return std::error_code();
   }
 
     return std::error_code();
   }
 
+  if (GV->hasDLLImportStorageClass())
+    OS << "__imp_";
+
   if (Mang)
     Mang->getNameWithPrefix(OS, GV, false);
   else
   if (Mang)
     Mang->getNameWithPrefix(OS, GV, false);
   else
index 9db654f22712b665b13c8310dc5a02ebf3b6ee3d..34faaeb6fed7ee734a966abe52cf301cc9ae04d1 100644 (file)
@@ -57,3 +57,7 @@ define void @use() nounwind {
 
   ret void
 }
 
   ret void
 }
+
+; CHECK: _fp:
+; CHECK-NEXT: .long _fun
+@fp = constant void ()* @fun
diff --git a/test/Object/dllimport.ll b/test/Object/dllimport.ll
new file mode 100644 (file)
index 0000000..afdb456
--- /dev/null
@@ -0,0 +1,17 @@
+; RUN: llvm-as %s -o - | llvm-nm - | FileCheck %s
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; CHECK: U __imp_f
+; CHECK: U __imp_v
+; CHECK: T g
+
+declare dllimport void @f()
+@v = external dllimport global i32
+
+define void @g() {
+  call void @f()
+  store i32 42, i32* @v
+  ret void
+}