public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* ppc64le: gcc forces -many on gas
@ 2021-08-11  2:55 Amol
  2021-08-11 10:42 ` Segher Boessenkool
  0 siblings, 1 reply; 3+ messages in thread
From: Amol @ 2021-08-11  2:55 UTC (permalink / raw)
  To: gcc-help

Hello,

When compiling the following lines with ppc64le-linux-gnu-gcc, version 11.2.0,
an incorrect instruction is assembled.

unsigned long val;
asm volatile ("mfpir %0" : "=r"(val));
// ppc64le-linux-gnu-gcc -mcpu=power9 a.c

The output binary contains
mfspr r9, 286

instead of

mfspr r9, 1023

----
It turns out that the assembler doesn't actually recognize the mfpir
opcode, but,
since gcc forces -many on the assembler, it is coaxed into assembling an
instruction that isn't the correct one for the power9 arch. The resulting binary
misbehaves. Another instance of this problem at [1].

Is there a way gcc can be told to not force -many on the assembler,
or, otherwise
be made to correctly support mfpir?

gcc configured with:
--enable-languages=c,c++ --with-long-double-128 --disable-nls --disable-multilib

Thank you,
Amol

[1] https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id=960e30029863db95ec79a71009272d
[2] https://www.nxp.com/docs/en/reference-manual/E500CORERM.pdf

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ppc64le: gcc forces -many on gas
  2021-08-11  2:55 ppc64le: gcc forces -many on gas Amol
@ 2021-08-11 10:42 ` Segher Boessenkool
  2021-08-16  5:55   ` Kewen.Lin
  0 siblings, 1 reply; 3+ messages in thread
From: Segher Boessenkool @ 2021-08-11 10:42 UTC (permalink / raw)
  To: Amol; +Cc: gcc-help

Hi Amol,

On Wed, Aug 11, 2021 at 08:25:24AM +0530, Amol via Gcc-help wrote:
> When compiling the following lines with ppc64le-linux-gnu-gcc, version 11.2.0,
> an incorrect instruction is assembled.
> 
> unsigned long val;
> asm volatile ("mfpir %0" : "=r"(val));
> // ppc64le-linux-gnu-gcc -mcpu=power9 a.c
> 
> The output binary contains
> mfspr r9, 286
> 
> instead of
> 
> mfspr r9, 1023
> 
> ----
> It turns out that the assembler doesn't actually recognize the mfpir
> opcode, but,
> since gcc forces -many on the assembler, it is coaxed into assembling an
> instruction that isn't the correct one for the power9 arch. The resulting binary
> misbehaves. Another instance of this problem at [1].
> 
> Is there a way gcc can be told to not force -many on the assembler,
> or, otherwise
> be made to correctly support mfpir?

There is no "mfpir" instruction on Power9, there is an extended mnemonic
though, and apparently GAS does not implement it yet.  Please file a bug
in the binutils bugzilla for that.  (We probably should implement the
extended mnemonics for many more mfspr/mtspr btw).

GCC will stop using -many as soon as that is possible to do, GCC 12 if
that works out, but that will still not solve your problem: it then will
give an error on mfpir.  If GAS *does* implement the Power9 extended
mnemonic, it will work with as well as without -many.


Segher

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ppc64le: gcc forces -many on gas
  2021-08-11 10:42 ` Segher Boessenkool
@ 2021-08-16  5:55   ` Kewen.Lin
  0 siblings, 0 replies; 3+ messages in thread
From: Kewen.Lin @ 2021-08-16  5:55 UTC (permalink / raw)
  To: suratiamol; +Cc: gcc-help, Segher Boessenkool

on 2021/8/11 下午6:42, Segher Boessenkool wrote:
> Hi Amol,
> 
> On Wed, Aug 11, 2021 at 08:25:24AM +0530, Amol via Gcc-help wrote:
>> When compiling the following lines with ppc64le-linux-gnu-gcc, version 11.2.0,
>> an incorrect instruction is assembled.
>>
>> unsigned long val;
>> asm volatile ("mfpir %0" : "=r"(val));
>> // ppc64le-linux-gnu-gcc -mcpu=power9 a.c
>>
>> The output binary contains
>> mfspr r9, 286
>>
>> instead of
>>
>> mfspr r9, 1023
>>
>> ----
>> It turns out that the assembler doesn't actually recognize the mfpir
>> opcode, but,
>> since gcc forces -many on the assembler, it is coaxed into assembling an
>> instruction that isn't the correct one for the power9 arch. The resulting binary
>> misbehaves. Another instance of this problem at [1].
>>
>> Is there a way gcc can be told to not force -many on the assembler,
>> or, otherwise
>> be made to correctly support mfpir?
> 
> There is no "mfpir" instruction on Power9, there is an extended mnemonic
> though, and apparently GAS does not implement it yet.  Please file a bug
> in the binutils bugzilla for that.  (We probably should implement the
> extended mnemonics for many more mfspr/mtspr btw).
> 

It looks that Paul had filed one PR for it:

https://sourceware.org/bugzilla/show_bug.cgi?id=27684

It should work with binutils 2.37 at -mcpu=power10.  The fix seems to
guard mfpir under Power10 mask while it's introduced since at least Power6,
it looks like a typo, probably just have a test with 2.37 and reopen it if
it doesn't work with -mcpu=power9.  :)

BR,
Kewen

> GCC will stop using -many as soon as that is possible to do, GCC 12 if
> that works out, but that will still not solve your problem: it then will
> give an error on mfpir.  If GAS *does* implement the Power9 extended
> mnemonic, it will work with as well as without -many.
> 
> 
> Segher
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-16  5:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11  2:55 ppc64le: gcc forces -many on gas Amol
2021-08-11 10:42 ` Segher Boessenkool
2021-08-16  5:55   ` Kewen.Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).