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

--- Comment #13 from H.J. Lu <hjl.tools at gmail dot com> ---
Another testcase:

[hjl@gnu-tools-1 pr18695]$ cat bar.c
#include <stdio.h>

extern int *get_foo (void);

int
main ()
{
  int *p = get_foo ();
  printf ("foo: %d\n", *p);
  *p = 1;
  printf ("foo: %d\n", *p);
  return 0;
}
[hjl@gnu-tools-1 pr18695]$ cat get_foo.S 
#ifndef SPACE
#define SPACE 0x80000000
#endif
        .data
        .space SPACE
        .comm foo,4
        .globl get_foo
        .text
get_foo:
        mov     $foo, %rax
        ret
[hjl@gnu-tools-1 pr18695]$ make b1
gcc -B./ -mx32 -fno-lto    -c -o get_foo.o get_foo.S
gcc -B./ -mx32 -fno-lto -g -O2   -c -o bar.o bar.c
gcc -B./ -mx32 -fno-lto  -o b1 get_foo.o bar.o
/usr/lib/gcc/x86_64-redhat-linux/5.3.1/x32/crtbegin.o: In function
`__do_global_dtors_aux':
crtstuff.c:(.text+0x72): relocation truncated to fit: R_X86_64_PC32 against
`.bss'
crtstuff.c:(.text+0x84): relocation truncated to fit: R_X86_64_PC32 against
`.bss'
get_foo.o: In function `get_foo':
(.text+0x3): relocation truncated to fit: R_X86_64_32S against symbol `foo'
defined in COMMON section in get_foo.o
collect2: error: ld returned 1 exit status
Makefile:37: recipe for target 'b1' failed
make: *** [b1] Error 1
[hjl@gnu-tools-1 pr18695]$ make b2
gcc -B./ -mx32 -fno-lto  -o b2 get_foo.o bar.o -fuse-ld=gold
[hjl@gnu-tools-1 pr18695]$ ./b2
foo: 0
foo: 1
Segmentation fault (core dumped)
[hjl@gnu-tools-1 pr18695]$ make g1
gcc -B./ -mx32 -fno-lto -g -O2 -DSPACE=0x800  -c -o good.o get_foo.S
gcc -B./ -mx32 -fno-lto  -o g1 good.o bar.o
[hjl@gnu-tools-1 pr18695]$ ./g1
foo: 0
foo: 1
[hjl@gnu-tools-1 pr18695]$ 
[hjl@gnu-tools-1 pr18695]$ gdb b2
GNU gdb (GDB) Fedora 7.10.1-30.fc23
Copyright (C) 2015 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 "x86_64-redhat-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 b2...done.
(gdb) disass get_foo
Dump of assembler code for function get_foo:
   0x00400488 <+0>:     mov    $0xffffffff80401784,%rax
   0x0040048f <+7>:     retq   
   0x00400490 <+8>:     nopl   (%rax)
   0x00400493 <+11>:    add    %al,(%rax)
   0x00400495 <+13>:    add    %al,(%rax)
   0x00400497 <+15>:    add    %al,(%rax)
   0x00400499 <+17>:    add    %al,(%rax)
   0x0040049b <+19>:    add    %al,(%rax)
   0x0040049d <+21>:    add    %al,(%rax)
   0x0040049f <+23>:    add    %al,0x57(%rcx)
End of assembler dump.
(gdb) disass main
Dump of assembler code for function main:
   0x00400360 <+0>:     push   %rbp
   0x00400361 <+1>:     push   %rbx
   0x00400362 <+2>:     mov    $0x400518,%ebx
   0x00400367 <+7>:     sub    $0x8,%esp
   0x0040036a <+10>:    callq  0x400488 <get_foo>
   0x0040036f <+15>:    mov    (%eax),%esi
   0x00400372 <+18>:    mov    %eax,%ebp
   0x00400374 <+20>:    mov    %rbx,%rdi
   0x00400377 <+23>:    xor    %eax,%eax
   0x00400379 <+25>:    callq  0x400350 <printf@plt>
   0x0040037e <+30>:    movl   $0x1,0x0(%ebp)
   0x00400386 <+38>:    mov    %rbx,%rdi
   0x00400389 <+41>:    mov    $0x1,%esi
   0x0040038e <+46>:    xor    %eax,%eax
   0x00400390 <+48>:    callq  0x400350 <printf@plt>
   0x00400395 <+53>:    add    $0x8,%esp
   0x00400398 <+56>:    xor    %eax,%eax
   0x0040039a <+58>:    pop    %rbx
   0x0040039b <+59>:    pop    %rbp
   0x0040039c <+60>:    retq   
End of assembler dump.
(gdb) b *0x00400372
Breakpoint 1 at 0x400372: file bar.c, line 8.
(gdb) r
Starting program: /export/home/hjl/bugs/binutils/pr18695/b2 
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.22-7.0.fc23.x32

Breakpoint 1, main () at bar.c:8
8         int *p = get_foo ();
(gdb) p $rax
$1 = -2143283324
(gdb) p/x $rax
$2 = 0xffffffff80401784
(gdb) p/x $eax
$3 = 0x80401784
(gdb) c
Continuing.
foo: 0
foo: 1

Program received signal SIGSEGV, Segmentation fault.
0x00400440 in __do_global_dtors_aux ()
(gdb)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils

Reply via email to