[Bug c/106835] [i386] Taking an address of _GLOBAL_OFFSET_TABLE_ produces a wrong value

hjl.tools at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Sep 5 16:46:54 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106835

--- Comment #5 from H.J. Lu <hjl.tools at gmail dot com> ---
To access this special symbol:

[hjl@gnu-tgl-3 tmp]$ cat c.c
#include <stdio.h>

extern char GLOBAL_OFFSET_TABLE[];
char *ptr = GLOBAL_OFFSET_TABLE;

int main() {
  printf("%lx\n", (unsigned long)ptr);
}
[hjl@gnu-tgl-3 tmp]$ gcc -m32 c.c
/usr/local/bin/ld: /tmp/ccK14eSl.o:(.data+0x0): undefined reference to
`GLOBAL_OFFSET_TABLE'
collect2: error: ld returned 1 exit status
[hjl@gnu-tgl-3 tmp]$ gcc -m32 c.c
-Wl,--defsym,GLOBAL_OFFSET_TABLE=_GLOBAL_OFFSET_TABLE_ 
[hjl@gnu-tgl-3 tmp]$ ./a.out 
804bff4
[hjl@gnu-tgl-3 tmp]$


More information about the Gcc-bugs mailing list