[lld] r234130 - Strip .strtab and .symtab when --strip-all is used.
Davide Italiano
davide at freebsd.org
Sun Apr 5 15:47:55 PDT 2015
Author: davide
Date: Sun Apr 5 17:47:54 2015
New Revision: 234130
URL: http://llvm.org/viewvc/llvm-project?rev=234130&view=rev
Log:
Strip .strtab and .symtab when --strip-all is used.
This matches other linkers behaviour. Moreover, there's really
no need to keep them around.
Reported by: Rafael Avila de Espindola
PR: 22890
Modified:
lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h
lld/trunk/test/elf/strip-all.test
Modified: lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h?rev=234130&r1=234129&r2=234130&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/OutputELFWriter.h Sun Apr 5 17:47:54 2015
@@ -319,9 +319,11 @@ void OutputELFWriter<ELFT>::buildAtomToA
_atomToAddressMap[atom->_atom] = atom->_virtualAddr;
// Set the total number of atoms in the symbol table, so that appropriate
- // resizing of the string table can be done
- _symtab->setNumEntries(totalDefinedAtoms + totalAbsAtoms +
- totalUndefinedAtoms);
+ // resizing of the string table can be done.
+ // There's no such thing as symbol table if we're stripping all the symbols
+ if (!_ctx.stripSymbols())
+ _symtab->setNumEntries(totalDefinedAtoms + totalAbsAtoms +
+ totalUndefinedAtoms);
}
template<class ELFT>
@@ -395,18 +397,23 @@ template <class ELFT> void OutputELFWrit
_layout.setHeader(_elfHeader.get());
_layout.setProgramHeader(_programHeader.get());
- _symtab = std::move(this->createSymbolTable());
- _strtab.reset(new (_alloc) StringTable<ELFT>(
- _ctx, ".strtab", TargetLayout<ELFT>::ORDER_STRING_TABLE));
+ // Don't create .symtab and .strtab sections if we're going to
+ // strip all the symbols.
+ if (!_ctx.stripSymbols()) {
+ _symtab = std::move(this->createSymbolTable());
+ _strtab.reset(new (_alloc) StringTable<ELFT>(
+ _ctx, ".strtab", TargetLayout<ELFT>::ORDER_STRING_TABLE));
+ _layout.addSection(_symtab.get());
+ _layout.addSection(_strtab.get());
+ _symtab->setStringSection(_strtab.get());
+ }
+
_shstrtab.reset(new (_alloc) StringTable<ELFT>(
_ctx, ".shstrtab", TargetLayout<ELFT>::ORDER_SECTION_STRINGS));
_shdrtab.reset(new (_alloc) SectionHeader<ELFT>(
_ctx, TargetLayout<ELFT>::ORDER_SECTION_HEADERS));
- _layout.addSection(_symtab.get());
- _layout.addSection(_strtab.get());
_layout.addSection(_shstrtab.get());
_shdrtab->setStringSection(_shstrtab.get());
- _symtab->setStringSection(_strtab.get());
_layout.addSection(_shdrtab.get());
for (auto sec : _layout.sections()) {
Modified: lld/trunk/test/elf/strip-all.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/strip-all.test?rev=234130&r1=234129&r2=234130&view=diff
==============================================================================
--- lld/trunk/test/elf/strip-all.test (original)
+++ lld/trunk/test/elf/strip-all.test Sun Apr 5 17:47:54 2015
@@ -1,5 +1,5 @@
-# Tests the --strip-all (-s) flag. We expect the symbol table to not contain
-# any symbol in the output file.
+# Tests the --strip-all (-s) flag.
+# We expect that .symtab and .strtab are stripped from the final executable.
#
# The following code was used to generate the object.
# $ clang -c blah.c -o blah
@@ -20,9 +20,11 @@
#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
+#RUN: llvm-objdump -section-headers %t1 | FileCheck %s
-#CHECKSYMS: @
+#CHECK: 14 .shstrtab 0000007d 0000000000000000
+#CHECK-NOT: 15 .symtab 00000198 0000000000000000
+#CHECK-NOT: 16 .strtab 000000e4 0000000000000000
---
FileHeader:
More information about the llvm-commits
mailing list