[Bug driver/81653] gcc configured with --enable-default-pie on SPARC miscompiles hand-written .s files

2017-08-05 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81653

--- Comment #8 from Andrew Pinski  ---
If anything it should be the linker which should error out.  The linker is part
of binutils, report it to them.

[Bug driver/81653] gcc configured with --enable-default-pie on SPARC miscompiles hand-written .s files

2017-08-05 Thread bruno at clisp dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81653

--- Comment #7 from Bruno Haible  ---
And what do you think about the fact that it produces crashing code without any
warning?

Is there a chance that 'as' could emit a warning when it produces
R_SPARC_GOT22/R_SPARC_GOT10 relocations instead of the intended
R_SPARC_HI22/R_SPARC_LO10 relocations?

[Bug driver/81653] gcc configured with --enable-default-pie on SPARC miscompiles hand-written .s files

2017-08-05 Thread bruno at clisp dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81653

--- Comment #6 from Bruno Haible  ---
> passing -fno-pie seems to be the agreed upon way out here.

My assembly code is located in a library (think at libffcall, libffi, gmp,
...).
Therefore I don't control the final linker options.

So, the only available option the '#ifdef __PIC__' solution from comment 2.

[Bug driver/81653] gcc configured with --enable-default-pie on SPARC miscompiles hand-written .s files

2017-08-05 Thread ebotcazou at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81653

Eric Botcazou  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |WONTFIX

--- Comment #5 from Eric Botcazou  ---
OK, thanks, so passing -fno-pie seems to be the agreed upon way out here.

[Bug driver/81653] gcc configured with --enable-default-pie on SPARC miscompiles hand-written .s files

2017-08-05 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81653

--- Comment #4 from Jakub Jelinek  ---
Obviously, if you are compiling hand written assembly and linking it into PIEs
the code must be PIC.  So what is written in #c2 is not a workaround, but the
right fix.  If you have assembly that is not PIC compatible and you don't want
to link it into a PIE, either don't configure the compiler with
--enable-default-pie, or compile it with -fno-pie and link with -no-pie.
This isn't any different from any other arch; if you link in non-PIC assembly
into PIEs, either stuff doesn't link, or you get text relocations.

[Bug driver/81653] gcc configured with --enable-default-pie on SPARC miscompiles hand-written .s files

2017-08-05 Thread ebotcazou at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81653

Eric Botcazou  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-08-05
 CC||ebotcazou at gcc dot gnu.org,
   ||jakub at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #3 from Eric Botcazou  ---
Jakub, you're probably the only one with enough expertise in this area to give
an informed opinion.  What do you think?  How does that work for other targets?

[Bug driver/81653] gcc configured with --enable-default-pie on SPARC miscompiles hand-written .s files

2017-08-01 Thread bruno at clisp dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81653

Bruno Haible  changed:

   What|Removed |Added

 Target||sparc64-linux-gnu

--- Comment #2 from Bruno Haible  ---
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" ?

[Bug driver/81653] gcc configured with --enable-default-pie on SPARC miscompiles hand-written .s files

2017-08-01 Thread bruno at clisp dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81653

--- Comment #1 from Bruno Haible  ---
Created attachment 41885
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41885=edit
Test case program, part 2