diff options
| -rw-r--r-- | lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h | 16 | ||||
| -rw-r--r-- | lld/test/pecoff/localyimported.test | 16 | 
2 files changed, 20 insertions, 12 deletions
| diff --git a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h index 61e38659794..0b02b8ef1fb 100644 --- a/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h +++ b/lld/lib/ReaderWriter/PECOFF/LinkerGeneratedSymbolFile.h @@ -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; diff --git a/lld/test/pecoff/localyimported.test b/lld/test/pecoff/localyimported.test index 592c0fa6507..52b32d7b80b 100644 --- a/lld/test/pecoff/localyimported.test +++ b/lld/test/pecoff/localyimported.test @@ -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 | 

