[ELF] Implement --strip-all/-s

Differential Revision:	D7489
Reviewed by:	shankarke

llvm-svn: 228533
This commit is contained in:
Davide Italiano 2015-02-08 19:42:15 +00:00
parent 3fa03da6f8
commit 1fd20ff599
6 changed files with 127 additions and 2 deletions

View File

@ -292,6 +292,10 @@ public:
bool alignSegments() const { return _alignSegments; }
void setAlignSegments(bool align) { _alignSegments = align; }
/// \brief Strip symbols.
bool stripSymbols() const { return _stripSymbols; }
void setStripSymbols(bool strip) { _stripSymbols = strip; }
// We can parse several linker scripts via command line whose ASTs are stored
// in the current linking context via addLinkerScript().
void addLinkerScript(std::unique_ptr<script::Parser> script) {
@ -322,6 +326,7 @@ protected:
bool _noAllowDynamicLibraries;
bool _mergeRODataToTextSegment;
bool _demangle;
bool _stripSymbols;
bool _alignSegments;
bool _nostdlib;
llvm::Optional<uint64_t> _maxPageSize;

View File

@ -685,6 +685,11 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
break;
}
case OPT_strip_all: {
ctx->setStripSymbols(true);
break;
}
case OPT_soname:
ctx->setSharedObjectName(inputArg->getValue());
break;

View File

@ -239,6 +239,11 @@ def demangle : Flag<["--"], "demangle">,
def no_demangle : Flag<["--"], "no-demangle">,
HelpText<"Dont demangle C++ symbols">,
Group<grp_symbolopts>;
def strip_all : Flag<["--"], "strip-all">,
HelpText<"Omit all symbol informations from output">,
Group<grp_symbolopts>;
def alias_strip_all : Flag<["-"], "s">,
Alias<strip_all>;
//===----------------------------------------------------------------------===//
/// Optimization Options

View File

@ -60,7 +60,8 @@ ELFLinkingContext::ELFLinkingContext(
_isStaticExecutable(false), _noInhibitExec(false), _exportDynamic(false),
_mergeCommonStrings(false), _useShlibUndefines(true),
_dynamicLinkerArg(false), _noAllowDynamicLibraries(false),
_mergeRODataToTextSegment(true), _demangle(true), _alignSegments(true),
_mergeRODataToTextSegment(true), _demangle(true),
_stripSymbols(false), _alignSegments(true),
_outputMagic(OutputMagic::DEFAULT), _initFunction("_init"),
_finiFunction("_fini"), _sysrootPath("") {}

View File

@ -417,7 +417,9 @@ std::error_code OutputELFWriter<ELFT>::buildOutput(const File &file) {
buildAtomToAddressMap(file);
// Create symbol table and section string table
buildStaticSymbolTable(file);
// Do it only if -s is not specified.
if (!_context.stripSymbols())
buildStaticSymbolTable(file);
// Finalize the layout by calling the finalize() functions
_layout.finalize();

107
lld/test/elf/strip-all.test Normal file
View File

@ -0,0 +1,107 @@
# Tests the --strip-all (-s) flag. We expect the symbol table to not contain
# any symbol in the output file.
#
# The following code was used to generate the object.
# $ clang -c blah.c -o blah
#
# void
# callMeMaybe(int *v)
# {
# *v += 1;
# }
#
# int
# main(void)
# {
#
# int blah = 42;
# callMeMaybe(&blah);
# }
#RUN: yaml2obj -format=elf %s -o=%t.o
#RUN: lld -flavor gnu -target x86_64 %t.o -e=main --strip-all -o %t1
#RUN: llvm-readobj -dt %t1 | FileCheck -check-prefix CHECKSYMS %s
#CHECKSYMS: @
---
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: 0x0000000000000010
Content: 554889E548897DF8488B7DF88B07050100000089075DC3660F1F840000000000554889E54883EC10488D7DFCC745FC2A000000E8C8FFFFFFB8000000004883C4105DC3
- 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: .comment
Type: SHT_PROGBITS
Flags: [ SHF_MERGE, SHF_STRINGS ]
AddressAlign: 0x0000000000000001
Content: 004672656542534420636C616E672076657273696F6E20332E342E312028746167732F52454C454153455F33342F646F74312D66696E616C203230383033322920323031343035313200
- Name: .note.GNU-stack
Type: SHT_PROGBITS
AddressAlign: 0x0000000000000001
Content: ''
- Name: .eh_frame
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
AddressAlign: 0x0000000000000008
Content: 1400000000000000017A5200017810011B0C070890010000180000001C000000000000001700000000410E108602430D060000001800000038000000000000002300000000410E108602430D06000000
- Name: .rela.eh_frame
Type: SHT_RELA
Link: .symtab
AddressAlign: 0x0000000000000008
Info: .eh_frame
Relocations:
- Offset: 0x0000000000000020
Symbol: .text
Type: R_X86_64_PC32
- Offset: 0x000000000000003C
Symbol: .text
Type: R_X86_64_PC32
Addend: 32
Symbols:
Local:
- Name: .text
Type: STT_SECTION
Section: .text
- Name: .data
Type: STT_SECTION
Section: .data
- Name: .bss
Type: STT_SECTION
Section: .bss
- Name: .comment
Type: STT_SECTION
Section: .comment
- Name: .note.GNU-stack
Type: STT_SECTION
Section: .note.GNU-stack
- Name: .eh_frame
Type: STT_SECTION
Section: .eh_frame
Global:
- Name: callMeMaybe
Type: STT_FUNC
Section: .text
Size: 0x0000000000000017
- Name: main
Type: STT_FUNC
Section: .text
Value: 0x0000000000000020
Size: 0x0000000000000023
...