Bug 22758 - FAIL: Run pr22393-2
Summary: FAIL: Run pr22393-2
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.31
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-28 18:50 UTC by John David Anglin
Modified: 2018-03-31 12:35 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John David Anglin 2018-01-28 18:50:11 UTC
gcc  -B/home/dave/gnu/binutils/objdir/ld/tmpdir/ld/ -I/home/dave/gnu/binutils/src/ld/testsuite/ld-elf -g -O2   -c -g -O2 -fno-PIE -c /home/dave/gnu/binutils/src/ld/testsuite/ld-elf/pr22393-2b.c -o tmpdir/pr22393-2b.o
Executing on host: sh -c {gcc  -B/home/dave/gnu/binutils/objdir/ld/tmpdir/ld/ -I/home/dave/gnu/binutils/src/ld/testsuite/ld-elf -g -O2   -c -g -O2 -fno-PIE -c /home/dave/gnu/binutils/src/ld/testsuite/ld-elf/pr22393-2b.c -o tmpdir/pr22393-2b.o 2>&1}  /dev/null ld.tmp (timeout = 300)
spawn [open ...]
gcc -B/home/dave/gnu/binutils/objdir/ld/tmpdir/ld/   -L=/home/dave/opt/gnu/hppa-unknown-linux-gnu/lib -L=/home/dave/opt/gnu/lib -L=/usr/local/lib -L=/lib -L=/usr/lib  -o tmpdir/pr22393-2  -L/home/dave/gnu/binutils/src/ld/testsuite/ld-elf -no-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so tmpdir/pr22393-2b.o
Executing on host: sh -c {gcc -B/home/dave/gnu/binutils/objdir/ld/tmpdir/ld/   -L=/home/dave/opt/gnu/hppa-unknown-linux-gnu/lib -L=/home/dave/opt/gnu/lib -L=/usr/local/lib -L=/lib -L=/usr/lib  -o tmpdir/pr22393-2  -L/home/dave/gnu/binutils/src/ld/testsuite/ld-elf -no-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so tmpdir/pr22393-2b.o 2>&1}  /dev/null ld.tmp (timeout = 300)
spawn [open ...]
Running: tmpdir/pr22393-2 > tmpdir/pr22393-2.out
child killed: segmentation violation
FAIL: Run pr22393-2

Similar fail:
FAIL: Run pr22393-2 (PIE)
Comment 1 Nick Clifton 2018-01-29 14:18:27 UTC
Hi John,

  Please could you narrow this down to the linker command line and a tarball 
  of the object files & libraries involved ?  (I do not have easy access to
  an hppa based build system).

Cheers
  Nick
Comment 2 dave.anglin 2018-01-29 14:36:28 UTC
Hi Nick,

On 2018-01-29 9:18 AM, nickc at redhat dot com wrote:
>    Please could you narrow this down to the linker command line and a tarball
>    of the object files & libraries involved ?  (I do not have easy access to
>    an hppa based build system).
I'll try to look at this as soon as I can.  Alan has an account on a 
hppa-linux system.

Dave
Comment 3 Eric Botcazou 2018-01-29 23:33:55 UTC
Let me add that we have the same couple of failures on SPARC64/Linux.
Comment 4 Alan Modra 2018-01-30 05:10:40 UTC
Here are pr22393-2 program headers and section to header mapping:

  PHDR           0x000034 0x00010034 0x00010034 0x00140 0x00140 R   0x4
  INTERP         0x000174 0x00010174 0x00010174 0x0000d 0x0000d R   0x1
      [Requesting program interpreter: /lib/ld.so.1]
  LOAD           0x000000 0x00010000 0x00010000 0x0043c 0x0043c R   0x1000
  LOAD           0x001000 0x00011000 0x00011000 0x00554 0x00554 R E 0x1000
  LOAD           0x002000 0x00012000 0x00012000 0x00118 0x00118 R   0x1000
  LOAD           0x003000 0x00013000 0x00013000 0x000f8 0x000f8 RW  0x1000
  LOAD           0x0040f8 0x000130f8 0x000130f8 0x00064 0x00064 RWE 0x1000
  LOAD           0x00515c 0x0001315c 0x0001315c 0x0001c 0x0002c RW  0x1000
  DYNAMIC        0x003020 0x00013020 0x00013020 0x000d0 0x000d0 RW  0x4
  NOTE           0x000184 0x00010184 0x00010184 0x00044 0x00044 R   0x4

   00     
   01     .interp 
   02     .interp .note.ABI-tag .note.gnu.build-id .hash .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.plt 
   03     .init .text .fini 
   04     .rodata .PARISC.unwind .eh_frame 
   05     .init_array .ctors .dtors .data.rel.ro .dynamic .data 
   06     .plt 
   07     .got .bss 
   08     .dynamic 
   09     .note.ABI-tag .note.gnu.build-id 

There's a problem with the last 3 PT_LOAD headers.  They can't be mapped from different disk pages (0x3000, 0x4000 and 0x5000) into the same memory page (0x13000).
Comment 5 Sourceware Commits 2018-01-30 08:30:33 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=76cb3a89a6615cf3418fa1efe8268bf6673a5c8a

commit 76cb3a89a6615cf3418fa1efe8268bf6673a5c8a
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Jan 30 16:02:32 2018 +1030

    PR22758, FAIL: Run pr22393-2
    
    We can't map different disk pages into the same memory page; The last
    page mapped will simply overwrite any previous pages.  The
    executable/non-executable new_segment test ignored this fact, leading
    to a ld.so segfault on hppa when .dynamic is overwritten with zeros.
    
    This patch moves existing tests for demand paging with lma on the same
    memory page, to a new test performed before any case where we want a
    new segment due to protection or loadable conflicts.
    
    	PR 22758
    	* elf.c (_bfd_elf_map_sections_to_segments): Don't start a new
    	segment when demand paged with lma on the same page.  Test this
    	before load/non-load, executable/non-executable,
    	writable/non-writable tests and simplify.  Delete bogus relro
    	condition in writable/non-writable test.  Delete outdated
    	comment.  Formatting.
Comment 6 Alan Modra 2018-01-30 11:30:21 UTC
Fixed master.
Comment 7 Romain Geissler 2018-02-14 16:01:59 UTC
Hi,

Long story short, I was trying to build clang in PGO+LTO bootstrap mode the last few days, and the bootstrap fails with a segfault at the moment clang is ran on the profiling data set.

I hunted down the issue to the fact that in some LLVM libraries, "atexit" function is inlined and included in the loaded shared libraries, but placed in a section that ld.so mapped in a RW segment rather than a RE segment, and both segment are not correctly aligned to the boundary of a 2MB page like it should.

When applying this patch, the bootstrap of clang works. Given that this might potentially happen arbitrarily to any user of binutils 2.30 and it is not so easy to understand that section placement is wrong here, would you please backport this to the 2.30 branch ?

Thanks,
Romain
Comment 8 Sourceware Commits 2018-02-15 16:23:55 UTC
The binutils-2_30-branch branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=355d8ed79b1e830d5216a70026f751f5a38df9e9

commit 355d8ed79b1e830d5216a70026f751f5a38df9e9
Author: Nick Clifton <nickc@redhat.com>
Date:   Thu Feb 15 16:21:02 2018 +0000

    Import patch from mainline to fix a bug that would place executable and non-executables pages in the same segment.
    
    	PR 22758
    bfd	* elf.c (_bfd_elf_map_sections_to_segments): Don't start a new
    	segment when demand paged with lma on the same page.  Test this
    	before load/non-load, executable/non-executable,
    	writable/non-writable tests and simplify.  Delete bogus relro
    	condition in writable/non-writable test.  Delete outdated
    	comment.  Formatting.
Comment 9 Nick Clifton 2018-02-15 16:24:33 UTC
(In reply to Romain Geissler from comment #7)

> Given that this
> might potentially happen arbitrarily to any user of binutils 2.30 and it is
> not so easy to understand that section placement is wrong here, would you
> please backport this to the 2.30 branch ?

Done.