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

            Bug ID: 17592
           Summary: x86-64 linker generates wrong PLT for large model
           Product: binutils
           Version: 2.26 (HEAD)
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: hjl.tools at gmail dot com

When PLT is more 2GB from GOT, we must use large model PLT layout.
Otherwise, PLT entry can't load GOT entry:

[hjl@gnu-6 large-2]$ cat main.c 
extern void foo (void);
extern void bar (void);

int
main ()
{
  foo ();
  bar ();
  return 0;
}
[hjl@gnu-6 large-2]$ cat foo.c 
#include <stdio.h>

void
foo (void)
{
  printf ("hello\n");
}
[hjl@gnu-6 large-2]$ cat gap.S 
    .text
    .p2align 4,,15
    .globl    bar
    .type    bar, @function
bar:
    jmp .L0
    .space 0x40000000, 0x90
.L0:
    jmp .L2
    .space 0x3fdffe14, 0x90
.L2:
    leaq    .L2(%rip), %rcx
    movabsq    $_GLOBAL_OFFSET_TABLE_-.L2, %r11
    movabsq    $foo@PLTOFF, %rax
    addq    %r11, %rcx
    addq    %rcx, %rax
    jmp    *%rax
    .size    bar, .-bar
    .section    .note.GNU-stack,"",@progbits
[hjl@gnu-6 large-2]$ make
gcc -O2   -c -o main.o main.c
gcc -O2 -c -o gap.o gap.S
gcc -O2 -mcmodel=large -fpic   -c -o foo.o foo.c
./ld -shared -o libfoo.so gap.o foo.o
gcc -O2 -o foo main.o libfoo.so -Wl,-R,.
./foo
make: *** [all] Segmentation fault
[hjl@gnu-6 large-2]$

-- 
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