COFF: Remove OutputSection::getPermissions() and getCharacteristics().

All callers can just access the header directly.

Differential Revision: https://reviews.llvm.org/D45800

llvm-svn: 330367
This commit is contained in:
Peter Collingbourne 2018-04-19 21:48:37 +00:00
parent 7209117868
commit be084eca5b
4 changed files with 8 additions and 10 deletions

View File

@ -162,7 +162,7 @@ void SectionChunk::applyRelARM(uint8_t *Off, uint16_t Type, OutputSection *OS,
uint64_t S, uint64_t P) const { uint64_t S, uint64_t P) const {
// Pointer to thumb code must have the LSB set. // Pointer to thumb code must have the LSB set.
uint64_t SX = S; uint64_t SX = S;
if (OS && (OS->getPermissions() & IMAGE_SCN_MEM_EXECUTE)) if (OS && (OS->Header.Characteristics & IMAGE_SCN_MEM_EXECUTE))
SX |= 1; SX |= 1;
switch (Type) { switch (Type) {
case IMAGE_REL_ARM_ADDR32: add32(Off, SX + Config->ImageBase); break; case IMAGE_REL_ARM_ADDR32: add32(Off, SX + Config->ImageBase); break;

View File

@ -1056,7 +1056,7 @@ static void addLinkerModuleSectionSymbol(pdb::DbiModuleDescriptorBuilder &Mod,
BumpPtrAllocator &Allocator) { BumpPtrAllocator &Allocator) {
SectionSym Sym(SymbolRecordKind::SectionSym); SectionSym Sym(SymbolRecordKind::SectionSym);
Sym.Alignment = 12; // 2^12 = 4KB Sym.Alignment = 12; // 2^12 = 4KB
Sym.Characteristics = OS.getCharacteristics(); Sym.Characteristics = OS.Header.Characteristics;
Sym.Length = OS.getVirtualSize(); Sym.Length = OS.getVirtualSize();
Sym.Name = OS.Name; Sym.Name = OS.Name;
Sym.Rva = OS.getRVA(); Sym.Rva = OS.getRVA();
@ -1127,7 +1127,7 @@ void PDBLinker::addSectionContrib(pdb::DbiModuleDescriptorBuilder &LinkerModule,
CRC.update(CharContents); CRC.update(CharContents);
SC.DataCrc = CRC.getCRC(); SC.DataCrc = CRC.getCRC();
} else { } else {
SC.Characteristics = OS->getCharacteristics(); SC.Characteristics = OS->Header.Characteristics;
// FIXME: When we start creating DBI for import libraries, use those here. // FIXME: When we start creating DBI for import libraries, use those here.
SC.Imod = LinkerModule.getModuleIndex(); SC.Imod = LinkerModule.getModuleIndex();
} }

View File

@ -469,7 +469,7 @@ void Writer::createSections() {
return 3; return 3;
// Move DISCARDABLE (or non-memory-mapped) sections to the end of file because // Move DISCARDABLE (or non-memory-mapped) sections to the end of file because
// the loader cannot handle holes. // the loader cannot handle holes.
if (S->getPermissions() & IMAGE_SCN_MEM_DISCARDABLE) if (S->Header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE)
return 2; return 2;
// .rsrc should come at the end of the non-discardable sections because its // .rsrc should come at the end of the non-discardable sections because its
// size may change by the Win32 UpdateResources() function, causing // size may change by the Win32 UpdateResources() function, causing
@ -666,7 +666,7 @@ void Writer::createSymbolAndStringTable() {
for (OutputSection *Sec : OutputSections) { for (OutputSection *Sec : OutputSections) {
if (Sec->Name.size() <= COFF::NameSize) if (Sec->Name.size() <= COFF::NameSize)
continue; continue;
if ((Sec->getPermissions() & IMAGE_SCN_MEM_DISCARDABLE) == 0) if ((Sec->Header.Characteristics & IMAGE_SCN_MEM_DISCARDABLE) == 0)
continue; continue;
Sec->setStringTableOff(addEntryToStringTable(Sec->Name)); Sec->setStringTableOff(addEntryToStringTable(Sec->Name));
} }
@ -987,7 +987,7 @@ static void markSymbolsWithRelocations(ObjFile *File,
if (auto *D = dyn_cast_or_null<Defined>(Ref)) { if (auto *D = dyn_cast_or_null<Defined>(Ref)) {
Chunk *RefChunk = D->getChunk(); Chunk *RefChunk = D->getChunk();
OutputSection *OS = RefChunk ? RefChunk->getOutputSection() : nullptr; OutputSection *OS = RefChunk ? RefChunk->getOutputSection() : nullptr;
if (OS && OS->getPermissions() & IMAGE_SCN_MEM_EXECUTE) if (OS && OS->Header.Characteristics & IMAGE_SCN_MEM_EXECUTE)
addSymbolToRVASet(UsedSymbols, D); addSymbolToRVASet(UsedSymbols, D);
} }
} }
@ -1117,7 +1117,7 @@ void Writer::writeSections() {
// Fill gaps between functions in .text with INT3 instructions // Fill gaps between functions in .text with INT3 instructions
// instead of leaving as NUL bytes (which can be interpreted as // instead of leaving as NUL bytes (which can be interpreted as
// ADD instructions). // ADD instructions).
if (Sec->getPermissions() & IMAGE_SCN_CNT_CODE) if (Sec->Header.Characteristics & IMAGE_SCN_CNT_CODE)
memset(SecBuf, 0xCC, Sec->getRawSize()); memset(SecBuf, 0xCC, Sec->getRawSize());
for_each(parallel::par, Sec->getChunks().begin(), Sec->getChunks().end(), for_each(parallel::par, Sec->getChunks().begin(), Sec->getChunks().end(),
[&](Chunk *C) { C->writeTo(SecBuf); }); [&](Chunk *C) { C->writeTo(SecBuf); });
@ -1207,7 +1207,7 @@ OutputSection *Writer::findSection(StringRef Name) {
uint32_t Writer::getSizeOfInitializedData() { uint32_t Writer::getSizeOfInitializedData() {
uint32_t Res = 0; uint32_t Res = 0;
for (OutputSection *S : OutputSections) for (OutputSection *S : OutputSections)
if (S->getPermissions() & IMAGE_SCN_CNT_INITIALIZED_DATA) if (S->Header.Characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA)
Res += S->getRawSize(); Res += S->getRawSize();
return Res; return Res;
} }

View File

@ -35,8 +35,6 @@ public:
ArrayRef<Chunk *> getChunks() { return Chunks; } ArrayRef<Chunk *> getChunks() { return Chunks; }
void addPermissions(uint32_t C); void addPermissions(uint32_t C);
void setPermissions(uint32_t C); void setPermissions(uint32_t C);
uint32_t getPermissions() { return Header.Characteristics & PermMask; }
uint32_t getCharacteristics() { return Header.Characteristics; }
uint64_t getRVA() { return Header.VirtualAddress; } uint64_t getRVA() { return Header.VirtualAddress; }
uint64_t getFileOff() { return Header.PointerToRawData; } uint64_t getFileOff() { return Header.PointerToRawData; }
void writeHeaderTo(uint8_t *Buf); void writeHeaderTo(uint8_t *Buf);