<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Sep 24, 2015 at 8:08 AM, Davide Italiano via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: davide<br>
Date: Thu Sep 24 10:08:23 2015<br>
New Revision: 248499<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=248499&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=248499&view=rev</a><br>
Log:<br>
[ELF2] Add support for -discard-none.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D13083" rel="noreferrer" target="_blank">http://reviews.llvm.org/D13083</a><br>
<br>
Added:<br>
lld/trunk/test/elf2/discard-none.s<br>
Modified:<br>
lld/trunk/ELF/Config.h<br>
lld/trunk/ELF/Driver.cpp<br>
lld/trunk/ELF/Options.td<br>
lld/trunk/ELF/OutputSections.cpp<br>
lld/trunk/ELF/OutputSections.h<br>
lld/trunk/ELF/Writer.cpp<br>
<br>
Modified: lld/trunk/ELF/Config.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=248499&r1=248498&r2=248499&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=248499&r1=248498&r2=248499&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Config.h (original)<br>
+++ lld/trunk/ELF/Config.h Thu Sep 24 10:08:23 2015<br>
@@ -22,6 +22,7 @@ struct Configuration {<br>
bool Shared = false;<br>
bool DiscardAll = false;<br>
bool DiscardLocals = false;<br>
+ bool DiscardNone = false;<br>
bool ExportDynamic = false;<br>
};<br>
<br>
<br>
Modified: lld/trunk/ELF/Driver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=248499&r1=248498&r2=248499&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=248499&r1=248498&r2=248499&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Driver.cpp (original)<br>
+++ lld/trunk/ELF/Driver.cpp Thu Sep 24 10:08:23 2015<br>
@@ -88,6 +88,9 @@ void LinkerDriver::link(ArrayRef<const c<br>
if (Args.hasArg(OPT_discard_locals))<br>
Config->DiscardLocals = true;<br>
<br>
+ if (Args.hasArg(OPT_discard_none))<br>
+ Config->DiscardNone = true;<br>
+<br>
if (Args.hasArg(OPT_export_dynamic))<br>
Config->ExportDynamic = true;<br>
<br>
<br>
Modified: lld/trunk/ELF/Options.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=248499&r1=248498&r2=248499&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=248499&r1=248498&r2=248499&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Options.td (original)<br>
+++ lld/trunk/ELF/Options.td Thu Sep 24 10:08:23 2015<br>
@@ -28,6 +28,9 @@ def discard_locals : Flag<["-"], "discar<br>
def alias_discard_locals: Flag<["-"], "X">,<br>
Alias<discard_locals>;<br>
<br>
+def discard_none : Flag<["-"], "discard-none">,<br>
+ HelpText<"Keep all symbols in the symbol table">;<br>
+<br>
//===----------------------------------------------------------------------===//<br>
/// Ignored options<br>
//===----------------------------------------------------------------------===//<br>
<br>
Modified: lld/trunk/ELF/OutputSections.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=248499&r1=248498&r2=248499&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=248499&r1=248498&r2=248499&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/OutputSections.cpp (original)<br>
+++ lld/trunk/ELF/OutputSections.cpp Thu Sep 24 10:08:23 2015<br>
@@ -272,6 +272,15 @@ bool lld::elf2::includeInSymtab(const Sy<br>
return true;<br>
}<br>
<br>
+template <class ELFT><br>
+bool SymbolTableSection<ELFT>::shouldKeepInSymtab(StringRef SymName) {<br>
+ if (Config->DiscardNone)<br>
+ return true;<br>
+<br>
+ // ELF defines dynamic locals as symbols which name starts with ".L".<br>
+ return !(Config->DiscardLocals && SymName.startswith(".L"));<br>
+}<br></blockquote><div><br></div><div>This function doesn't seem to depend on any class or instance, so I'd make this a static non-member function instead of a member function of SymbolTableSection<ELFT>.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
bool lld::elf2::includeInDynamicSymtab(const SymbolBody &B) {<br>
if (Config->ExportDynamic || Config->Shared)<br>
return true;<br>
@@ -294,7 +303,7 @@ template <class ELFT> void SymbolTableSe<br>
auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);<br>
uint32_t SecIndex = Sym.st_shndx;<br>
ErrorOr<StringRef> SymName = Sym.getName(File.getStringTable());<br>
- if (Config->DiscardLocals && SymName->startswith(".L"))<br>
+ if (SymName && !shouldKeepInSymtab(*SymName))<br>
continue;<br>
ESym->st_name = (SymName) ? StrTabSec.getFileOff(*SymName) : 0;<br>
ESym->st_size = Sym.st_size;<br>
<br>
Modified: lld/trunk/ELF/OutputSections.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=248499&r1=248498&r2=248499&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=248499&r1=248498&r2=248499&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/OutputSections.h (original)<br>
+++ lld/trunk/ELF/OutputSections.h Thu Sep 24 10:08:23 2015<br>
@@ -186,6 +186,8 @@ public:<br>
++NumLocals;<br>
}<br>
<br>
+ bool shouldKeepInSymtab(StringRef Name);<br>
+<br>
StringTableSection<ELFT::Is64Bits> &getStrTabSec() const { return StrTabSec; }<br>
unsigned getNumSymbols() const { return NumVisible + 1; }<br>
<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=248499&r1=248498&r2=248499&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=248499&r1=248498&r2=248499&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Thu Sep 24 10:08:23 2015<br>
@@ -336,7 +336,7 @@ template <class ELFT> void Writer<ELFT>:<br>
Elf_Sym_Range Syms = File.getLocalSymbols();<br>
for (const Elf_Sym &Sym : Syms) {<br>
ErrorOr<StringRef> SymName = Sym.getName(File.getStringTable());<br>
- if (SymName && !(Config->DiscardLocals && SymName->startswith(".L")))<br>
+ if (SymName && SymTabSec.shouldKeepInSymtab(*SymName))<br>
SymTabSec.addSymbol(*SymName, true);<br>
}<br>
}<br>
<br>
Added: lld/trunk/test/elf2/discard-none.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/discard-none.s?rev=248499&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/discard-none.s?rev=248499&view=auto</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/discard-none.s (added)<br>
+++ lld/trunk/test/elf2/discard-none.s Thu Sep 24 10:08:23 2015<br>
@@ -0,0 +1,58 @@<br>
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux -save-temp-labels %s -o %t<br>
+// RUN: lld -flavor gnu2 -discard-none -shared %t -o %t2<br>
+// RUN: llvm-readobj -s -sd -t %t2 | FileCheck %s<br>
+// REQUIRES: x86<br>
+<br>
+.text<br>
+.Lmyvar:<br>
+.Lmyothervar:<br>
+<br>
+// CHECK: Section {<br>
+// CHECK: Name: .strtab<br>
+// CHECK-NEXT: Type: SHT_STRTAB<br>
+// CHECK-NEXT: Flags [<br>
+// CHECK-NEXT: ]<br>
+// CHECK-NEXT: Address:<br>
+// CHECK-NEXT: Offset:<br>
+// CHECK-NEXT: Size:<br>
+// CHECK-NEXT: Link:<br>
+// CHECK-NEXT: Info:<br>
+// CHECK-NEXT: AddressAlignment:<br>
+// CHECK-NEXT: EntrySize:<br>
+// CHECK-NEXT: SectionData (<br>
+// CHECK-NEXT: 0000: 002E7465 7874002E 62737300 2E64796E |..text..bss..dyn|<br>
+// CHECK-NEXT: 0010: 73747200 2E4C6D79 76617200 2E4C6D79 |str..Lmyvar..Lmy|<br>
+// CHECK-NEXT: 0020: 6F746865 72766172 002E6479 6E73796D |othervar..dynsym|<br>
+// CHECK-NEXT: 0030: 002E6861 7368002E 64796E61 6D696300 |..hash..dynamic.|<br>
+// CHECK-NEXT: 0040: 2E737472 74616200 2E73796D 74616200 |.strtab..symtab.|<br>
+// CHECK-NEXT: 0050: 2E646174 6100 |.data.|<br>
+// CHECK-NEXT: )<br>
+// CHECK-NEXT: }<br>
+<br>
+// CHECK: Symbol {<br>
+// CHECK-NEXT: Name:<br>
+// CHECK-NEXT: Value: 0x0<br>
+// CHECK-NEXT: Size: 0<br>
+// CHECK-NEXT: Binding: Local<br>
+// CHECK-NEXT: Type: None<br>
+// CHECK-NEXT: Other: 0<br>
+// CHECK-NEXT: Section: Undefined<br>
+// CHECK-NEXT: }<br>
+// CHECK-NEXT: Symbol {<br>
+// CHECK-NEXT: Name: .Lmyothervar<br>
+// CHECK-NEXT: Value: 0x1000<br>
+// CHECK-NEXT: Size: 0<br>
+// CHECK-NEXT: Binding: Local<br>
+// CHECK-NEXT: Type: None<br>
+// CHECK-NEXT: Other: 0<br>
+// CHECK-NEXT: Section: .text<br>
+// CHECK-NEXT: }<br>
+// CHECK-NEXT: Symbol {<br>
+// CHECK-NEXT: Name: .Lmyvar<br>
+// CHECK-NEXT: Value: 0x1000<br>
+// CHECK-NEXT: Size: 0<br>
+// CHECK-NEXT: Binding: Local<br>
+// CHECK-NEXT: Type: None<br>
+// CHECK-NEXT: Other: 0<br>
+// CHECK-NEXT: Section: .text<br>
+// CHECK-NEXT: }<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>