[lld] r276261 - Instantiate Interp output section only when needed.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 21 04:01:24 PDT 2016
Author: ruiu
Date: Thu Jul 21 06:01:23 2016
New Revision: 276261
URL: http://llvm.org/viewvc/llvm-project?rev=276261&view=rev
Log:
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.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/Writer.cpp
lld/trunk/ELF/Writer.h
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=276261&r1=276260&r2=276261&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Jul 21 06:01:23 2016
@@ -344,7 +344,7 @@ LinkerScript<ELFT>::createPhdrs(ArrayRef
switch (Cmd.Type) {
case PT_INTERP:
- if (needsInterpSection<ELFT>())
+ if (Out<ELFT>::Interp)
Added.add(Out<ELFT>::Interp);
break;
case PT_DYNAMIC:
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=276261&r1=276260&r2=276261&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Jul 21 06:01:23 2016
@@ -112,6 +112,11 @@ void elf::reportDiscarded(InputSectionBa
<< "' 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::writeRes
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::writeRes
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::writeRes
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::writeRes
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>:
// 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
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>();
Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=276261&r1=276260&r2=276261&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Thu Jul 21 06:01:23 2016
@@ -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);
More information about the llvm-commits
mailing list