summaryrefslogtreecommitdiffstats
path: root/src/strip.c
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2018-10-13 10:27:47 +0200
committerMark Wielaard <[email protected]>2018-10-17 13:49:53 +0200
commitc06ab0bbb4761a69d2f188675d21d1a9131e9ecb (patch)
treecf6bc383262aaed1029562f2364893acfa38ddd6 /src/strip.c
parent2876b3b648f665736ac9c879d34de5e3866ba8f9 (diff)
strip, unstrip: Handle SHT_GROUP correctly.
The usage of annobin in Fedora showed a couple of bugs when using eu-strip and eu-unstrip on ET_REL files that contain multiple group sections. When stripping we should not remove the SHF_GROUP flag from sections even if the group section itself might be removed. Either the section itself gets removed, and so the flag doesn't matter. Or it gets moved together with the group section into the debug file, and then it still needs to have the flag set. Also we would "renumber" the section group flag field (which isn't a section index, and so shouldn't be changed). Often the group sections have the exact same name (".group"), flags (none) and sometimes the same sizes. Which makes matching them hard. Extract the group signature and compare those when comparing two group sections. Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'src/strip.c')
-rw-r--r--src/strip.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/strip.c b/src/strip.c
index 1f7b3cab..fdebc5e2 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -792,9 +792,13 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
if (shdr_info[shdr_info[cnt].group_idx].idx == 0)
{
- /* The section group section will be removed. */
+ /* The section group section might be removed.
+ Don't remove the SHF_GROUP flag. The section is
+ either also removed, in which case the flag doesn't matter.
+ Or it moves with the group into the debug file, then
+ it will be reconnected with the new group and should
+ still have the flag set. */
shdr_info[cnt].group_idx = 0;
- shdr_info[cnt].shdr.sh_flags &= ~SHF_GROUP;
}
}
@@ -1368,7 +1372,9 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
&& shdr_info[cnt].data->d_buf != NULL);
Elf32_Word *grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf;
- for (size_t inner = 0;
+ /* First word is the section group flag.
+ Followed by section indexes, that need to be renumbered. */
+ for (size_t inner = 1;
inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word);
++inner)
if (grpref[inner] < shnum)