[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
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 32efa7c..2a45022 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -291,6 +291,21 @@
In<ELFT>::Common = Common;
Symtab<ELFT>::X->Sections.push_back(Common);
}
+
+ if (Config->EMachine == EM_MIPS) {
+ // .MIPS.options
+ auto *OptSec = make<MipsOptionsSection<ELFT>>();
+ if (OptSec->Live) {
+ In<ELFT>::MipsOptions = OptSec;
+ Symtab<ELFT>::X->Sections.push_back(OptSec);
+ }
+ // MIPS .reginfo
+ auto *RegSec = make<MipsReginfoSection<ELFT>>();
+ if (RegSec->Live) {
+ In<ELFT>::MipsReginfo = RegSec;
+ Symtab<ELFT>::X->Sections.push_back(RegSec);
+ }
+ }
}
template <class ELFT>
@@ -1441,6 +1456,13 @@
template <class ELFT> void Writer<ELFT>::writeSections() {
uint8_t *Buf = Buffer->getBufferStart();
+ // Finalize MIPS .reginfo and .MIPS.options sections
+ // because they contain offsets to .got and _gp.
+ if (In<ELFT>::MipsReginfo)
+ In<ELFT>::MipsReginfo->finalize();
+ if (In<ELFT>::MipsOptions)
+ In<ELFT>::MipsOptions->finalize();
+
// PPC64 needs to process relocations in the .opd section
// before processing relocations in code-containing sections.
Out<ELFT>::Opd = findSection(".opd");