[PATCH] Object: Prepend __imp_ when mangling a dllimport symbol in IRObjectFile.

Peter Collingbourne peter at pcc.me.uk
Thu Jun 11 13:29:13 PDT 2015


Hi rnk,

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.

http://reviews.llvm.org/D10400

Files:
  lib/Object/IRObjectFile.cpp
  test/CodeGen/X86/dllimport.ll
  test/Object/dllimport.ll

Index: lib/Object/IRObjectFile.cpp
===================================================================
--- lib/Object/IRObjectFile.cpp
+++ lib/Object/IRObjectFile.cpp
@@ -198,6 +198,9 @@
     return std::error_code();
   }
 
+  if (GV->hasDLLImportStorageClass())
+    OS << "__imp_";
+
   if (Mang)
     Mang->getNameWithPrefix(OS, GV, false);
   else
Index: test/CodeGen/X86/dllimport.ll
===================================================================
--- test/CodeGen/X86/dllimport.ll
+++ test/CodeGen/X86/dllimport.ll
@@ -57,3 +57,7 @@
 
   ret void
 }
+
+; CHECK: _fp:
+; CHECK-NEXT: .long _fun
+ at fp = constant void ()* @fun
Index: test/Object/dllimport.ll
===================================================================
--- /dev/null
+++ test/Object/dllimport.ll
@@ -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()
+ at v = external dllimport global i32
+
+define void @g() {
+  call void @f()
+  store i32 42, i32* @v
+  ret void
+}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10400.27540.patch
Type: text/x-patch
Size: 1153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150611/79a38474/attachment.bin>


More information about the llvm-commits mailing list