Reference reference
.got
or .mipsgot
are synthetic input sections created before relocation can actually happen on them. They are created before finalizeSections()
, so that they can be placed into the finall output; they are updated during finalizeSections()
, where they got allocated in the virtual space; After the location of sections are finalized, virtual addresses are mostly available for relocation to happen.
Now here tracks the first step where synthetic relocation sections such as .got
are created and
initialized.
.got
as InputSection is created via createSyntheticSections()
// lld/ELF/Writer.cpp
template <class ELFT> void createSyntheticSections() {
...
// Add .got. MIPS' .got is so different from the other archs,
// it has its own class.
if (config->emachine == EM_MIPS) {
in.mipsGot = make<MipsGotSection>();
add(in.mipsGot);
} else {
in.got = make<GotSection>();
add(in.got);
}
...
}
// call path for createSyntheticSections()
LinkerDriver::link() -> createSyntheticSections<ELFT>();
Non-Mips .got
section entries are created in:
Mips .got
section entries are created in
Every SyntheticSection
in LLD implements function finalizeContents()
.
What does it do?
In (both Mips and Non-Mips) .got
: it compute and set the size
of the section.
// lld/ELF/SyntheticSections.cpp
void GotSection::finalizeContents() {
size = numEntries * config->wordsize;
}
void MipsGotSection::finalizeContents() { updateAllocSize(); }
bool MipsGotSection::updateAllocSize() {
size = headerEntriesNum * config->wordsize;
for (const FileGot &g : gots)
size += g.getEntriesNum() * config->wordsize;
return false;
}
When/Where it is invoked?
During the execution of finalizeSections()
, where each section is “finalized” with a certain virtual address. Call path:
// lld/ELF/Writer.cpp
Writer::finalizeSections(){
...
finalizeSynthetic(in.bss);
finalizeSynthetic(in.bssRelRo);
finalizeSynthetic(in.symTabShndx);
finalizeSynthetic(in.shStrTab);
finalizeSynthetic(in.strTab);
finalizeSynthetic(in.got);
finalizeSynthetic(in.mipsGot);
finalizeSynthetic(in.igotPlt);
finalizeSynthetic(in.gotPlt);
finalizeSynthetic(in.relaIplt);
finalizeSynthetic(in.relaPlt);
finalizeSynthetic(in.plt);
finalizeSynthetic(in.iplt);
finalizeSynthetic(in.ppc32Got2);
finalizeSynthetic(in.partIndex);
...
}
// lld/ELF/Writer.cpp
static void finalizeSynthetic(SyntheticSection *sec){
if (sec && sec->isNeeded() && sec->getParent())
sec->finalizeContents();
}
If you could revise
the fundmental principles of
computer system design
to improve security...
... what would you change?