summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2018-11-09 15:19:07 +0100
committerMark Wielaard <mark@klomp.org>2018-11-13 16:53:40 +0100
commitd3e6266754b95244063aa1e40c531fdd57259332 (patch)
tree0e7a087d2e349428b5acc63373b9083838880a76 /src
parent72e30c2e0cb49a9a300667fdd5ff09082f717950 (diff)
strip: Also handle gnu compressed debug sections with --reloc-debug-sections
Check whether a section was gnu compressed and decompress it first before trying to resolve relocations. Recompress it afterwards. This found a bug in elf_compress_gnu which would use the "raw" file contents even if the user had just created the section (copying over the section from the original input file). Add compressed ET_REL tests to run-strip-reloc.sh testcase. Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog5
-rw-r--r--src/strip.c29
2 files changed, 28 insertions, 6 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index f014de8f..7eecfcb5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-09 Mark Wielaard <mark@klomp.org>
+
+ * strip.c (remove_debug_relocations): Check if section is gnu
+ compressed and decompress and recompress it.
+
2018-11-12 Mark Wielaard <mark@klomp.org>
* elflint.c (check_note_data): Recognize NT_GNU_BUILD_ATTRIBUTE_OPEN
diff --git a/src/strip.c b/src/strip.c
index e953c4d5..15180737 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -485,12 +485,22 @@ remove_debug_relocations (Ebl *ebl, Elf *elf, GElf_Ehdr *ehdr,
(and recompress if necessary at the end). */
GElf_Chdr tchdr;
int tcompress_type = 0;
- if (gelf_getchdr (tscn, &tchdr) != NULL)
+ bool is_gnu_compressed = false;
+ if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0)
{
- tcompress_type = tchdr.ch_type;
- if (elf_compress (tscn, 0, 0) != 1)
+ is_gnu_compressed = true;
+ if (elf_compress_gnu (tscn, 0, 0) != 1)
INTERNAL_ERROR (fname);
}
+ else
+ {
+ if (gelf_getchdr (tscn, &tchdr) != NULL)
+ {
+ tcompress_type = tchdr.ch_type;
+ if (elf_compress (tscn, 0, 0) != 1)
+ INTERNAL_ERROR (fname);
+ }
+ }
Elf_Data *tdata = elf_getdata (tscn, NULL);
if (tdata == NULL || tdata->d_buf == NULL
@@ -686,9 +696,16 @@ remove_debug_relocations (Ebl *ebl, Elf *elf, GElf_Ehdr *ehdr,
shdr->sh_size = reldata->d_size = nrels * shdr->sh_entsize;
gelf_update_shdr (scn, shdr);
- if (tcompress_type != 0)
- if (elf_compress (tscn, tcompress_type, ELF_CHF_FORCE) != 1)
- INTERNAL_ERROR (fname);
+ if (is_gnu_compressed)
+ {
+ if (elf_compress_gnu (tscn, 1, ELF_CHF_FORCE) != 1)
+ INTERNAL_ERROR (fname);
+ }
+ else if (tcompress_type != 0)
+ {
+ if (elf_compress (tscn, tcompress_type, ELF_CHF_FORCE) != 1)
+ INTERNAL_ERROR (fname);
+ }
}
}
}