diff options
Diffstat (limited to 'ELF/OutputSections.cpp')
-rw-r--r-- | ELF/OutputSections.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/ELF/OutputSections.cpp b/ELF/OutputSections.cpp index 8253b18b486c0..c1442c0787361 100644 --- a/ELF/OutputSections.cpp +++ b/ELF/OutputSections.cpp @@ -25,6 +25,7 @@ using namespace llvm; using namespace llvm::dwarf; using namespace llvm::object; +using namespace llvm::support::endian; using namespace llvm::ELF; using namespace lld; @@ -32,7 +33,6 @@ using namespace lld::elf; uint8_t Out::First; PhdrEntry *Out::TlsPhdr; -OutputSection *Out::DebugInfo; OutputSection *Out::ElfHeader; OutputSection *Out::ProgramHeaders; OutputSection *Out::PreinitArray; @@ -95,7 +95,7 @@ void OutputSection::addSection(InputSection *IS) { Flags = IS->Flags; } else { // Otherwise, check if new type or flags are compatible with existing ones. - unsigned Mask = SHF_ALLOC | SHF_TLS | SHF_LINK_ORDER; + unsigned Mask = SHF_TLS | SHF_LINK_ORDER; if ((Flags & Mask) != (IS->Flags & Mask)) error("incompatible section flags for " + Name + "\n>>> " + toString(IS) + ": 0x" + utohexstr(IS->Flags) + "\n>>> output section " + Name + @@ -171,11 +171,12 @@ void OutputSection::sort(llvm::function_ref<int(InputSectionBase *S)> Order) { // Fill [Buf, Buf + Size) with Filler. // This is used for linker script "=fillexp" command. -static void fill(uint8_t *Buf, size_t Size, uint32_t Filler) { +static void fill(uint8_t *Buf, size_t Size, + const std::array<uint8_t, 4> &Filler) { size_t I = 0; for (; I + 4 < Size; I += 4) - memcpy(Buf + I, &Filler, 4); - memcpy(Buf + I, &Filler, Size - I); + memcpy(Buf + I, Filler.data(), 4); + memcpy(Buf + I, Filler.data(), Size - I); } // Compress section contents if this section contains debug info. @@ -236,8 +237,9 @@ template <class ELFT> void OutputSection::writeTo(uint8_t *Buf) { // Write leading padding. std::vector<InputSection *> Sections = getInputSections(this); - uint32_t Filler = getFiller(); - if (Filler) + std::array<uint8_t, 4> Filler = getFiller(); + bool NonZeroFiller = read32(Filler.data()) != 0; + if (NonZeroFiller) fill(Buf, Sections.empty() ? Size : Sections[0]->OutSecOff, Filler); parallelForEachN(0, Sections.size(), [&](size_t I) { @@ -245,7 +247,7 @@ template <class ELFT> void OutputSection::writeTo(uint8_t *Buf) { IS->writeTo<ELFT>(Buf); // Fill gaps between sections. - if (Filler) { + if (NonZeroFiller) { uint8_t *Start = Buf + IS->OutSecOff + IS->getSize(); uint8_t *End; if (I + 1 == Sections.size()) @@ -270,13 +272,13 @@ static void finalizeShtGroup(OutputSection *OS, // sh_link field for SHT_GROUP sections should contain the section index of // the symbol table. - OS->Link = InX::SymTab->getParent()->SectionIndex; + OS->Link = In.SymTab->getParent()->SectionIndex; // sh_info then contain index of an entry in symbol table section which // provides signature of the section group. ObjFile<ELFT> *Obj = Section->getFile<ELFT>(); ArrayRef<Symbol *> Symbols = Obj->getSymbols(); - OS->Info = InX::SymTab->getSymbolIndex(Symbols[Section->Info]); + OS->Info = In.SymTab->getSymbolIndex(Symbols[Section->Info]); } template <class ELFT> void OutputSection::finalize() { @@ -308,7 +310,7 @@ template <class ELFT> void OutputSection::finalize() { if (isa<SyntheticSection>(First)) return; - Link = InX::SymTab->getParent()->SectionIndex; + Link = In.SymTab->getParent()->SectionIndex; // sh_info for SHT_REL[A] sections should contain the section header index of // the section to which the relocation applies. InputSectionBase *S = First->getRelocatedSection(); @@ -406,12 +408,12 @@ void OutputSection::sortInitFini() { sort([](InputSectionBase *S) { return getPriority(S->Name); }); } -uint32_t OutputSection::getFiller() { +std::array<uint8_t, 4> OutputSection::getFiller() { if (Filler) return *Filler; if (Flags & SHF_EXECINSTR) return Target->TrapInstr; - return 0; + return {0, 0, 0, 0}; } template void OutputSection::writeHeaderTo<ELF32LE>(ELF32LE::Shdr *Shdr); |