From e2fd426bdafe9f5c10066d3926ece6e342184a67 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 19 Jan 2019 10:05:49 +0000 Subject: Vendor import of lld trunk r351319 (just before the release_80 branch point): https://llvm.org/svn/llvm-project/lld/trunk@351319 --- ELF/OutputSections.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'ELF/OutputSections.cpp') diff --git a/ELF/OutputSections.cpp b/ELF/OutputSections.cpp index 8253b18b486c..c1442c078736 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 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 &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 void OutputSection::writeTo(uint8_t *Buf) { // Write leading padding. std::vector Sections = getInputSections(this); - uint32_t Filler = getFiller(); - if (Filler) + std::array 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 void OutputSection::writeTo(uint8_t *Buf) { IS->writeTo(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 *Obj = Section->getFile(); ArrayRef Symbols = Obj->getSymbols(); - OS->Info = InX::SymTab->getSymbolIndex(Symbols[Section->Info]); + OS->Info = In.SymTab->getSymbolIndex(Symbols[Section->Info]); } template void OutputSection::finalize() { @@ -308,7 +310,7 @@ template void OutputSection::finalize() { if (isa(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 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::Shdr *Shdr); -- cgit v1.2.3