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

--- Comment #9 from H.J. Lu <hjl.tools at gmail dot com> ---
_GLOBAL_OFFSET_TABLE_ is a special symbol and can't be accessed like regular
symbols.  To workaround it:

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

extern char GLOBAL_OFFSET_TABLE[];

int main() {
  printf("%lx\n", (unsigned long)GLOBAL_OFFSET_TABLE);
}
[hjl@gnu-tgl-3 tmp]$ gcc -fPIC x.c
/usr/local/bin/ld: /tmp/cc4Lekj4.o: in function `main':
x.c:(.text+0x7): undefined reference to `GLOBAL_OFFSET_TABLE'
collect2: error: ld returned 1 exit status
[hjl@gnu-tgl-3 tmp]$ gcc -fPIC x.c
-Wl,--defsym,GLOBAL_OFFSET_TABLE=_GLOBAL_OFFSET_TABLE_
[hjl@gnu-tgl-3 tmp]$ ./a.out 
403fe8
[hjl@gnu-tgl-3 tmp]$

Reply via email to