diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2015-07-07 02:15:25 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2015-07-07 02:15:25 +0000 |
commit | f0cf4fb8b2da296991b12fb68a7b901fa0d2ebc0 (patch) | |
tree | 0e7a08d1be657d82a2af491d1c3af0576c437412 | |
parent | fa9fdd783b61a83fa8bbd5410b30c76468c13550 (diff) |
COFF: Fix bug involving archives defining a symbol multiple times.
Previously we were unnecessarily loading lazy symbols if they appeared in an
archive multiple times, as can happen with comdat symbols. This change fixes
the bug by only loading symbols from archives at load time if the original
symbol was undefined.
Differential Revision: http://reviews.llvm.org/D10980
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@241538 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | COFF/SymbolTable.cpp | 3 | ||||
-rw-r--r-- | test/COFF/ar-comdat.test | 38 |
2 files changed, 40 insertions, 1 deletions
diff --git a/COFF/SymbolTable.cpp b/COFF/SymbolTable.cpp index 5e27e5fda..7f7187a37 100644 --- a/COFF/SymbolTable.cpp +++ b/COFF/SymbolTable.cpp @@ -177,7 +177,8 @@ void SymbolTable::addLazy(Lazy *New, std::vector<Symbol *> *Accum) { if (!Sym->Body.compare_exchange_strong(Existing, New)) continue; New->setBackref(Sym); - Accum->push_back(Sym); + if (isa<Undefined>(Existing)) + Accum->push_back(Sym); return; } } diff --git a/test/COFF/ar-comdat.test b/test/COFF/ar-comdat.test new file mode 100644 index 000000000..27a4085db --- /dev/null +++ b/test/COFF/ar-comdat.test @@ -0,0 +1,38 @@ +# RUN: yaml2obj %s > %t1.obj +# RUN: yaml2obj %s > %t2.obj +# RUN: llvm-lib /out:%t.lib %t1.obj %t2.obj +# RUN: lld -flavor link2 /out:%t.exe /lldmap:%t.map /entry:main /subsystem:console %p/Inputs/ret42.obj %t.lib +# RUN: FileCheck %s < %t.map + +# CHECK-NOT: .lib + +--- +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .bss + Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: '' +symbols: + - Name: .bss + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 1 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: x + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... |