public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: "mark at klomp dot org" <sourceware-bugzilla@sourceware.org>
To: elfutils-devel@sourceware.org
Subject: [Bug general/23370] run-next-cfi-self.sh doesn't handle compressed ELF sections
Date: Thu, 05 Jul 2018 14:21:00 -0000	[thread overview]
Message-ID: <bug-23370-10460-buuoTNH5R3@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-23370-10460@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=23370

Mark Wielaard <mark at klomp dot org> 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 <mark at klomp dot org> ---
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     00000000 0057e4 0000c5  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 <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);
            }
        }
     }

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

  reply	other threads:[~2018-07-05 14:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-04 14:12 [Bug general/23370] New: run-next-cfi-self.sh fails on armv7l mliska at suse dot cz
2018-07-05 14:21 ` mark at klomp dot org [this message]
2018-07-10 13:12 ` [Bug general/23370] run-next-cfi-self.sh doesn't handle compressed ELF sections mliska at suse dot cz
2018-07-10 17:48 ` mark at klomp dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-23370-10460-buuoTNH5R3@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).