[lld] r235357 - [GNU/ELF] Add support for -X/--discard-locals.
Aaron Ballman
aaron at aaronballman.com
Thu Apr 23 08:11:02 PDT 2015
On Mon, Apr 20, 2015 at 6:52 PM, Davide Italiano <davide at freebsd.org> wrote:
> Author: davide
> Date: Mon Apr 20 17:52:56 2015
> New Revision: 235357
>
> URL: http://llvm.org/viewvc/llvm-project?rev=235357&view=rev
> Log:
> [GNU/ELF] Add support for -X/--discard-locals.
>
> There's (almost) never need to keep .L symbols around for production
> builds. In fact, the FreeBSD kernel explicitly specify -X beacuse the
> size impact (and the subsequent performance impact) might be significant,
> because we keep symbols in memory.
> I was tempted to make this the default, but I haven't (yet).
>
> PR: 23232
>
> Added:
> lld/trunk/test/elf/discard-locals.test
> Modified:
> lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
> lld/trunk/lib/Driver/GnuLdDriver.cpp
> lld/trunk/lib/Driver/GnuLdOptions.td
> lld/trunk/lib/ReaderWriter/ELF/SectionChunks.cpp
>
> Modified: lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h?rev=235357&r1=235356&r2=235357&view=diff
> ==============================================================================
> --- lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h (original)
> +++ lld/trunk/include/lld/ReaderWriter/ELFLinkingContext.h Mon Apr 20 17:52:56 2015
> @@ -314,6 +314,10 @@ public:
> 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; }
> @@ -370,6 +374,7 @@ protected:
> bool _noAllowDynamicLibraries = false;
> bool _mergeRODataToTextSegment = true;
> bool _demangle = true;
> + bool _discardTempLocals = false;
> bool _discardLocals = false;
> bool _stripSymbols = false;
> bool _alignSegments = true;
>
> Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=235357&r1=235356&r2=235357&view=diff
> ==============================================================================
> --- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
> +++ lld/trunk/lib/Driver/GnuLdDriver.cpp Mon Apr 20 17:52:56 2015
> @@ -478,6 +478,9 @@ bool GnuLdDriver::parse(int argc, const
> 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);
>
>
> Modified: lld/trunk/lib/Driver/GnuLdOptions.td
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdOptions.td?rev=235357&r1=235356&r2=235357&view=diff
> ==============================================================================
> --- lld/trunk/lib/Driver/GnuLdOptions.td (original)
> +++ lld/trunk/lib/Driver/GnuLdOptions.td Mon Apr 20 17:52:56 2015
> @@ -260,6 +260,11 @@ def discard_loc : Flag<["--"], "discard-
> 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>;
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.cpp?rev=235357&r1=235356&r2=235357&view=diff
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.cpp Mon Apr 20 17:52:56 2015
> @@ -489,6 +489,11 @@ void SymbolTable<ELFT>::addSymbol(const
> 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)
>
> Added: lld/trunk/test/elf/discard-locals.test
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/discard-locals.test?rev=235357&view=auto
> ==============================================================================
> --- lld/trunk/test/elf/discard-locals.test (added)
> +++ lld/trunk/test/elf/discard-locals.test Mon Apr 20 17:52:56 2015
> @@ -0,0 +1,66 @@
> +# 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
> +...
This test is failing for me on Windows, with:
>lit E:\llvm\llvm\tools\lld\test\elf\discard-locals.test
-- Testing: 1 tests, 1 threads --
FAIL: lld :: elf/discard-locals.test (1 of 1)
******************** TEST 'lld :: elf/discard-locals.test' FAILED
********************
Script:
--
yaml2obj -format=elf
E:\llvm\llvm\tools\lld\test\elf\discard-locals.test
-o=E:\llvm\2013\tools\lld\test\elf\Output\discard-locals.test.tmp.o
lld -flavor gnu
E:\llvm\2013\tools\lld\test\elf\Output\discard-locals.test.tmp.o
-shared -X -o E:\llvm\2013\tools\lld\test\elf\Output\discard-locals.test.tmp1
llvm-objdump -t
E:\llvm\2013\tools\lld\test\elf\Output\discard-locals.test.tmp1 |
FileCheck E:\llvm\llvm\tools\lld\test\elf\discard-locals.test
--
Exit Code: 1
Command Output (stdout):
--
Command 0: "yaml2obj" "-format=elf"
"E:\llvm\llvm\tools\lld\test\elf\discard-locals.test"
"-o=E:\llvm\2013\tools\lld\test\elf\Output\discard-locals.test.tmp.o"
Command 0 Result: 0
Command 0 Output:
Command 0 Stderr:
Command 1: "lld" "-flavor" "gnu"
"E:\llvm\2013\tools\lld\test\elf\Output\discard-locals.test.tmp.o"
"-shared" "-X" "-o"
"E:\llvm\2013\tools\lld\test\elf\Output\discard-locals.test.tmp1"
Command 1 Result: 1
Command 1 Output:
Command 1 Stderr:
Cannot open E:\llvm\2013\tools\lld\test\elf\Output\discard-locals.test.tmp.o:
incompatible machine type
--
********************
Testing Time: 0.04s
********************
Failing Tests (1):
lld :: elf/discard-locals.test
Unexpected Failures: 1
~Aaron
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list