bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/21132] New: [hppa-linux] pie support doesn't work


From: danglin at gcc dot gnu.org
Subject: [Bug ld/21132] New: [hppa-linux] pie support doesn't work
Date: Sun, 12 Feb 2017 23:32:12 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=21132

            Bug ID: 21132
           Summary: [hppa-linux] pie support doesn't work
           Product: binutils
           Version: 2.27
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: danglin at gcc dot gnu.org
                CC: deller at gmx dot de
  Target Milestone: ---
              Host: hppa-unknown-linux-gnu
            Target: hppa-unknown-linux-gnu
             Build: hppa-unknown-linux-gnu

If one compiles "int main() { return 0; }" with "gcc -o main -pie main.c",
the program faults in _start:

address@hidden:~/ffmpeg$ gdb main
GNU gdb (Debian 7.12-6) 7.12.0.20161007-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "hppa-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from main...(no debugging symbols found)...done.
(gdb) r
Starting program: /home/dave/ffmpeg/main 

Program received signal SIGSEGV, Segmentation fault.
0x41000548 in _start ()
(gdb) disass
Dump of assembler code for function _start:
   0x41000528 <+0>:     stw r0,-4(sp)
   0x4100052c <+4>:     stw rp,-14(sp)
   0x41000530 <+8>:     ldo 40(sp),sp
   0x41000534 <+12>:    stw sp,-4(sp)
   0x41000538 <+16>:    stw r19,-20(sp)
   0x4100053c <+20>:    stw r23,-38(sp)
   0x41000540 <+24>:    addil L%0,r19,r1
   0x41000544 <+28>:    ldw 7c(r1),r26
=> 0x41000548 <+32>:    ldw 0(r26),r26

The fault is in this hunk of code in glibc's start.S for hppa:

        /* Have the linker create plabel words so we get PLABEL32
           relocs and not 21/14.  The use of 21/14 relocs is only
           supported in the latest dynamic linker.  */
#ifdef SHARED
        .section        .data.rel.ro,"aw",@progbits
#else
        .section        .rodata,"a",@progbits
#endif
        .align 4
.Lpmain:
        .word P%main
.Lp__libc_start_main:
        .word P%__libc_start_main
.Lp__libc_csu_fini:
        .word P%__libc_csu_fini
.Lp__libc_csu_init:
        .word P%__libc_csu_init
#ifdef SHARED
.Lp__global:
        .word $global$
#endif

        .text
        .align 4
        .globl _start
        .export _start, ENTRY
        .type _start,@function
_start:
        /* At entry to the function we have:

                r26 - Unused
                r25 - argc
                r24 - argv
                r23 - False _dl_fini plabel address

           This function is called from the lower half of RTLD_START.

           The call to __libc_start_main expects:

                1. r26 - Application main
                2. r25 - argc
                3. r24 - argv
                4. r23 - __libc_csu_init
                5. sp-52 - __libc_csu_fini
                6. sp-56 - rtld_fini
                7. sp-60 - stackend  */

        .proc
        .callinfo
        /* Clear previous-sp.  */
        stw     %r0, -4(%sp)
        /* Setup the stack and frame.  */
        stw     %rp, -20(%sp)
        ldo     64(%sp), %sp
        stw     %sp, -4(%sp)
        stw     %r19, -32(%sp)

        /* argc and argv should be in 25 and 24 (2nd and 3rd argument) */
        /* void (*rtld_fini) (void) (6th argument) */
        stw     %r23, -56(%sp)
        /* Need to setup 1, 4, 5, and 7th arguments */

#ifdef SHARED
        /* load main (1st argument) */
        addil   LT'.Lpmain, %r19
        ldw     RT'.Lpmain(%r1), %r26
        ldw     0(%r26),%r26

(gdb) p/x $r19
$1 = 0x41001120
(gdb) info address .Lpmain
Symbol ".Lpmain" is at 0x41001018 in a file compiled without debugging.
(gdb) x/x 0x41001018
0x41001018:     0x41001142
(gdb) x/2x 0x41001140
0x41001140:     0x410007f8      0x41001120
(gdb) info address main
Symbol "main" is at 0x410007f8 in a file compiled without debugging.
(gdb) p/x $r26
$2 = 0x0
(gdb) p/x $r1+0x7c
$3 = 0x4100119c
(gdb) p/x $r1
$4 = 0x41001120

So, there's an offset inconsistency of 0x7c.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]