diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp index dd5b14de165a..beddcf14f843 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -478,7 +478,7 @@ private: COFFDefinedAtom(*this, "", sectionName, Atom::scopeTranslationUnit, type, perms, _merge[section], data, 0); atoms.push_back(atom); - _definedAtomLocations[section][0] = atom; + _definedAtomLocations[section][0].push_back(atom); return error_code::success(); } @@ -491,7 +491,7 @@ private: COFFDefinedAtom(*this, "", sectionName, Atom::scopeTranslationUnit, type, perms, _merge[section], data, ++ordinal); atoms.push_back(atom); - _definedAtomLocations[section][0] = atom; + _definedAtomLocations[section][0].push_back(atom); } for (auto si = symbols.begin(), se = symbols.end(); si != se; ++si) { @@ -505,12 +505,12 @@ private: type, perms, _merge[section], data, ++ordinal); atoms.push_back(atom); _symbolAtom[*si] = atom; - _definedAtomLocations[section][(*si)->Value] = atom; + _definedAtomLocations[section][(*si)->Value].push_back(atom); } // Finally, set alignment to the first atom so that the section contents // will be aligned as specified by the object section header. - _definedAtomLocations[section][0]->setAlignment(getAlignment(section)); + _definedAtomLocations[section][0][0]->setAlignment(getAlignment(section)); return error_code::success(); } @@ -542,7 +542,8 @@ private: COFFDefinedFileAtom *&result, uint32_t &offsetInAtom) { for (auto i : _definedAtomLocations[section]) { uint32_t atomAddress = i.first; - COFFDefinedAtom *atom = i.second; + std::vector &atomsAtSameLocation = i.second; + COFFDefinedAtom *atom = atomsAtSameLocation.back(); if (atomAddress <= targetAddress && targetAddress < atomAddress + atom->size()) { result = atom; @@ -697,7 +698,8 @@ private: // A sorted map to find an atom from a section and an offset within // the section. - std::map > + std::map > > _definedAtomLocations; mutable llvm::BumpPtrAllocator _alloc; diff --git a/lld/test/pecoff/Inputs/alignment.obj.yaml b/lld/test/pecoff/Inputs/alignment.obj.yaml new file mode 100644 index 000000000000..ba6e156eaa03 --- /dev/null +++ b/lld/test/pecoff/Inputs/alignment.obj.yaml @@ -0,0 +1,48 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 256 + SectionData: 5589E583EC14C745FC00000000C744240C00000000C744240807000000C744240400000000C7042400000000FF150000000083EC1031C083C4145DC3 + Relocations: + - VirtualAddress: 25 + SymbolName: .data + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 33 + SymbolName: .data + Type: IMAGE_REL_I386_DIR32 + - Name: .text$1 + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4096 + SectionData: 00 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: 576F726C64210048656C6C6F2C00 +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + NumberOfAuxSymbols: 1 + AuxiliaryData: 3C0000000300000000000000010000000000 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + NumberOfAuxSymbols: 1 + AuxiliaryData: 0E0000000000000000000000020000000000 + - Name: _start + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... diff --git a/lld/test/pecoff/alignment.test b/lld/test/pecoff/alignment.test new file mode 100644 index 000000000000..b2e1d002541b --- /dev/null +++ b/lld/test/pecoff/alignment.test @@ -0,0 +1,6 @@ +# RUN: yaml2obj %p/Inputs/alignment.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t1 /subsystem:console /force /entry:start \ +# RUN: -- %t.obj && llvm-readobj -sections %t1 | FileCheck %s + +CHECK: VirtualSize: 0x1001