Bug 22537 - Segmentation fault with static PIE
Summary: Segmentation fault with static PIE
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.30
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-01 13:46 UTC by H.J. Lu
Modified: 2018-04-19 06:07 UTC (History)
0 users

See Also:
Host:
Target: hppa-linux
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2017-12-01 13:46:52 UTC
On hjl/pie/static branch in glibc git repo, when --enable-static-pie
is used to configure glibc, I got

(gdb) r --sysroot=/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../sysroot -static -o /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/elf/sln -L/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../lib/gcc/hppa-glibc-linux-gnu/7.2.1 -L/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../lib/gcc -L/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../lib/gcc/hppa-glibc-linux-gnu/7.2.1/../../../../hppa-glibc-linux-gnu/lib -L/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../sysroot/lib -L/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../sysroot/usr/lib -pie --no-dynamic-linker --eh-frame-hdr -z text /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/csu/rcrt1.o /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/csu/crti.o /export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../lib/gcc/hppa-glibc-linux-gnu/7.2.1/crtbeginS.o /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/elf/sln.o /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/elf/static-stubs.o --start-group /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/libc.a -lgcc --end-group /export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../lib/gcc/hppa-glibc-linux-gnu/7.2.1/crtendS.o /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/csu/crtn.o
Starting program: /export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/hppa-glibc-linux-gnu-ld --sysroot=/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../sysroot -static -o /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/elf/sln -L/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../lib/gcc/hppa-glibc-linux-gnu/7.2.1 -L/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../lib/gcc -L/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../lib/gcc/hppa-glibc-linux-gnu/7.2.1/../../../../hppa-glibc-linux-gnu/lib -L/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../sysroot/lib -L/export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../sysroot/usr/lib -pie --no-dynamic-linker --eh-frame-hdr -z text /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/csu/rcrt1.o /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/csu/crti.o /export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../lib/gcc/hppa-glibc-linux-gnu/7.2.1/crtbeginS.o /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/elf/sln.o /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/elf/static-stubs.o --start-group /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/libc.a -lgcc --end-group /export/ssd/git/toolchain/install/compilers/hppa-linux-gnu/bin/../lib/gcc/hppa-glibc-linux-gnu/7.2.1/crtendS.o /export/gnu/import/git/toolchain/build/glibcs/hppa-linux-gnu/glibc/csu/crtn.o
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.26-18.0.fc27.x86_64

Program received signal SIGSEGV, Segmentation fault.
hppa_build_one_stub (bh=0x73e310, in_arg=<optimized out>)
---Type <return> to continue, or q <return> to quit---
    at /export/gnu/import/git/toolchain/src/binutils/bfd/elf32-hppa.c:759
759	      sym_value -= (hsh->stub_offset
(gdb) p hsh
$1 = (struct elf32_hppa_stub_hash_entry *) 0x73e310
(gdb) list
754	      sym_value = (hsh->target_value
755			   + hsh->target_section->output_offset
756			   + hsh->target_section->output_section->vma);
757	
758	      /* And this is where we are coming from, more or less.  */
759	      sym_value -= (hsh->stub_offset
760			    + stub_sec->output_offset
761			    + stub_sec->output_section->vma);
762	
763	      bfd_put_32 (stub_bfd, (bfd_vma) BL_R1, loc);
(gdb) p hsh->target_section
$2 = (asection *) 0x0
(gdb) bt
#0  hppa_build_one_stub (bh=0x73e310, in_arg=<optimized out>)
    at /export/gnu/import/git/toolchain/src/binutils/bfd/elf32-hppa.c:759
#1  0x000000000042c7d0 in bfd_hash_traverse (table=table@entry=0x734a28, 
    func=func@entry=0x43e690 <hppa_build_one_stub>, 
    info=info@entry=0x719c80 <link_info>)
    at /export/gnu/import/git/toolchain/src/binutils/bfd/hash.c:656
#2  0x000000000043ff95 in elf32_hppa_build_stubs (info=0x719c80 <link_info>)
    at /export/gnu/import/git/toolchain/src/binutils/bfd/elf32-hppa.c:3120
#3  0x00000000004225bb in gldhppalinux_after_allocation () at ehppalinux.c:386
#4  0x0000000000414f81 in lang_process ()
    at /export/gnu/import/git/toolchain/src/binutils/ld/ldlang.c:7393
#5  0x00000000004033ee in main (argc=<optimized out>, argv=<optimized out>)
    at /export/gnu/import/git/toolchain/src/binutils/ld/ldmain.c:432
(gdb)
Comment 1 Sourceware Commits 2018-04-19 05:53:59 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit f6a8b8c7ac2d5369070a6b76a94ee0f3052433ff
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Apr 19 14:13:41 2018 +0930

    PR22537, Segmentation fault with static PIE
    
    The only stub type that makes sense for undefined symbols, or those
    defined in shared libraries, is a plt call stub.  This patch arranges
    to have "destination" set to -1 on such symbols, making for an easy
    test in hppa_type_of_stub.
    
    	PR 22537
    	* elf32-hppa.c (elf32_hppa_size_stubs): Init "destination" to -1.
    	(hppa_type_of_stub): Don't return a long branch stub for
    	symbols other than those defined statically.
Comment 2 Alan Modra 2018-04-19 06:07:29 UTC
Should be fixed