From ce02cf0099e912e31300d58477d65ae26ea13ef8 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Wed, 9 Nov 2016 21:36:56 +0000 Subject: [ELF][MIPS] Convert .reginfo and .MIPS.options sections to synthetic input sections Previously, we have both input and output sections for .reginfo and .MIPS.options. Now for each such sections we have one synthetic input sections: MipsReginfoSection and MipsOptionsSection respectively. Both sections are handled as regular sections until the control reaches Writer. Writer then aggregates all sections whose type is SHT_MIPS_REGINFO or SHT_MIPS_OPTIONS to create a single synthesized input section. In that moment Writer also save GP0 value to the MipsGp0 field of the corresponding ObjectFile. This value required for R_MIPS_GPREL16 and R_MIPS_GPREL32 relocations calculation. Differential revision: https://reviews.llvm.org/D26444 llvm-svn: 286397 --- lld/ELF/OutputSections.cpp | 79 +++------------------------------------------- 1 file changed, 5 insertions(+), 74 deletions(-) (limited to 'lld/ELF/OutputSections.cpp') diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index c8c622ca495..45587d0a49e 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -913,6 +913,11 @@ OutputSection::OutputSection(StringRef Name, uint32_t Type, uintX_t Flags) this->Entsize = sizeof(Elf_Rela); else if (Type == SHT_REL) this->Entsize = sizeof(Elf_Rel); + else if (Type == SHT_MIPS_REGINFO) + this->Entsize = sizeof(Elf_Mips_RegInfo); + else if (Type == SHT_MIPS_OPTIONS) + this->Entsize = + sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo); } template void OutputSection::finalize() { @@ -1724,64 +1729,6 @@ template void VersionNeedSection::finalize() { this->Size = Size; } -template -MipsReginfoOutputSection::MipsReginfoOutputSection() - : OutputSectionBase(".reginfo", SHT_MIPS_REGINFO, SHF_ALLOC) { - this->Addralign = 4; - this->Entsize = sizeof(Elf_Mips_RegInfo); - this->Size = sizeof(Elf_Mips_RegInfo); -} - -template -void MipsReginfoOutputSection::writeTo(uint8_t *Buf) { - auto *R = reinterpret_cast(Buf); - if (Config->Relocatable) - R->ri_gp_value = 0; - else - R->ri_gp_value = Out::Got->Addr + MipsGPOffset; - R->ri_gprmask = GprMask; -} - -template -void MipsReginfoOutputSection::addSection(InputSectionBase *C) { - // Copy input object file's .reginfo gprmask to output. - auto *S = cast>(C); - GprMask |= S->Reginfo->ri_gprmask; - S->OutSec = this; -} - -template -MipsOptionsOutputSection::MipsOptionsOutputSection() - : OutputSectionBase(".MIPS.options", SHT_MIPS_OPTIONS, - SHF_ALLOC | SHF_MIPS_NOSTRIP) { - this->Addralign = 8; - this->Entsize = 1; - this->Size = sizeof(Elf_Mips_Options) + sizeof(Elf_Mips_RegInfo); -} - -template -void MipsOptionsOutputSection::writeTo(uint8_t *Buf) { - auto *Opt = reinterpret_cast(Buf); - Opt->kind = ODK_REGINFO; - Opt->size = this->Size; - Opt->section = 0; - Opt->info = 0; - auto *Reg = reinterpret_cast(Buf + sizeof(*Opt)); - if (Config->Relocatable) - Reg->ri_gp_value = 0; - else - Reg->ri_gp_value = Out::Got->Addr + MipsGPOffset; - Reg->ri_gprmask = GprMask; -} - -template -void MipsOptionsOutputSection::addSection(InputSectionBase *C) { - auto *S = cast>(C); - if (S->Reginfo) - GprMask |= S->Reginfo->ri_gprmask; - S->OutSec = this; -} - template MipsAbiFlagsOutputSection::MipsAbiFlagsOutputSection() : OutputSectionBase(".MIPS.abiflags", SHT_MIPS_ABIFLAGS, SHF_ALLOC) { @@ -1876,12 +1823,6 @@ OutputSectionFactory::create(const SectionKey &Key, case InputSectionBase::Merge: Sec = make>(Key.Name, Type, Flags, Key.Alignment); break; - case InputSectionBase::MipsReginfo: - Sec = make>(); - break; - case InputSectionBase::MipsOptions: - Sec = make>(); - break; case InputSectionBase::MipsAbiFlags: Sec = make>(); break; @@ -1978,16 +1919,6 @@ template class EhOutputSection; template class EhOutputSection; template class EhOutputSection; -template class MipsReginfoOutputSection; -template class MipsReginfoOutputSection; -template class MipsReginfoOutputSection; -template class MipsReginfoOutputSection; - -template class MipsOptionsOutputSection; -template class MipsOptionsOutputSection; -template class MipsOptionsOutputSection; -template class MipsOptionsOutputSection; - template class MipsAbiFlagsOutputSection; template class MipsAbiFlagsOutputSection; template class MipsAbiFlagsOutputSection; -- cgit v1.2.3