https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63538
Bug ID: 63538
Summary: [X86_64] With -mcmodel=medium .lrodata accesses do not
use 64-bit addresses
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: tmsriram at google dot com
CC: davidxl at google dot com
foo.cc
======
#include <stdio.h>
const char *str = "Hello World";
int main() {
printf("str = %p %s\n",str, str);
return 0;
}
$ g++ --save-temps foo.cc -mcmodel=medium -mlarge-data-threshold=0 -O2
Linked with gold linker.
Look at foo.s:
===========
.section .lrodata,"a",@progbits
.LC0:
.string "str = %p %s\n"
.....
main:
...
movl $.LC0, %edi
This is the problem, it treats .LC0 as a 32-bit address when it should a 64-bit
address since it is placed in .lrodata
Now this bug will not manifest until .lrodata exceeds the 2GB limit. That can
be done by linking with -Wl,-Ttext=0x7ffff000 which moves the start address of
.text to be very close to 2GB and enough to throw .lrodata out of the limit.
Program segfaults.