[lld] r256445 - Define SECNAME_{start, end} symbols in a separate function. NFC.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 26 01:48:01 PST 2015
Author: ruiu
Date: Sat Dec 26 03:48:00 2015
New Revision: 256445
URL: http://llvm.org/viewvc/llvm-project?rev=256445&view=rev
Log:
Define SECNAME_{start,end} symbols in a separate function. NFC.
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=256445&r1=256444&r2=256445&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sat Dec 26 03:48:00 2015
@@ -80,6 +80,7 @@ private:
unsigned getNumSections() const { return OutputSections.size() + 1; }
void addRelIpltSymbols();
+ void addStartEndSymbols();
void addStartStopSymbols(OutputSectionBase<ELFT> *Sec);
void setPhdr(Elf_Phdr *PH, uint32_t Type, uint32_t Flags, uintX_t FileOff,
uintX_t VA, uintX_t Size, uintX_t Align);
@@ -772,24 +773,10 @@ template <class ELFT> void Writer<ELFT>:
Out<ELFT>::Dynamic->FiniArraySec =
Factory.lookup(".fini_array", SHT_FINI_ARRAY, SHF_WRITE | SHF_ALLOC);
- auto AddStartEnd = [&](StringRef Start, StringRef End,
- OutputSectionBase<ELFT> *OS) {
- if (OS) {
- Symtab.addSynthetic(Start, *OS, 0);
- Symtab.addSynthetic(End, *OS, OS->getSize());
- } else {
- Symtab.addIgnored(Start);
- Symtab.addIgnored(End);
- }
- };
-
- AddStartEnd("__preinit_array_start", "__preinit_array_end",
- Out<ELFT>::Dynamic->PreInitArraySec);
- AddStartEnd("__init_array_start", "__init_array_end",
- Out<ELFT>::Dynamic->InitArraySec);
- AddStartEnd("__fini_array_start", "__fini_array_end",
- Out<ELFT>::Dynamic->FiniArraySec);
-
+ // The linker needs to define SECNAME_start, SECNAME_end and SECNAME_stop
+ // symbols for sections, so that the runtime can get the start and end
+ // addresses of each section by section name. Add such symbols.
+ addStartEndSymbols();
for (OutputSectionBase<ELFT> *Sec : RegularSections)
addStartStopSymbols(Sec);
@@ -921,6 +908,28 @@ template <class ELFT> void Writer<ELFT>:
OutputSections.push_back(Out<ELFT>::Plt);
}
+// The linker is expected to define SECNAME_start and SECNAME_end
+// symbols for a few sections. This function defines them.
+template <class ELFT> void Writer<ELFT>::addStartEndSymbols() {
+ auto Define = [&](StringRef Start, StringRef End,
+ OutputSectionBase<ELFT> *OS) {
+ if (OS) {
+ Symtab.addSynthetic(Start, *OS, 0);
+ Symtab.addSynthetic(End, *OS, OS->getSize());
+ } else {
+ Symtab.addIgnored(Start);
+ Symtab.addIgnored(End);
+ }
+ };
+
+ Define("__preinit_array_start", "__preinit_array_end",
+ Out<ELFT>::Dynamic->PreInitArraySec);
+ Define("__init_array_start", "__init_array_end",
+ Out<ELFT>::Dynamic->InitArraySec);
+ Define("__fini_array_start", "__fini_array_end",
+ Out<ELFT>::Dynamic->FiniArraySec);
+}
+
static bool isAlpha(char C) {
return ('a' <= C && C <= 'z') || ('A' <= C && C <= 'Z') || C == '_';
}
More information about the llvm-commits
mailing list