https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81653
Bruno Haible <bruno at clisp dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target| |sparc64-linux-gnu
--- Comment #2 from Bruno Haible <bruno at clisp dot org> ---
Apparently, on SPARC, there are two ways of referring to global variables from
within .s files. The non-PIC way is
sethi %hi(variable), %g1
or %g1, %lo(variable), %g1
The PIC way is
sethi %hi(_GLOBAL_OFFSET_TABLE_-8), %l7
add %l7, %lo(_GLOBAL_OFFSET_TABLE_-4), %l7
call __sparc_get_pc_thunk.l7
nop
sethi %gdop_hix22(variable), %g1
xor %g1, %gdop_lox10(variable), %g1
ld [%l7 + %g1], %g1, %gdop(variable)
The ugly thing is that
* the non-PIC way, compiled by "gcc -fPIC", crashes,
* the PIC way, compiled by "gcc" without -fPIC and without
--enable-default-pie, crashes as well.
So in order to write hand-written assembly that accesses global variables, one
has to write a .S file (that gets preprocessed!)
#ifdef __PIC__
sethi %hi(_GLOBAL_OFFSET_TABLE_-8), %l7
add %l7, %lo(_GLOBAL_OFFSET_TABLE_-4), %l7
call __sparc_get_pc_thunk.l7
nop
sethi %gdop_hix22(variable), %g1
xor %g1, %gdop_lox10(variable), %g1
ld [%l7 + %g1], %g1, %gdop(variable)
#else
sethi %hi(variable), %g1
or %g1, %lo(variable), %g1
#endif
Is this the only workaround to a silent change of behaviour of commands such as
"gcc -c getter.s" ?