public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Milian Wolff <milian.wolff@kdab.com>
Cc: elfutils-devel@sourceware.org
Subject: Re: [PATCH] Also find CFI in sections of type SHT_X86_64_UNWIND
Date: Tue, 06 Nov 2018 11:07:00 -0000	[thread overview]
Message-ID: <f8b7a2805eed658a3e8dfeb8b81d7f15653d838a.camel@klomp.org> (raw)
In-Reply-To: <2537678.yolsnJm5dN@agathebauer>

[-- Attachment #1: Type: text/plain, Size: 1386 bytes --]

Hi Milian,

On Tue, 2018-11-06 at 00:12 +0100, Milian Wolff wrote:
> On Montag, 5. November 2018 00:04:32 CET Mark Wielaard wrote:
> 
> Interestingly, when I try to reproduce this on my laptop (i.e. compile even 
> the trivial C example), then I cannot reproduce this at all anymore - the 
> .eh_frame sections show up as PROGBITS. My desktop at work still shows this 
> behavior though (also see below). I can't quite explain this difference...

It seems to only happen with a specific combination of gcc and the gold
linker, I could only generate the SHT_X86_64_UNWIND sections only on
fedora 29 with gcc 8.2.1 and gold version 2.31.1-13.fc29 (1.16).

> > - It might be better to change the check to shdr->sh_type != SHT_NOBITS
> >   The idea is probably that we don't want to look at the data in case
> >   this is a .debug file which has it removed. This might be better than
> >   adding a check for X86_64_UNWIND since then we would also need to
> >   check the arch. Does != SHT_NOBITS work for you?
> 
> Yes, since SHT_NOBITS is not equal to SHT_X86_64_UNWIND :)

OK, then lets change your patch to do that as attached.

> > - What does eu-readelf -S show?
> >   I think we need a x86_64_section_type_name () ebl hook to show it
> >   correctly.
> 
> Yes, that looks like it:

And the other attached patch should clean that up.

Thanks,

Mark

[-- Attachment #2: 0001-Also-find-CFI-in-sections-of-type-SHT_X86_64_UNWIND.patch --]
[-- Type: text/x-patch, Size: 1912 bytes --]

From e556deeb6498b9a5fc320c1d9ee23c6fcdcab384 Mon Sep 17 00:00:00 2001
From: Milian Wolff <milian.wolff@kdab.com>
Date: Mon, 29 Oct 2018 16:21:26 +0100
Subject: [PATCH 1/2] Also find CFI in sections of type SHT_X86_64_UNWIND

On my system with g++ (GCC) 8.2.1 20180831 with GNU gold (GNU Binutils
2.31.1) 1.16, the .eh_frame section does not have type PROGBITS
but rather is using X86_64_UNWIND nowadays:

```
$ echo "int main(){ return 0; }" > test.c
$ gcc test.c
$ readelf --sections a.out | grep .eh_frame
  [14] .eh_frame         X86_64_UNWIND    0000000000000670  00000670
  [15] .eh_frame_hdr     X86_64_UNWIND    0000000000000724  00000724
```

Without this patch, libdw refuses to use the available unwind
information, leading to broken backtraces while unwinding. With the
patch applied, unwinding works once more in such situations.

Signed-off-by: Milian Wolff <milian.wolff@kdab.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libdw/ChangeLog          | 4 ++++
 libdw/dwarf_getcfi_elf.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index ebe002c..627fdde 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2018-10-29  Milian Wolff  <milian.wolff@kdab.com>
+
+	* dwarf_getcfi_elf.c (getcfi_shdr): Check sh_type != SHT_NOBITS.
+
 2018-09-13  Mark Wielaard  <mark@klomp.org>
 
 	* dwarf_begin_elf.c (check_section): Drop ehdr argument, add and
diff --git a/libdw/dwarf_getcfi_elf.c b/libdw/dwarf_getcfi_elf.c
index 315cc02..adcaea0 100644
--- a/libdw/dwarf_getcfi_elf.c
+++ b/libdw/dwarf_getcfi_elf.c
@@ -298,7 +298,7 @@ getcfi_shdr (Elf *elf, const GElf_Ehdr *ehdr)
 	    }
 	  else if (!strcmp (name, ".eh_frame"))
 	    {
-	      if (shdr->sh_type == SHT_PROGBITS)
+	      if (shdr->sh_type != SHT_NOBITS)
 		return getcfi_scn_eh_frame (elf, ehdr, scn, shdr,
 					    hdr_scn, hdr_vaddr);
 	      else
-- 
1.8.3.1


[-- Attachment #3: 0002-backends-Add-x86_64-section_type_name-for-SHT_X86_64.patch --]
[-- Type: text/x-patch, Size: 2548 bytes --]

From 3ca96596538cb57d9f23f6f5ddfc8e145e8b2177 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Tue, 6 Nov 2018 12:01:25 +0100
Subject: [PATCH 2/2] backends: Add x86_64 section_type_name for
 SHT_X86_64_UNWIND.

Makes sure that eu-readelf and eu-elflint recognize and show the
x86_64 specific section type correctly.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 backends/ChangeLog       |  5 +++++
 backends/x86_64_init.c   |  3 ++-
 backends/x86_64_symbol.c | 14 +++++++++++++-
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/backends/ChangeLog b/backends/ChangeLog
index 768c270..e2a0281 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-06  Mark Wielaard  <mark@klomp.org>
+
+	* x86_64_symbol.c (x86_64_section_type_name): New function.
+	* x86_64_init.c (x86_64_int): Hook section_type_name.
+
 2018-10-20  Mark Wielaard  <mark@klomp.org>
 
 	* ppc_initreg.c (ppc_set_initial_registers_tid): Use define instead of
diff --git a/backends/x86_64_init.c b/backends/x86_64_init.c
index adfa479..49f6c6c 100644
--- a/backends/x86_64_init.c
+++ b/backends/x86_64_init.c
@@ -1,5 +1,5 @@
 /* Initialization of x86-64 specific backend library.
-   Copyright (C) 2002-2009, 2013 Red Hat, Inc.
+   Copyright (C) 2002-2009, 2013, 2018 Red Hat, Inc.
    Copyright (C) H.J. Lu <hjl.tools@gmail.com>, 2015.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -55,6 +55,7 @@ x86_64_init (Elf *elf __attribute__ ((unused)),
   eh->name = "AMD x86-64";
   x86_64_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
+  HOOK (eh, section_type_name);
   if (eh->class == ELFCLASS32)
     eh->core_note = x32_core_note;
   else
diff --git a/backends/x86_64_symbol.c b/backends/x86_64_symbol.c
index e07b180..98457bc 100644
--- a/backends/x86_64_symbol.c
+++ b/backends/x86_64_symbol.c
@@ -1,5 +1,5 @@
 /* x86_64 specific symbolic name handling.
-   Copyright (C) 2002, 2005 Red Hat, Inc.
+   Copyright (C) 2002, 2005, 2018 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -59,3 +59,15 @@ x86_64_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
       return ELF_T_NUM;
     }
 }
+
+/* Return symbolic representation of section type.  */
+const char *
+x86_64_section_type_name (int type,
+			  char *buf __attribute__ ((unused)),
+			  size_t len __attribute__ ((unused)))
+{
+  if (type == SHT_X86_64_UNWIND)
+    return "X86_64_UNWIND";
+
+  return NULL;
+}
-- 
1.8.3.1


  reply	other threads:[~2018-11-06 11:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-29 15:21 Milian Wolff
2018-11-04 23:04 ` Mark Wielaard
2018-11-05 23:13   ` Milian Wolff
2018-11-06 11:07     ` Mark Wielaard [this message]
2018-11-07  9:03       ` Milian Wolff
2018-11-09 16:57         ` Mark Wielaard
2018-11-10 23:29           ` Mark Wielaard
2018-11-13 21:19             ` Mark Wielaard

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=f8b7a2805eed658a3e8dfeb8b81d7f15653d838a.camel@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=milian.wolff@kdab.com \
    /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).