[Bug general/23370] run-next-cfi-self.sh doesn't handle compressed ELF sections

2018-07-05 Thread mark at klomp dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=23370

Mark Wielaard  changed:

   What|Removed |Added

 CC||mark at klomp dot org
Summary|run-next-cfi-self.sh fails  |run-next-cfi-self.sh
   |on armv7l   |doesn't handle compressed
   ||ELF sections

--- Comment #1 from Mark Wielaard  ---
Although relocations in ET_REL files could be an issue, they aren't actually
for this test, because the relocations that are there are against the addresses
inside to .debug_frame section, and we don't care what they are in this test
case.

[We do really need some easier way to apply simple relocations when dealing
with ET_REL files (currently you need to create a Dwfl, which is a bit overkill
in this case).]

The real issue in this case is that the toolchain that created this test file
(size.o) used ELF debug section compression:

[35] .debug_frame PROGBITS  0057e4 c5  0 C  0   0 
4
 [ELF ZLIB (1) 000154  4]

(Oddly enough it seems it only does this for ET_REL files and the linker again
decompresses again when creating the ET_EXEC/DYN files. Which seems horribly
inefficient.)

So the real fix is to just uncompress the section in the test:

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 

 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);
}
}
 }

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

2018-07-05 Thread 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 
---
 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  
+
+   * 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  
 
* 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 
 
 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



Re: [PATCH 1/2] Require gawk in maintainer mode

2018-07-05 Thread Mark Wielaard
On Wed, Jul 04, 2018 at 12:11:07PM +0100, Ross Burton wrote:
> gawk is required to build known_dwarf.h, so check for it in configure.ac.

Thanks. Added a ChangeLog entry and pushed to master.


Re: [PATCH 2/2] Consolidate error.h inclusion in system.h

2018-07-05 Thread Mark Wielaard
On Wed, Jul 04, 2018 at 12:11:08PM +0100, Ross Burton wrote:
> error.h isn't standard and so isn't part of the musl C library.  To easy 
> future
> porting, consolidate the inclusion of error.h into system.h.
> 
> https://sourceware.org/bugzilla/show_bug.cgi?id=21008

Thanks, added ChangeLog entries and pushed to master.

But this isn't real solution. error is a useful GNU extension
that is widely used in the code base. So I think if you really
do want to use an alternative glibc implementation that it should
just provide error.

Cheers,

Mark


Re: [PATCH] readelf: Don't shadow index function from string.h

2018-07-05 Thread Mark Wielaard
On Wed, Jul 04, 2018 at 04:13:26PM +0200, Mark Wielaard wrote:
> On some ancient GCC versions (4.4.7 at least) -Wshadow warns about local
> variables "shadowing" global function definitions.
> 
>   readelf.c: In function ‘print_debug_addr_section’:
>   readelf.c:5265: error: declaration of ‘index’ shadows a global declaration
>   /usr/include/string.h:489: error: shadowed declaration is here
> 
> This is silly of course, but easy to work around.

Pushed to master.