[lld] r218690 - [PECOFF] Fix __imp_ prefix on x64.

Rui Ueyama ruiu at google.com
Tue Sep 30 12:42:04 PDT 2014


Author: ruiu
Date: Tue Sep 30 14:42:04 2014
New Revision: 218690

URL: http://llvm.org/viewvc/llvm-project?rev=218690&view=rev
Log:
[PECOFF] Fix __imp_ prefix on x64.

"__imp_" prefix always starts with double underscores.
When I was writing the original code I misunderstood
that it's "_imp_" on x64.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
    lld/trunk/test/pecoff/localyimported.test

Modified: lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h?rev=218690&r1=218689&r2=218690&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h Tue Sep 30 14:42:04 2014
@@ -132,15 +132,16 @@ private:
   COFFAbsoluteAtom _imageBaseAtom;
 };
 
-// A LocallyImporteSymbolFile is an archive file containing _imp_
+// A LocallyImporteSymbolFile is an archive file containing __imp_
 // symbols for local use.
 //
 // For each defined symbol, linker creates an implicit defined symbol
-// by appending "_imp_" prefix to the original name. The content of
+// by appending "__imp_" prefix to the original name. The content of
 // the implicit symbol is a pointer to the original symbol
 // content. This feature allows one to compile and link the following
 // code without error, although _imp__hello is not defined in the
-// code.
+// code. (the leading "_" in this example is automatically appended,
+// assuming it's x86.)
 //
 //   void hello() { printf("Hello\n"); }
 //   extern void (*_imp__hello)();
@@ -153,19 +154,18 @@ private:
 class LocallyImportedSymbolFile : public impl::VirtualArchiveLibraryFile {
 public:
   LocallyImportedSymbolFile(const PECOFFLinkingContext &ctx)
-      : VirtualArchiveLibraryFile("__imp_"),
-        _prefix(ctx.decorateSymbol("_imp_")), _is64(ctx.is64Bit()),
+      : VirtualArchiveLibraryFile("__imp_"), _is64(ctx.is64Bit()),
         _ordinal(0) {}
 
   const File *find(StringRef sym, bool dataSymbolOnly) const override {
-    if (!sym.startswith(_prefix))
+    std::string prefix = "__imp_";
+    if (!sym.startswith(prefix))
       return nullptr;
-    StringRef undef = sym.substr(_prefix.size());
+    StringRef undef = sym.substr(prefix.size());
     return new (_alloc) impl::ImpSymbolFile(sym, undef, _ordinal++, _is64);
   }
 
 private:
-  std::string _prefix;
   bool _is64;
   mutable uint64_t _ordinal;
   mutable llvm::BumpPtrAllocator _alloc;

Modified: lld/trunk/test/pecoff/localyimported.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/localyimported.test?rev=218690&r1=218689&r2=218690&view=diff
==============================================================================
--- lld/trunk/test/pecoff/localyimported.test (original)
+++ lld/trunk/test/pecoff/localyimported.test Tue Sep 30 14:42:04 2014
@@ -1,7 +1,15 @@
 # RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
 #
-# RUN: not lld -flavor link /out:%t2.exe /include:__imp__nosuchsym %t.obj \
-# RUN:   >& %t2.log
-# RUN: FileCheck %s < %t2.log
+# RUN: not lld -flavor link /out:%t.exe /include:__imp__nosuchsym %t.obj \
+# RUN:   >& %t.log
+# RUN: FileCheck -check-prefix=X86 %s < %t.log
 
-CHECK: Undefined symbol: __imp__nosuchsym: _nosuchsym
+X86: Undefined symbol: __imp__nosuchsym: _nosuchsym
+
+# RUN: yaml2obj %p/Inputs/hello64.obj.yaml > %t2.obj
+#
+# RUN: not lld -flavor link /out:%t2.exe /include:__imp__nosuchsym %t2.obj \
+# RUN:   /machine:x64 >& %t2.log
+# RUN: FileCheck -check-prefix=X64 %s < %t2.log
+
+X64: Undefined symbol: __imp__nosuchsym: _nosuchsym





More information about the llvm-commits mailing list