bool discardLocals() const { return _discardLocals; }
void setDiscardLocals(bool d) { _discardLocals = d; }
+ /// \brief Discard temprorary local symbols.
+ bool discardTempLocals() const { return _discardTempLocals; }
+ void setDiscardTempLocals(bool d) { _discardTempLocals = d; }
+
/// \brief Strip symbols.
bool stripSymbols() const { return _stripSymbols; }
void setStripSymbols(bool strip) { _stripSymbols = strip; }
bool _noAllowDynamicLibraries = false;
bool _mergeRODataToTextSegment = true;
bool _demangle = true;
+ bool _discardTempLocals = false;
bool _discardLocals = false;
bool _stripSymbols = false;
bool _alignSegments = true;
if (parsedArgs->hasArg(OPT_discard_loc))
ctx->setDiscardLocals(true);
+ if (parsedArgs->hasArg(OPT_discard_temp_loc))
+ ctx->setDiscardTempLocals(true);
+
if (parsedArgs->hasArg(OPT_strip_all))
ctx->setStripSymbols(true);
Group<grp_symbolopts>;
def alias_discard_loc: Flag<["-"], "x">,
Alias<discard_loc>;
+def discard_temp_loc : Flag<["--"], "discard-locals">,
+ HelpText<"Discard temporary local symbols">,
+ Group<grp_symbolopts>;
+def alias_discard_temp_loc : Flag<["-"], "X">,
+ Alias<discard_temp_loc>;
def no_demangle : Flag<["--"], "no-demangle">,
HelpText<"Dont demangle C++ symbols">,
Group<grp_symbolopts>;
if (this->_ctx.discardLocals() && symbol.getBinding() == llvm::ELF::STB_LOCAL)
return;
+ // Temporary locals are all the symbols which name starts with .L.
+ // This is defined by the ELF standard.
+ if (this->_ctx.discardTempLocals() && atom->name().startswith(".L"))
+ return;
+
_symbolTable.push_back(SymbolEntry(atom, symbol, atomLayout));
this->_fsize += sizeof(Elf_Sym);
if (this->_flags & SHF_ALLOC)
--- /dev/null
+# Test that -X/--discard-locals works.
+#
+#RUN: yaml2obj -format=elf %s -o=%t.o
+#RUN: lld -flavor gnu %t.o -shared -X -o %t1
+#RUN: llvm-objdump -t %t1 | FileCheck %s
+
+#CHECK-NOT: 0000000000400121 l .rodata 00000000 .Lsym8
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_FREEBSD
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x0000000000000004
+ Content: 00000000F20F100D00000000C3
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000004
+ Content: ''
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x0000000000000004
+ Content: ''
+ - Name: .rodata.str1.1
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ]
+ AddressAlign: 0x0000000000000001
+ Content: ''
+ - Name: .rela.text
+ Type: SHT_RELA
+ Link: .symtab
+ AddressAlign: 0x0000000000000008
+ Info: .text
+ Relocations:
+ - Offset: 0x0000000000000008
+ Symbol: .Lsym8
+ Type: R_X86_64_PC32
+ Addend: -4
+Symbols:
+ Local:
+ - Name: .Lsym8
+ Section: .rodata.str1.1
+ - Name: test
+ Section: .text
+ Value: 0x000000000000000C
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .data
+ Type: STT_SECTION
+ Section: .data
+ - Name: .bss
+ Type: STT_SECTION
+ Section: .bss
+ - Name: .rodata.str1.1
+ Type: STT_SECTION
+ Section: .rodata.str1.1
+...