forked from OSchip/llvm-project
Instantiate Interp output section only when needed.
This change simplifies interaction between Writer and the linker script because we can make needsInterpSection() a file-scope function. llvm-svn: 276261
This commit is contained in:
parent
865bf8637b
commit
fd03cfd27a
|
|
@ -344,7 +344,7 @@ LinkerScript<ELFT>::createPhdrs(ArrayRef<OutputSectionBase<ELFT> *> Sections) {
|
|||
|
||||
switch (Cmd.Type) {
|
||||
case PT_INTERP:
|
||||
if (needsInterpSection<ELFT>())
|
||||
if (Out<ELFT>::Interp)
|
||||
Added.add(Out<ELFT>::Interp);
|
||||
break;
|
||||
case PT_DYNAMIC:
|
||||
|
|
|
|||
|
|
@ -112,6 +112,11 @@ void elf::reportDiscarded(InputSectionBase<ELFT> *IS,
|
|||
<< "' in file '" << File->getName() << "'\n";
|
||||
}
|
||||
|
||||
template <class ELFT> static bool needsInterpSection() {
|
||||
return !Symtab<ELFT>::X->getSharedFiles().empty() &&
|
||||
!Config->DynamicLinker.empty();
|
||||
}
|
||||
|
||||
template <class ELFT> void elf::writeResult(SymbolTable<ELFT> *Symtab) {
|
||||
typedef typename ELFT::uint uintX_t;
|
||||
typedef typename ELFT::Ehdr Elf_Ehdr;
|
||||
|
|
@ -121,7 +126,6 @@ template <class ELFT> void elf::writeResult(SymbolTable<ELFT> *Symtab) {
|
|||
DynamicSection<ELFT> Dynamic;
|
||||
EhOutputSection<ELFT> EhFrame;
|
||||
GotSection<ELFT> Got;
|
||||
InterpSection<ELFT> Interp;
|
||||
PltSection<ELFT> Plt;
|
||||
RelocationSection<ELFT> RelaDyn(Config->Rela ? ".rela.dyn" : ".rel.dyn",
|
||||
Config->ZCombreloc);
|
||||
|
|
@ -137,6 +141,7 @@ template <class ELFT> void elf::writeResult(SymbolTable<ELFT> *Symtab) {
|
|||
ProgramHeaders.updateAlignment(sizeof(uintX_t));
|
||||
|
||||
// Instantiate optional output sections if they are needed.
|
||||
std::unique_ptr<InterpSection<ELFT>> Interp;
|
||||
std::unique_ptr<BuildIdSection<ELFT>> BuildId;
|
||||
std::unique_ptr<EhFrameHeader<ELFT>> EhFrameHdr;
|
||||
std::unique_ptr<GnuHashTableSection<ELFT>> GnuHashTab;
|
||||
|
|
@ -148,6 +153,9 @@ template <class ELFT> void elf::writeResult(SymbolTable<ELFT> *Symtab) {
|
|||
std::unique_ptr<OutputSection<ELFT>> MipsRldMap;
|
||||
std::unique_ptr<VersionDefinitionSection<ELFT>> VerDef;
|
||||
|
||||
if (needsInterpSection<ELFT>())
|
||||
Interp.reset(new InterpSection<ELFT>);
|
||||
|
||||
if (Config->BuildId == BuildIdKind::Fnv1)
|
||||
BuildId.reset(new BuildIdFnv1<ELFT>);
|
||||
else if (Config->BuildId == BuildIdKind::Md5)
|
||||
|
|
@ -195,7 +203,7 @@ template <class ELFT> void elf::writeResult(SymbolTable<ELFT> *Symtab) {
|
|||
Out<ELFT>::Got = &Got;
|
||||
Out<ELFT>::GotPlt = GotPlt.get();
|
||||
Out<ELFT>::HashTab = HashTab.get();
|
||||
Out<ELFT>::Interp = &Interp;
|
||||
Out<ELFT>::Interp = Interp.get();
|
||||
Out<ELFT>::Plt = &Plt;
|
||||
Out<ELFT>::RelaDyn = &RelaDyn;
|
||||
Out<ELFT>::RelaPlt = RelaPlt.get();
|
||||
|
|
@ -474,12 +482,6 @@ uint32_t elf::toPhdrFlags(uint64_t Flags) {
|
|||
return Ret;
|
||||
}
|
||||
|
||||
// Various helper functions
|
||||
template <class ELFT> bool elf::needsInterpSection() {
|
||||
return !Symtab<ELFT>::X->getSharedFiles().empty() &&
|
||||
!Config->DynamicLinker.empty();
|
||||
}
|
||||
|
||||
template <class ELFT> bool elf::isOutputDynamic() {
|
||||
return !Symtab<ELFT>::X->getSharedFiles().empty() || Config->Pic;
|
||||
}
|
||||
|
|
@ -843,7 +845,7 @@ template <class ELFT> void Writer<ELFT>::addPredefinedSections() {
|
|||
|
||||
// Add .interp at first because some loaders want to see that section
|
||||
// on the first page of the executable file when loaded into memory.
|
||||
if (needsInterpSection<ELFT>())
|
||||
if (Out<ELFT>::Interp)
|
||||
OutputSections.insert(OutputSections.begin(), Out<ELFT>::Interp);
|
||||
|
||||
// This order is not the same as the final output order
|
||||
|
|
@ -962,7 +964,7 @@ std::vector<PhdrEntry<ELFT>> Writer<ELFT>::createPhdrs() {
|
|||
Hdr.add(Out<ELFT>::ProgramHeaders);
|
||||
|
||||
// PT_INTERP must be the second entry if exists.
|
||||
if (needsInterpSection<ELFT>()) {
|
||||
if (Out<ELFT>::Interp) {
|
||||
Phdr &Hdr = *AddHdr(PT_INTERP, toPhdrFlags(Out<ELFT>::Interp->getFlags()));
|
||||
Hdr.add(Out<ELFT>::Interp);
|
||||
}
|
||||
|
|
@ -1332,11 +1334,6 @@ template struct elf::PhdrEntry<ELF32BE>;
|
|||
template struct elf::PhdrEntry<ELF64LE>;
|
||||
template struct elf::PhdrEntry<ELF64BE>;
|
||||
|
||||
template bool elf::needsInterpSection<ELF32LE>();
|
||||
template bool elf::needsInterpSection<ELF32BE>();
|
||||
template bool elf::needsInterpSection<ELF64LE>();
|
||||
template bool elf::needsInterpSection<ELF64BE>();
|
||||
|
||||
template bool elf::isOutputDynamic<ELF32LE>();
|
||||
template bool elf::isOutputDynamic<ELF32BE>();
|
||||
template bool elf::isOutputDynamic<ELF64LE>();
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ template <class ELFT> class ObjectFile;
|
|||
template <class ELFT> class SymbolTable;
|
||||
template <class ELFT> void writeResult(SymbolTable<ELFT> *Symtab);
|
||||
template <class ELFT> void markLive();
|
||||
template <class ELFT> bool needsInterpSection();
|
||||
template <class ELFT> bool isOutputDynamic();
|
||||
template <class ELFT> bool isRelroSection(OutputSectionBase<ELFT> *Sec);
|
||||
template <class ELFT> bool needsPtLoad(OutputSectionBase<ELFT> *Sec);
|
||||
|
|
|
|||
Loading…
Reference in New Issue