diff options
| author | Mark Wielaard <[email protected]> | 2015-08-11 21:38:38 +0200 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2015-10-05 21:55:51 +0200 |
| commit | df7dfab451246e8b088040e052ca01f9d6aba774 (patch) | |
| tree | 7c6bf28c6ac102a94a7ebcd9c2ee87e5b29141c9 /src/strip.c | |
| parent | 3adda3ce2a83e2733aa0c84da9bb7949413d02fd (diff) | |
Handle merged strtab/shstrtab string tables in strip and unstrip.
ELF files can share the section header string table (e_shstrndx) with
the symtab .strtab section. That might in some cases save a bit of space
since symbols and sections might share some (sub)strings. To handle that
eu-strip just needs to not unconditionally remove the .shstrtab section
(it will be properly marked as used/unused as needed). eu-unstrip needs
to make sure the section names are added to the strtab if it decides to
rewrite that section. Also makes sure that eu-strip won't move around
a SHT_NOBITS section that has SHF_ALLOC set. Although it is allowed to
move such sections around, there is no benefit. And some tools might
expect no allocated section to move around, not even a nobits section.
It also makes it harder to do "roundtripping" sanity checks that make
sure splitting a file with eu-strip and then reconstructed with eu-unstrip
produce the same ELF file (as is done in the new run-strip-strmerge.sh).
Introduces a somewhat large test generator elfstrmerge.c that will
hopefully turn into a more generic string table merger program.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'src/strip.c')
| -rw-r--r-- | src/strip.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/strip.c b/src/strip.c index 8b08d72d..41169eda 100644 --- a/src/strip.c +++ b/src/strip.c @@ -644,10 +644,12 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, goto illformed; /* Sections in files other than relocatable object files which - don't contain any file content or are not loaded can be freely - moved by us. In relocatable object files everything can be moved. */ + not loaded can be freely moved by us. In theory we can also + freely move around allocated nobits sections. But we don't + to keep the layout of all allocated sections as similar as + possible to the original file. In relocatable object files + everything can be moved. */ if (ehdr->e_type == ET_REL - || shdr_info[cnt].shdr.sh_type == SHT_NOBITS || (shdr_info[cnt].shdr.sh_flags & SHF_ALLOC) == 0) shdr_info[cnt].shdr.sh_offset = 0; @@ -1035,9 +1037,10 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, } } - /* Mark the section header string table as unused, we will create - a new one. */ - shdr_info[shstrndx].idx = 0; + /* Although we always create a new section header string table we + don't explicitly mark the existing one as unused. It can still + be used through a symbol table section we are keeping. If not it + will already be marked as unused. */ /* We need a string table for the section headers. */ shst = ebl_strtabinit (true); |
