[lld] r327667 - COFF: Move assignment of section RVAs to assignAddresses(). NFCI.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 15 14:13:46 PDT 2018
Author: pcc
Date: Thu Mar 15 14:13:46 2018
New Revision: 327667
URL: http://llvm.org/viewvc/llvm-project?rev=327667&view=rev
Log:
COFF: Move assignment of section RVAs to assignAddresses(). NFCI.
This makes the design a little more similar to the ELF linker and
should allow for features such as ARM range extension thunks to be
implemented more easily.
Differential Revision: https://reviews.llvm.org/D44501
Modified:
lld/trunk/COFF/MapFile.cpp
lld/trunk/COFF/PDB.cpp
lld/trunk/COFF/Writer.cpp
lld/trunk/COFF/Writer.h
Modified: lld/trunk/COFF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MapFile.cpp?rev=327667&r1=327666&r2=327667&view=diff
==============================================================================
--- lld/trunk/COFF/MapFile.cpp (original)
+++ lld/trunk/COFF/MapFile.cpp Thu Mar 15 14:13:46 2018
@@ -108,7 +108,7 @@ void coff::writeMapFile(ArrayRef<OutputS
// Print out file contents.
for (OutputSection *Sec : OutputSections) {
writeHeader(OS, Sec->getRVA(), Sec->getVirtualSize(), /*Align=*/PageSize);
- OS << Sec->getName() << '\n';
+ OS << Sec->Name << '\n';
for (Chunk *C : Sec->getChunks()) {
auto *SC = dyn_cast<SectionChunk>(C);
Modified: lld/trunk/COFF/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=327667&r1=327666&r2=327667&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Thu Mar 15 14:13:46 2018
@@ -1024,7 +1024,7 @@ static void addLinkerModuleSectionSymbol
Sym.Alignment = 12; // 2^12 = 4KB
Sym.Characteristics = OS.getCharacteristics();
Sym.Length = OS.getVirtualSize();
- Sym.Name = OS.getName();
+ Sym.Name = OS.Name;
Sym.Rva = OS.getRVA();
Sym.SectionNumber = OS.SectionIndex;
Mod.addSymbol(codeview::SymbolSerializer::writeOneSymbol(
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=327667&r1=327666&r2=327667&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Thu Mar 15 14:13:46 2018
@@ -218,37 +218,9 @@ static Timer DiskCommitTimer("Commit Out
void writeResult() { Writer().run(); }
-void OutputSection::setRVA(uint64_t RVA) {
- Header.VirtualAddress = RVA;
- for (Chunk *C : Chunks)
- C->setRVA(C->getRVA() + RVA);
-}
-
-void OutputSection::setFileOffset(uint64_t Off) {
- // If a section has no actual data (i.e. BSS section), we want to
- // set 0 to its PointerToRawData. Otherwise the output is rejected
- // by the loader.
- if (Header.SizeOfRawData == 0)
- return;
-
- // It is possible that this assignment could cause an overflow of the u32,
- // but that should be caught by the FileSize check in OutputSection::run().
- Header.PointerToRawData = Off;
-}
-
void OutputSection::addChunk(Chunk *C) {
Chunks.push_back(C);
C->setOutputSection(this);
- uint64_t Off = Header.VirtualSize;
- Off = alignTo(Off, C->Alignment);
- C->setRVA(Off);
- C->OutputSectionOff = Off;
- Off += C->getSize();
- if (Off > UINT32_MAX)
- error("section larger than 4 GiB: " + Name);
- Header.VirtualSize = Off;
- if (C->hasData())
- Header.SizeOfRawData = alignTo(Off, SectorSize);
}
void OutputSection::addPermissions(uint32_t C) {
@@ -631,8 +603,7 @@ void Writer::createSymbolAndStringTable(
// Name field in the section table is 8 byte long. Longer names need
// to be written to the string table. First, construct string table.
for (OutputSection *Sec : OutputSections) {
- StringRef Name = Sec->getName();
- if (Name.size() <= COFF::NameSize)
+ if (Sec->Name.size() <= COFF::NameSize)
continue;
// If a section isn't discardable (i.e. will be mapped at runtime),
// prefer a truncated section name over a long section name in
@@ -640,7 +611,7 @@ void Writer::createSymbolAndStringTable(
// always truncates, even for discardable sections.
if ((Sec->getPermissions() & IMAGE_SCN_MEM_DISCARDABLE) == 0)
continue;
- Sec->setStringTableOff(addEntryToStringTable(Name));
+ Sec->setStringTableOff(addEntryToStringTable(Sec->Name));
}
if (Config->DebugDwarf) {
@@ -686,12 +657,26 @@ void Writer::assignAddresses() {
return (S->getPermissions() & IMAGE_SCN_MEM_DISCARDABLE) == 0;
});
for (OutputSection *Sec : OutputSections) {
- if (Sec->getName() == ".reloc")
+ if (Sec->Name == ".reloc")
addBaserels(Sec);
- Sec->setRVA(RVA);
- Sec->setFileOffset(FileSize);
- RVA += alignTo(Sec->getVirtualSize(), PageSize);
- FileSize += alignTo(Sec->getRawSize(), SectorSize);
+ uint64_t RawSize = 0, VirtualSize = 0;
+ Sec->Header.VirtualAddress = RVA;
+ for (Chunk *C : Sec->getChunks()) {
+ VirtualSize = alignTo(VirtualSize, C->Alignment);
+ C->setRVA(RVA + VirtualSize);
+ C->OutputSectionOff = VirtualSize;
+ VirtualSize += C->getSize();
+ if (C->hasData())
+ RawSize = alignTo(VirtualSize, SectorSize);
+ }
+ if (VirtualSize > UINT32_MAX)
+ error("section larger than 4 GiB: " + Sec->Name);
+ Sec->Header.VirtualSize = VirtualSize;
+ Sec->Header.SizeOfRawData = RawSize;
+ if (RawSize != 0)
+ Sec->Header.PointerToRawData = FileSize;
+ RVA += alignTo(VirtualSize, PageSize);
+ FileSize += alignTo(RawSize, SectorSize);
}
SizeOfImage = alignTo(RVA, PageSize);
}
@@ -1149,7 +1134,7 @@ void Writer::sortExceptionTable() {
OutputSection *Writer::findSection(StringRef Name) {
for (OutputSection *Sec : OutputSections)
- if (Sec->getName() == Name)
+ if (Sec->Name == Name)
return Sec;
return nullptr;
}
Modified: lld/trunk/COFF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.h?rev=327667&r1=327666&r2=327667&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.h (original)
+++ lld/trunk/COFF/Writer.h Thu Mar 15 14:13:46 2018
@@ -31,10 +31,7 @@ void writeResult();
class OutputSection {
public:
OutputSection(llvm::StringRef N) : Name(N), Header({}) {}
- void setRVA(uint64_t);
- void setFileOffset(uint64_t);
void addChunk(Chunk *C);
- llvm::StringRef getName() { return Name; }
ArrayRef<Chunk *> getChunks() { return Chunks; }
void addPermissions(uint32_t C);
void setPermissions(uint32_t C);
@@ -61,9 +58,10 @@ public:
// N.B. The section index is one based.
uint32_t SectionIndex = 0;
-private:
llvm::StringRef Name;
llvm::object::coff_section Header;
+
+private:
uint32_t StringTableOff = 0;
std::vector<Chunk *> Chunks;
};
More information about the llvm-commits
mailing list