Index: lld/trunk/ELF/OutputSections.h =================================================================== --- lld/trunk/ELF/OutputSections.h +++ lld/trunk/ELF/OutputSections.h @@ -201,7 +201,6 @@ static uint8_t First; static EhOutputSection *EhFrame; static OutputSection *Bss; - static OutputSection *MipsRldMap; static OutputSectionBase *Opd; static uint8_t *OpdBuf; static Elf_Phdr *TlsPhdr; @@ -249,7 +248,6 @@ template uint8_t Out::First; template EhOutputSection *Out::EhFrame; template OutputSection *Out::Bss; -template OutputSection *Out::MipsRldMap; template OutputSectionBase *Out::Opd; template uint8_t *Out::OpdBuf; template typename ELFT::Phdr *Out::TlsPhdr; Index: lld/trunk/ELF/SyntheticSections.h =================================================================== --- lld/trunk/ELF/SyntheticSections.h +++ lld/trunk/ELF/SyntheticSections.h @@ -599,6 +599,17 @@ Elf_Mips_RegInfo Reginfo; }; +// This is a MIPS specific section to hold a space within the data segment +// of executable file which is pointed to by the DT_MIPS_RLD_MAP entry. +// See "Dynamic section" in Chapter 5 in the following document: +// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf +template class MipsRldMap : public SyntheticSection { +public: + MipsRldMap(); + size_t getSize() const override { return sizeof(typename ELFT::uint); } + void writeTo(uint8_t *Buf) override; +}; + template InputSection *createCommonSection(); template InputSection *createInterpSection(); template MergeInputSection *createCommentSection(); @@ -618,6 +629,7 @@ static GotPltSection *GotPlt; static HashTableSection *HashTab; static InputSection *Interp; + static MipsRldMap *MipsRldMap; static PltSection *Plt; static RelocationSection *RelaDyn; static RelocationSection *RelaPlt; @@ -642,6 +654,7 @@ template GotPltSection *In::GotPlt; template HashTableSection *In::HashTab; template InputSection *In::Interp; +template MipsRldMap *In::MipsRldMap; template PltSection *In::Plt; template RelocationSection *In::RelaDyn; template RelocationSection *In::RelaPlt; Index: lld/trunk/ELF/SyntheticSections.cpp =================================================================== --- lld/trunk/ELF/SyntheticSections.cpp +++ lld/trunk/ELF/SyntheticSections.cpp @@ -18,6 +18,7 @@ #include "Config.h" #include "Error.h" #include "InputFiles.h" +#include "LinkerScript.h" #include "Memory.h" #include "OutputSections.h" #include "Strings.h" @@ -883,8 +884,8 @@ else add({DT_MIPS_GOTSYM, In::DynSymTab->getNumSymbols()}); add({DT_PLTGOT, In::MipsGot}); - if (Out::MipsRldMap) - add({DT_MIPS_RLD_MAP, Out::MipsRldMap}); + if (In::MipsRldMap) + add({DT_MIPS_RLD_MAP, In::MipsRldMap}); } this->OutSec->Entsize = this->Entsize; @@ -1655,6 +1656,19 @@ return Size; } +template +MipsRldMap::MipsRldMap() + : SyntheticSection(SHF_ALLOC | SHF_WRITE, SHT_PROGBITS, + sizeof(typename ELFT::uint), ".rld_map") {} + +template void MipsRldMap::writeTo(uint8_t *Buf) { + + // Apply filler from linker script. + uint64_t Filler = Script::X->getFiller(this->Name); + Filler = (Filler << 32) | Filler; + memcpy(Buf, &Filler, getSize()); +} + template InputSection *elf::createCommonSection(); template InputSection *elf::createCommonSection(); template InputSection *elf::createCommonSection(); @@ -1764,3 +1778,8 @@ template class elf::VersionDefinitionSection; template class elf::VersionDefinitionSection; template class elf::VersionDefinitionSection; + +template class elf::MipsRldMap; +template class elf::MipsRldMap; +template class elf::MipsRldMap; +template class elf::MipsRldMap; Index: lld/trunk/ELF/Writer.cpp =================================================================== --- lld/trunk/ELF/Writer.cpp +++ lld/trunk/ELF/Writer.cpp @@ -277,16 +277,6 @@ In::SymTab = make>(*In::StrTab); } - if (Config->EMachine == EM_MIPS && !Config->Shared) { - // This is a MIPS specific section to hold a space within the data segment - // of executable file which is pointed to by the DT_MIPS_RLD_MAP entry. - // See "Dynamic section" in Chapter 5 in the following document: - // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf - Out::MipsRldMap = make>(".rld_map", SHT_PROGBITS, - SHF_ALLOC | SHF_WRITE); - Out::MipsRldMap->Size = sizeof(uintX_t); - Out::MipsRldMap->updateAlignment(sizeof(uintX_t)); - } if (!Config->VersionDefinitions.empty()) In::VerDef = make>(); @@ -307,6 +297,10 @@ // Add MIPS-specific sections. if (Config->EMachine == EM_MIPS) { + if (!Config->Shared && In::DynSymTab) { + In::MipsRldMap = make>(); + Symtab::X->Sections.push_back(In::MipsRldMap); + } if (auto *Sec = MipsAbiFlagsSection::create()) Symtab::X->Sections.push_back(Sec); if (auto *Sec = MipsOptionsSection::create()) @@ -1009,7 +1003,6 @@ addInputSec(In::DynStrTab); if (In::RelaDyn->hasRelocs()) addInputSec(In::RelaDyn); - Add(Out::MipsRldMap); } // We always need to add rel[a].plt to output if it has entries.