From 4d169bdca2167c42d1a2bac2cfc9f60e6a864034 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 26 Feb 2016 16:38:39 +0000 Subject: [PATCH] Simplify. NFC. Regarding the comment, it is out of context because it describes what it does not do there. It got too long because it was originally two different comments that were simply merged together. The semantics is described in fixAbsoluteSymbols, so we don't need it. llvm-svn: 262031 --- lld/ELF/Writer.cpp | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index cbd7853..343f3fc 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -914,30 +914,22 @@ template void Writer::addReservedSymbols() { if (!isOutputDynamic()) Symtab.addIgnored("__tls_get_addr"); - auto Define = [this](StringRef Name, StringRef Alias, Elf_Sym &Sym) { - if (Symtab.find(Name)) - Symtab.addAbsolute(Name, Sym); - if (SymbolBody *B = Symtab.find(Alias)) + auto Define = [this](StringRef S, Elf_Sym &Sym) { + if (Symtab.find(S)) + Symtab.addAbsolute(S, Sym); + + // The name without the underscore is not a reserved name, + // so it is defined only when there is a reference against it. + assert(Name.startswith("_")); + S = S.substr(1); + if (SymbolBody *B = Symtab.find(S)) if (B->isUndefined()) - Symtab.addAbsolute(Alias, Sym); + Symtab.addAbsolute(S, Sym); }; - // If the "_end" symbol is referenced, it is expected to point to the address - // right after the data segment. Usually, this symbol points to the end - // of .bss section or to the end of .data section if .bss section is absent. - // We don't know the final address of _end yet, so just add a symbol here, - // and fix ElfSym::End.st_value later. - // Define "end" as an alias to "_end" if it is used but not defined. - // We don't want to define that unconditionally because we don't want to - // break programs that uses "end" as a regular symbol. - // The similar history with _etext/etext and _edata/edata: - // Address of _etext is the first location after the last read-only loadable - // segment. Address of _edata points to the end of the last non SHT_NOBITS - // section. That is how gold/bfd do. We update the values for these symbols - // later, after assigning sections to segments. - Define("_end", "end", ElfSym::End); - Define("_etext", "etext", ElfSym::Etext); - Define("_edata", "edata", ElfSym::Edata); + Define("_end", ElfSym::End); + Define("_etext", ElfSym::Etext); + Define("_edata", ElfSym::Edata); } // Sort input sections by section name suffixes for -- 2.7.4