From b40001f67c0809e2fe8c7a78c2a5ac12026f23b4 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 5 Jul 2018 16:24:57 +0200 Subject: [PATCH] tests: Handle compressed sections in next_cfi testcase. Some toolchains use compressed ELF sections by default. This would make run-next-cfi-self.sh fail because it would try to decode the compressed data. Fix by decompressing the section first. https://sourceware.org/bugzilla/show_bug.cgi?id=23370 Signed-off-by: Mark Wielaard --- tests/ChangeLog | 7 +++++++ tests/next_cfi.c | 27 +++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/ChangeLog b/tests/ChangeLog index 61b5037..0677b9f 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,10 @@ +2018-07-05 Mark Wielaard + + * next_cfi.c (handle_section): Take a new argument name. Check + whether the section is compressed and uncompress if so. + (main): Check also for .zdebug_frame and pass the name of the + section to handle_section. + 2018-07-04 Ross Burton * addrscopes.c: Remove error.h include, add system.h include. diff --git a/tests/next_cfi.c b/tests/next_cfi.c index fae0028..6a847b4 100644 --- a/tests/next_cfi.c +++ b/tests/next_cfi.c @@ -33,7 +33,7 @@ #include "system.h" void -handle_section (const unsigned char e_ident[], +handle_section (char *name, const unsigned char e_ident[], Elf_Scn *scn, const bool is_eh) { if (is_eh) @@ -41,6 +41,24 @@ handle_section (const unsigned char e_ident[], else printf (".debug_frame\n"); + GElf_Shdr mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &mem); + if (shdr == NULL) + error (EXIT_FAILURE, 0, "Couldn't get section header: %s", + elf_errmsg (-1)); + if ((shdr->sh_flags & SHF_COMPRESSED) != 0) + { + if (elf_compress (scn, 0, 0) < 0) + error (EXIT_FAILURE, 0, "Couldn't decompress section: %s", + elf_errmsg (-1)); + } + else if (name[0] == '.' && name[1] == 'z') + { + if (elf_compress_gnu (scn, 0, 0) < 0) + error (EXIT_FAILURE, 0, "Couldn't decompress section: %s", + elf_errmsg (-1)); + } + Elf_Data *data = elf_getdata (scn, NULL); if (data == NULL || data->d_buf == NULL) error (EXIT_FAILURE, 0, "no section data"); @@ -117,9 +135,10 @@ main (int argc, char *argv[]) if (name != NULL && shdr.sh_type == SHT_PROGBITS) { if (strcmp (name, ".eh_frame") == 0) - handle_section (ident, scn, true); - if (strcmp (name, ".debug_frame") == 0) - handle_section (ident, scn, false); + handle_section (name, ident, scn, true); + if (strcmp (name, ".debug_frame") == 0 + || strcmp (name, ".zdebug_frame") == 0) + handle_section (name, ident, scn, false); } } } -- 2.7.4