[lld] r248133 - [ELF2] Implement support for -discard-locals.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 20 14:58:13 PDT 2015
Author: davide
Date: Sun Sep 20 16:58:12 2015
New Revision: 248133
URL: http://llvm.org/viewvc/llvm-project?rev=248133&view=rev
Log:
[ELF2] Implement support for -discard-locals.
This is not on by default, but it may make sense to change it in future.
Added:
lld/trunk/test/elf2/discard-locals.s
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Options.td
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=248133&r1=248132&r2=248133&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Sun Sep 20 16:58:12 2015
@@ -21,6 +21,7 @@ struct Configuration {
std::string RPath;
bool Shared = false;
bool DiscardAll = false;
+ bool DiscardLocals = false;
};
extern Configuration *Config;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=248133&r1=248132&r2=248133&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sun Sep 20 16:58:12 2015
@@ -85,6 +85,9 @@ void LinkerDriver::link(ArrayRef<const c
if (Args.hasArg(OPT_discard_all))
Config->DiscardAll = true;
+ if (Args.hasArg(OPT_discard_locals))
+ Config->DiscardLocals = true;
+
// Create a list of input files.
std::vector<MemoryBufferRef> Inputs;
Modified: lld/trunk/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Options.td?rev=248133&r1=248132&r2=248133&view=diff
==============================================================================
--- lld/trunk/ELF/Options.td (original)
+++ lld/trunk/ELF/Options.td Sun Sep 20 16:58:12 2015
@@ -18,3 +18,6 @@ def shared : Flag<["-"], "shared">,
def discard_all : Flag<["-"], "discard-all">,
HelpText<"Delete all local symbols">;
+
+def discard_locals : Flag<["-"], "discard-locals">,
+ HelpText<"Delete temporary local symbols">;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=248133&r1=248132&r2=248133&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sun Sep 20 16:58:12 2015
@@ -820,6 +820,8 @@ template <class ELFT> void SymbolTableSe
auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
uint32_t SecIndex = Sym.st_shndx;
ErrorOr<StringRef> SymName = Sym.getName(File.getStringTable());
+ if (Config->DiscardLocals && SymName->startswith(".L"))
+ continue;
ESym->st_name = (SymName) ? StrTabSec.getFileOff(*SymName) : 0;
ESym->st_size = Sym.st_size;
ESym->setBindingAndType(Sym.getBinding(), Sym.getType());
@@ -1044,7 +1046,7 @@ template <class ELFT> void Writer<ELFT>:
Elf_Sym_Range Syms = File.getLocalSymbols();
for (const Elf_Sym &Sym : Syms) {
ErrorOr<StringRef> SymName = Sym.getName(File.getStringTable());
- if (SymName)
+ if (SymName && !(Config->DiscardLocals && SymName->startswith(".L")))
SymTabSec.addSymbol(*SymName, true);
}
}
Added: lld/trunk/test/elf2/discard-locals.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/discard-locals.s?rev=248133&view=auto
==============================================================================
--- lld/trunk/test/elf2/discard-locals.s (added)
+++ lld/trunk/test/elf2/discard-locals.s Sun Sep 20 16:58:12 2015
@@ -0,0 +1,52 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux -save-temp-labels %s -o %t
+// RUN: lld -flavor gnu2 -discard-locals %t -o %t2
+// RUN: llvm-readobj -s -sd -t %t2 | FileCheck %s
+// REQUIRES: x86
+
+.global _start
+_start:
+
+.text
+.Lmyvar:
+.Lmyothervar:
+
+// CHECK: Section {
+// CHECK: Name: .strtab
+// CHECK-NEXT: Type: SHT_STRTAB
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address:
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size:
+// CHECK-NEXT: Link:
+// CHECK-NEXT: Info:
+// CHECK-NEXT: AddressAlignment:
+// CHECK-NEXT: EntrySize:
+// CHECK-NEXT: SectionData (
+// CHECK-NEXT: 0000: 002E7465 7874005F 73746172 74002E62
+// CHECK-NEXT: 0010: 7373002E 73747274 6162002E 73796D74
+// CHECK-NEXT: 0020: 6162002E 64617461 00
+// CHECK-NEXT: )
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+
+// CHECK: Symbols [
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name:
+// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Local
+// CHECK-NEXT: Type: None
+// CHECK-NEXT: Other: 0
+// CHECK-NEXT: Section: Undefined
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: _start
+// CHECK-NEXT: Value: 0x11000
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Global
+// CHECK-NEXT: Type: None
+// CHECK-NEXT: Other: 0
+// CHECK-NEXT: Section: .text
+// CHECK-NEXT: }
+// CHECk-NEXT: ]
More information about the llvm-commits
mailing list