diff options
Diffstat (limited to 'lld/ELF')
| -rw-r--r-- | lld/ELF/LinkerScript.cpp | 4 | ||||
| -rw-r--r-- | lld/ELF/LinkerScript.h | 4 | ||||
| -rw-r--r-- | lld/ELF/OutputSections.cpp | 40 | ||||
| -rw-r--r-- | lld/ELF/OutputSections.h | 1 | ||||
| -rw-r--r-- | lld/ELF/SyntheticSections.cpp | 6 | ||||
| -rw-r--r-- | lld/ELF/Target.cpp | 4 | ||||
| -rw-r--r-- | lld/ELF/Target.h | 4 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 2 |
8 files changed, 11 insertions, 54 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index e5076be283d..9e39a5de32e 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -862,12 +862,12 @@ bool LinkerScript::ignoreInterpSection() { return true; } -Optional<uint32_t> LinkerScript::getFiller(StringRef Name) { +uint32_t LinkerScript::getFiller(StringRef Name) { for (BaseCommand *Base : Opt.Commands) if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base)) if (Cmd->Name == Name) return Cmd->Filler; - return None; + return 0; } static void writeInt(uint8_t *Buf, uint64_t Data, uint64_t Size) { diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index b221e75f003..e1962c04d92 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -112,7 +112,7 @@ struct OutputSectionCommand : BaseCommand { Expr SubalignExpr; std::vector<BaseCommand *> Commands; std::vector<StringRef> Phdrs; - llvm::Optional<uint32_t> Filler; + uint32_t Filler = 0; ConstraintKind Constraint = ConstraintKind::NoConstraint; std::string Location; std::string MemoryRegionName; @@ -262,7 +262,7 @@ public: std::vector<PhdrEntry> createPhdrs(); bool ignoreInterpSection(); - llvm::Optional<uint32_t> getFiller(StringRef Name); + uint32_t getFiller(StringRef Name); bool hasLMA(StringRef Name); bool shouldKeep(InputSectionBase *S); void assignOffsets(OutputSectionCommand *Cmd); diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 972cf1cbd3f..315ba1cc4db 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -225,9 +225,6 @@ void OutputSection::sortCtorsDtors() { // Fill [Buf, Buf + Size) with Filler. Filler is written in big // endian order. This is used for linker script "=fillexp" command. static void fill(uint8_t *Buf, size_t Size, uint32_t Filler) { - if (Filler == 0) - return; - uint8_t V[4]; write32be(V, Filler); size_t I = 0; @@ -236,44 +233,17 @@ static void fill(uint8_t *Buf, size_t Size, uint32_t Filler) { memcpy(Buf + I, V, Size - I); } -uint32_t OutputSection::getFill() { - // Determine what to fill gaps between InputSections with, as specified by the - // linker script. If nothing is specified and this is an executable section, - // fall back to trap instructions to prevent bad diassembly and detect invalid - // jumps to padding. - if (Optional<uint32_t> Filler = Script->getFiller(Name)) - return *Filler; - if (Flags & SHF_EXECINSTR) - return Target->TrapInstr; - return 0; -} - template <class ELFT> void OutputSection::writeTo(uint8_t *Buf) { Loc = Buf; + if (uint32_t Filler = Script->getFiller(this->Name)) + fill(Buf, this->Size, Filler); - uint32_t Filler = getFill(); - - // Write leading padding. - size_t FillSize = Sections.empty() ? Size : Sections[0]->OutSecOff; - fill(Buf, FillSize, Filler); - - parallelFor(0, Sections.size(), [=](size_t I) { - InputSection *Sec = Sections[I]; - Sec->writeTo<ELFT>(Buf); - - // Fill gaps between sections with the specified fill value. - uint8_t *Start = Buf + Sec->OutSecOff + Sec->getSize(); - uint8_t *End; - if (I + 1 == Sections.size()) - End = Buf + Size; - else - End = Buf + Sections[I + 1]->OutSecOff; - fill(Start, End - Start, Filler); - }); + parallelForEach(Sections.begin(), Sections.end(), + [=](InputSection *IS) { IS->writeTo<ELFT>(Buf); }); // Linker scripts may have BYTE()-family commands with which you // can write arbitrary bytes to the output. Process them if any. - Script->writeDataBytes(Name, Buf); + Script->writeDataBytes(this->Name, Buf); } static uint64_t getOutFlags(InputSectionBase *S) { diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 0ac6dc65b75..649d1fa4834 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -81,7 +81,6 @@ public: void sort(std::function<int(InputSectionBase *S)> Order); void sortInitFini(); void sortCtorsDtors(); - uint32_t getFill(); template <class ELFT> void writeTo(uint8_t *Buf); template <class ELFT> void finalize(); void assignOffsets(); diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 4c2b91647e1..c9cca76697b 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -2180,11 +2180,7 @@ MipsRldMapSection::MipsRldMapSection() void MipsRldMapSection::writeTo(uint8_t *Buf) { // Apply filler from linker script. - Optional<uint32_t> Fill = Script->getFiller(this->Name); - if (!Fill || *Fill == 0) - return; - - uint64_t Filler = *Fill; + uint64_t Filler = Script->getFiller(this->Name); Filler = (Filler << 32) | Filler; memcpy(Buf, &Filler, getSize()); } diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 0f565c50c08..872d8e650ac 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -349,8 +349,6 @@ X86TargetInfo::X86TargetInfo() { PltEntrySize = 16; PltHeaderSize = 16; TlsGdRelaxSkip = 2; - // 0xCC is the "int3" (call debug exception handler) instruction. - TrapInstr = 0xcccccccc; } RelExpr X86TargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const { @@ -649,8 +647,6 @@ template <class ELFT> X86_64TargetInfo<ELFT>::X86_64TargetInfo() { // Align to the large page size (known as a superpage or huge page). // FreeBSD automatically promotes large, superpage-aligned allocations. DefaultImageBase = 0x200000; - // 0xCC is the "int3" (call debug exception handler) instruction. - TrapInstr = 0xcccccccc; } template <class ELFT> diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h index 410e856890c..deb9cc45e70 100644 --- a/lld/ELF/Target.h +++ b/lld/ELF/Target.h @@ -90,10 +90,6 @@ public: bool NeedsThunks = false; - // A 4-byte field corresponding to one or more trap instructions, used to pad - // executable OutputSections. - uint32_t TrapInstr = 0; - virtual RelExpr adjustRelaxExpr(uint32_t Type, const uint8_t *Data, RelExpr Expr) const; virtual void relaxGot(uint8_t *Loc, uint64_t Val) const; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index fd761d68d15..56f1b5ee325 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1790,7 +1790,7 @@ template <class ELFT> void Writer<ELFT>::writeSections() { // The .eh_frame_hdr depends on .eh_frame section contents, therefore // it should be written after .eh_frame is written. - if (EhFrameHdr && !EhFrameHdr->Sections.empty()) + if (EhFrameHdr) EhFrameHdr->writeTo<ELFT>(Buf + EhFrameHdr->Offset); } |

