Re: [PATCH] Also find CFI in sections of type SHT_X86_64_UNWIND

2018-11-06 Thread Mark Wielaard
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
From e556deeb6498b9a5fc320c1d9ee23c6fcdcab384 Mon Sep 17 00:00:00 2001
From: Milian Wolff 
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_UNWIND0670  0670
  [15] .eh_frame_hdr X86_64_UNWIND0724  0724
```

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 
Signed-off-by: Mark Wielaard 
---
 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  
+
+	* dwarf_getcfi_elf.c (getcfi_shdr): Check sh_type != SHT_NOBITS.
+
 2018-09-13  Mark Wielaard  
 
 	* 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

From 3ca96596538cb57d9f23f6f5ddfc8e145e8b2177 Mon Sep 17 00:00:00 2001
From: Mark Wielaard 
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 
---
 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  
+
+	* 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  
 
 	* 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 , 2015.
This file is part of elfutils.
Written by Ulrich Drepper , 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.

Re: Add eu-strip --reloc-debug-sections-only option

2018-11-06 Thread Mark Wielaard
On Fri, 2018-10-26 at 23:50 +0200, Mark Wielaard wrote:
> eu-strip already supports --reloc-debug-sections to resolve all
> relocations between .debug_ sections while creating a separate
> .debug file with -f. It is sometimes useful to do the same without
> doing any other stripping.
> 
>   --reloc-debug-sections-only
>  Similar to --reloc-debug-sections, but resolve all
>  trivial relocations between debug sections in
>  place.  No other stripping is performed (operation
>  is not reversable, incompatible with -f, -g,
>  --remove-comment and --remove-section)
> 
> For example to ease debugging, tracing and profiling some distributions
> ship an uncompressed vmlinux ELF file which includes DWARF debuginfo.
> Since the vmlinux ELF kernel is relocatable, the relocations between the
> .debug sections are also still left in. On Fedora this file is 662M.
> eu-strip --reloc-debug-sections-only will remove more than 250MB of
> (unneeded) relocations between the .debug sections.
> 
> To reuse as much code as possible this patch series first refactors
> some of the code. It also makes it so that the type of ELF file doesn't
> matter for doing relocations (normally it only makes sense for ET_REL
> files, but the vmlinux ELF image is an ET_EXEC with SHT_RELA sections).
> 
> It also adds a new testcase to run-strip-reloc.sh to make sure that the
> result of creating a separate debug file using --reloc-debug-sections
> is identical to creating a separate debug file and then running eu-strip
> with --reloc-debug-sections-only.
> 
> [PATCH 1/4] strip: Always copy over any phdrs if there are any
> [PATCH 2/4] strip: Split out debug section relocation into separate helper
> [PATCH 3/4] strip: Extract code to update shdrstrndx into new common function
> [PATCH 4/4] strip: Add --reloc-debug-sections-only option

I pushed these 4 patches to master.

Cheers,

Mark


Buildbot failure in Wildebeest Builder on whole buildset

2018-11-06 Thread buildbot
The Buildbot has detected a failed build on builder whole buildset while 
building elfutils.
Full details are available at:
https://builder.wildebeest.org/buildbot/#builders/11/builds/244

Buildbot URL: https://builder.wildebeest.org/buildbot/

Worker for this Build: fedora-ppc64le

Build Reason: 
Blamelist: Mark Wielaard 

BUILD FAILED: failed test (failure)

Sincerely,
 -The BuildbotThe Buildbot has detected a failed build on builder whole 
buildset while building elfutils.
Full details are available at:
https://builder.wildebeest.org/buildbot/#builders/12/builds/242

Buildbot URL: https://builder.wildebeest.org/buildbot/

Worker for this Build: fedora-ppc64

Build Reason: 
Blamelist: Mark Wielaard 

BUILD FAILED: failed test (failure)

Sincerely,
 -The BuildbotThe Buildbot has detected a failed build on builder whole 
buildset while building elfutils.
Full details are available at:
https://builder.wildebeest.org/buildbot/#builders/15/builds/81

Buildbot URL: https://builder.wildebeest.org/buildbot/

Worker for this Build: debian-armhf

Build Reason: 
Blamelist: Mark Wielaard 

BUILD FAILED: failed test (failure)

Sincerely,
 -The Buildbot



Re: [PATCH 4/4] strip: Add --reloc-debug-sections-only option.

2018-11-06 Thread Mark Wielaard
On Fri, 2018-10-26 at 23:50 +0200, Mark Wielaard wrote:
> diff --git a/tests/ChangeLog b/tests/ChangeLog
> index 751a081..0870d4c 100644
> --- a/tests/ChangeLog
> +++ b/tests/ChangeLog
> @@ -1,3 +1,7 @@
> +2018-10-26  Mark Wielaard  
> +
> + * run-strip-reloc.sh: Add a test for --reloc-debug-sections-only.
> +
>  2018-10-12  Mark Wielaard  
>  
>   * run-readelf-zdebug.sh: Adjust flags output.
> diff --git a/tests/run-strip-reloc.sh b/tests/run-strip-reloc.sh
> index bbc9f58..6e54ab4 100755
> --- a/tests/run-strip-reloc.sh
> +++ b/tests/run-strip-reloc.sh
> @@ -32,6 +32,8 @@ runtest() {
>outfile2=out.stripped2
>debugfile2=out.debug2
>  
> +  echo "runtest $infile"
> +
>rm -f $outfile1 $debugfile1 $outfile2 $debugfile2
>  
>testrun ${abs_top_builddir}/src/strip -o $outfile1 -f $debugfile1 $infile 
> ||
> @@ -67,6 +69,15 @@ runtest() {
>  
>testrun_compare cat readelf.out1 < readelf.out2 ||
>{ echo "*** failure readelf -w compare $infile"; status=1; }
> +
> +  testrun ${abs_top_builddir}/src/strip --reloc-debug-sections-only \
> +   $debugfile1 ||
> +  { echo "*** failure strip --reloc-debug-sections-only $debugfile1"; \
> +status=1; }
> +
> +  cmp $debugfile1 $debugfile2 ||
> +  { echo "*** failure --reloc-debug-sections[-only] $debugfile1 
> $debugfile2"; \
> +status=1; }
>  }
>  
>  # Most simple hello world kernel module for various architectures.

The buildbot didn't sent any failure emails (I am still looking into
why), but this new cmp test failed on debian-armhf, fedora-ppc64 and
fedora-ppc64le:
https://builder.wildebeest.org/buildbot/#/builders/15/builds/81
https://builder.wildebeest.org/buildbot/#/builders/12/builds/242
https://builder.wildebeest.org/buildbot/#/builders/11/builds/244

It succeeds on everything else. Still investigating.