This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PR22048, Incorrect .eh_frame section in libc.so


On Wed, Aug 30, 2017 at 8:57 PM, Alan Modra <amodra@gmail.com> wrote:
> Yep, there is definitely an incorrect .eh_frame section in libc.so.
> It has a ZERO terminator in the middle!
>
>         PR 21441
>         PR 22048
>         * elflink.c (bfd_elf_discard_info): Don't pad embedded zero
>         terminators.
>
> diff --git a/bfd/elflink.c b/bfd/elflink.c
> index ceacb37..f6f57fa 100644
> --- a/bfd/elflink.c
> +++ b/bfd/elflink.c
> @@ -13878,17 +13878,22 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
>           /* Any prior sections must pad the last FDE out to the
>              output section alignment.  Otherwise we might have zero
>              padding between sections, which would be seen as a
> -            terminator.  */
> +            terminator.  If there is a terminator in the middle of
> +            FDEs, don't increase its size as that will write bogus
> +            data of whatever was after the terminator in the input
> +            file, to the output file.  */
>           for (; i != NULL; i = i->map_tail.s)
> -           {
> -             bfd_size_type size = (i->size + eh_alignment - 1) & -eh_alignment;
> -             if (i->size != size)
> -               {
> -                 i->size = size;
> -                 changed = 1;
> -                 eh_changed = 1;
> -               }
> -           }
> +           if (i->size != 4)
> +             {
> +               bfd_size_type size
> +                 = (i->size + eh_alignment - 1) & -eh_alignment;
> +               if (i->size != size)
> +                 {
> +                   i->size = size;
> +                   changed = 1;
> +                   eh_changed = 1;
> +                 }
> +             }
>         }
>        if (eh_changed)
>         elf_link_hash_traverse (elf_hash_table (info),
>

Here is a testcase.


-- 
H.J.
From aa957f736381ee697f2a3d9f123f8769c781ddc2 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 30 Aug 2017 21:59:17 -0700
Subject: [PATCH] Add a test for PR ld/22048

	PR ld/22048
	* testsuite/ld-elf/pr22048.d: New file.
	* testsuite/ld-elf/pr22048a.s: Likewise.
	* testsuite/ld-elf/pr22048b.s: Likewise.
---
 ld/ChangeLog                   |  7 +++++++
 ld/testsuite/ld-elf/pr22048.d  | 28 ++++++++++++++++++++++++++++
 ld/testsuite/ld-elf/pr22048a.s |  4 ++++
 ld/testsuite/ld-elf/pr22048b.s |  8 ++++++++
 4 files changed, 47 insertions(+)
 create mode 100644 ld/testsuite/ld-elf/pr22048.d
 create mode 100644 ld/testsuite/ld-elf/pr22048a.s
 create mode 100644 ld/testsuite/ld-elf/pr22048b.s

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 1dcb981353..4f58dec549 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
+2017-08-31  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/22048
+	* testsuite/ld-elf/pr22048.d: New file.
+	* testsuite/ld-elf/pr22048a.s: Likewise.
+	* testsuite/ld-elf/pr22048b.s: Likewise.
+
 2017-08-30  Maciej W. Rozycki  <macro@imgtec.com>
 
 	* testsuite/ld-elf/orphan-11.ld: Also discard `.MIPS.options'
diff --git a/ld/testsuite/ld-elf/pr22048.d b/ld/testsuite/ld-elf/pr22048.d
new file mode 100644
index 0000000000..9eb40e4d8d
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22048.d
@@ -0,0 +1,28 @@
+#source: pr22048a.s
+#source: pr22048b.s
+#as: --64
+#ld: -melf_x86_64 -Ttext 0x400078
+#readelf: -wf
+#target: x86_64-*-*
+
+Contents of the .eh_frame section:
+
+0+0000 ZERO terminator
+
+0+0008 0+014 0+0000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 1
+  Data alignment factor: -8
+  Return address column: 16
+  Augmentation data:     1b
+
+  DW_CFA_def_cfa: r7 \(rsp\) ofs 8
+  DW_CFA_offset: r16 \(rip\) at cfa-8
+  DW_CFA_nop
+  DW_CFA_nop
+
+0+0020 0+0010 0+001c FDE cie=0+0008 pc=0+400078\.\.0+40007a
+  DW_CFA_nop
+  DW_CFA_nop
+  DW_CFA_nop
diff --git a/ld/testsuite/ld-elf/pr22048a.s b/ld/testsuite/ld-elf/pr22048a.s
new file mode 100644
index 0000000000..060bd0171c
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22048a.s
@@ -0,0 +1,4 @@
+	.section	.eh_frame,"a",@progbits
+	.align 4
+	.zero	4
+	.ident	"GCC"
diff --git a/ld/testsuite/ld-elf/pr22048b.s b/ld/testsuite/ld-elf/pr22048b.s
new file mode 100644
index 0000000000..ea05c15471
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr22048b.s
@@ -0,0 +1,8 @@
+	.text
+	.globl _start
+	.type	_start, %function
+_start:
+	.cfi_startproc
+	rep ret
+	.cfi_endproc
+	.size	_start, .-_start
-- 
2.13.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]