public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] tests: Handle compressed sections in next_cfi testcase.
@ 2018-07-05 14:28 Mark Wielaard
  0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2018-07-05 14:28 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Martin Liska, Mark Wielaard

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-07-05 14:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-05 14:28 [PATCH] tests: Handle compressed sections in next_cfi testcase Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).