[PATCH] tests: Handle compressed sections in next_cfi testcase.

Mark Wielaard mark@klomp.org
Thu Jul 5 14:28:00 GMT 2018


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 <mark@klomp.org>
---
 tests/ChangeLog  |  7 +++++++
 tests/next_cfi.c | 27 +++++++++++++++++++++++----
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 765a874..55ba748 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,10 @@
+2018-07-05  Mark Wielaard  <mark@klomp.org>
+
+	* 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-06-28  Mark Wielaard  <mark@klomp.org>
 
 	* next_cfi.c: New file.
diff --git a/tests/next_cfi.c b/tests/next_cfi.c
index b923744..ae324c4 100644
--- a/tests/next_cfi.c
+++ b/tests/next_cfi.c
@@ -33,7 +33,7 @@
 #include <unistd.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);
 	    }
 	}
     }
-- 
1.8.3.1



More information about the Elfutils-devel mailing list