diff options
Diffstat (limited to 'lld')
| -rw-r--r-- | lld/COFF/Chunks.cpp | 10 | ||||
| -rw-r--r-- | lld/COFF/Chunks.h | 15 | ||||
| -rw-r--r-- | lld/COFF/DLL.cpp | 9 | ||||
| -rw-r--r-- | lld/COFF/Driver.cpp | 8 | ||||
| -rw-r--r-- | lld/COFF/ICF.cpp | 15 | ||||
| -rw-r--r-- | lld/COFF/MapFile.cpp | 2 | ||||
| -rw-r--r-- | lld/COFF/Writer.cpp | 2 |
7 files changed, 26 insertions, 35 deletions
diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index 43bb4d4c8f2..5b17ea9c3d1 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -36,7 +36,7 @@ SectionChunk::SectionChunk(ObjFile *F, const coff_section *H) // Initialize SectionName. File->getCOFFObj()->getSectionName(Header, SectionName); - Align = Header->getAlignment(); + Alignment = Header->getAlignment(); // Chunks may be discarded during comdat merging. Discarded = false; @@ -374,11 +374,7 @@ void SectionChunk::replace(SectionChunk *Other) { CommonChunk::CommonChunk(const COFFSymbolRef S) : Sym(S) { // Common symbols are aligned on natural boundaries up to 32 bytes. // This is what MSVC link.exe does. - Align = std::min(uint64_t(32), PowerOf2Ceil(Sym.getValue())); -} - -void CommonChunk::setAlign(uint32_t NewAlign) { - Align = std::max(Align, NewAlign); + Alignment = std::min(uint64_t(32), PowerOf2Ceil(Sym.getValue())); } uint32_t CommonChunk::getPermissions() const { @@ -393,7 +389,7 @@ void StringChunk::writeTo(uint8_t *Buf) const { ImportThunkChunkX64::ImportThunkChunkX64(Defined *S) : ImpSymbol(S) { // Intel Optimization Manual says that all branch targets // should be 16-byte aligned. MSVC linker does this too. - Align = 16; + Alignment = 16; } void ImportThunkChunkX64::writeTo(uint8_t *Buf) const { diff --git a/lld/COFF/Chunks.h b/lld/COFF/Chunks.h index 7fcdaf999c3..f0368331b2d 100644 --- a/lld/COFF/Chunks.h +++ b/lld/COFF/Chunks.h @@ -62,7 +62,6 @@ public: // The writer sets and uses the addresses. uint64_t getRVA() const { return RVA; } - uint32_t getAlign() const { return Align; } void setRVA(uint64_t V) { RVA = V; } // Returns true if this has non-zero data. BSS chunks return @@ -92,23 +91,22 @@ public: // bytes, so this is used only for logging or debugging. virtual StringRef getDebugName() { return ""; } + // The alignment of this chunk. The writer uses the value. + uint32_t Alignment = 1; + protected: Chunk(Kind K = OtherKind) : ChunkKind(K) {} const Kind ChunkKind; - // The alignment of this chunk. The writer uses the value. - uint32_t Align = 1; - // The RVA of this chunk in the output. The writer sets a value. uint64_t RVA = 0; + // The output section for this chunk. + OutputSection *Out = nullptr; + public: // The offset from beginning of the output section. The writer sets a value. uint64_t OutputSectionOff = 0; - -protected: - // The output section for this chunk. - OutputSection *Out = nullptr; }; // A chunk corresponding a section of an input file. @@ -243,7 +241,6 @@ public: bool hasData() const override { return false; } uint32_t getPermissions() const override; StringRef getSectionName() const override { return ".bss"; } - void setAlign(uint32_t NewAlign); private: const COFFSymbolRef Sym; diff --git a/lld/COFF/DLL.cpp b/lld/COFF/DLL.cpp index 168590f9a23..847d15d8594 100644 --- a/lld/COFF/DLL.cpp +++ b/lld/COFF/DLL.cpp @@ -61,7 +61,7 @@ private: // A chunk for the import descriptor table. class LookupChunk : public Chunk { public: - explicit LookupChunk(Chunk *C) : HintName(C) { Align = ptrSize(); } + explicit LookupChunk(Chunk *C) : HintName(C) { Alignment = ptrSize(); } size_t getSize() const override { return ptrSize(); } void writeTo(uint8_t *Buf) const override { @@ -76,7 +76,7 @@ public: // See Microsoft PE/COFF spec 7.1. Import Header for details. class OrdinalOnlyChunk : public Chunk { public: - explicit OrdinalOnlyChunk(uint16_t V) : Ordinal(V) { Align = ptrSize(); } + explicit OrdinalOnlyChunk(uint16_t V) : Ordinal(V) { Alignment = ptrSize(); } size_t getSize() const override { return ptrSize(); } void writeTo(uint8_t *Buf) const override { @@ -117,7 +117,6 @@ public: explicit NullChunk(size_t N) : Size(N) {} bool hasData() const override { return false; } size_t getSize() const override { return Size; } - void setAlign(size_t N) { Align = N; } private: size_t Size; @@ -302,7 +301,7 @@ public: // A chunk for the import descriptor table. class DelayAddressChunk : public Chunk { public: - explicit DelayAddressChunk(Chunk *C) : Thunk(C) { Align = ptrSize(); } + explicit DelayAddressChunk(Chunk *C) : Thunk(C) { Alignment = ptrSize(); } size_t getSize() const override { return ptrSize(); } void writeTo(uint8_t *Buf) const override { @@ -535,7 +534,7 @@ void DelayLoadContents::create(Defined *H) { for (int I = 0, E = Syms.size(); I < E; ++I) Syms[I]->setLocation(Addresses[Base + I]); auto *MH = make<NullChunk>(8); - MH->setAlign(8); + MH->Alignment = 8; ModuleHandles.push_back(MH); // Fill the delay import table header fields. diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index ab3612ca96b..0cae83461c1 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -1201,18 +1201,22 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { // Set extra alignment for .comm symbols for (auto Pair : Config->AlignComm) { StringRef Name = Pair.first; - int Align = Pair.second; + uint32_t Alignment = Pair.second; + Symbol *Sym = Symtab->find(Name); if (!Sym) { warn("/aligncomm symbol " + Name + " not found"); continue; } + auto *DC = dyn_cast<DefinedCommon>(Sym->body()); if (!DC) { warn("/aligncomm symbol " + Name + " of wrong kind"); continue; } - DC->getChunk()->setAlign(Align); + + CommonChunk *C = DC->getChunk(); + C->Alignment = std::max(C->Alignment, Alignment); } // Windows specific -- Create a side-by-side manifest file. diff --git a/lld/COFF/ICF.cpp b/lld/COFF/ICF.cpp index da8ca360542..e50b951c34d 100644 --- a/lld/COFF/ICF.cpp +++ b/lld/COFF/ICF.cpp @@ -61,12 +61,9 @@ private: // Returns a hash value for S. uint32_t ICF::getHash(SectionChunk *C) { - return hash_combine(C->getPermissions(), - hash_value(C->SectionName), - C->NumRelocs, - C->getAlign(), - uint32_t(C->Header->SizeOfRawData), - C->Checksum); + return hash_combine(C->getPermissions(), hash_value(C->SectionName), + C->NumRelocs, C->Alignment, + uint32_t(C->Header->SizeOfRawData), C->Checksum); } // Returns true if section S is subject of ICF. @@ -137,11 +134,9 @@ bool ICF::equalsConstant(const SectionChunk *A, const SectionChunk *B) { // Compare section attributes and contents. return A->getPermissions() == B->getPermissions() && - A->SectionName == B->SectionName && - A->getAlign() == B->getAlign() && + A->SectionName == B->SectionName && A->Alignment == B->Alignment && A->Header->SizeOfRawData == B->Header->SizeOfRawData && - A->Checksum == B->Checksum && - A->getContents() == B->getContents(); + A->Checksum == B->Checksum && A->getContents() == B->getContents(); } // Compare "moving" part of two sections, namely relocation targets. diff --git a/lld/COFF/MapFile.cpp b/lld/COFF/MapFile.cpp index a3b1850829c..076f8637c9d 100644 --- a/lld/COFF/MapFile.cpp +++ b/lld/COFF/MapFile.cpp @@ -115,7 +115,7 @@ void coff::writeMapFile(ArrayRef<OutputSection *> OutputSections) { if (!SC) continue; - writeHeader(OS, SC->getRVA(), SC->getSize(), SC->getAlign()); + writeHeader(OS, SC->getRVA(), SC->getSize(), SC->Alignment); OS << indent(1) << SC->File->getName() << ":(" << SC->getSectionName() << ")\n"; for (DefinedRegular *Sym : SectionSyms[SC]) diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 1a55a0f6b76..799611f39ab 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -183,7 +183,7 @@ void OutputSection::addChunk(Chunk *C) { Chunks.push_back(C); C->setOutputSection(this); uint64_t Off = Header.VirtualSize; - Off = alignTo(Off, C->getAlign()); + Off = alignTo(Off, C->Alignment); C->setRVA(Off); C->OutputSectionOff = Off; Off += C->getSize(); |

