public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt
@ 2021-03-10 21:51 thiago at kde dot org
2021-03-10 22:04 ` [Bug target/99530] " thiago at kde dot org
` (14 more replies)
0 siblings, 15 replies; 16+ messages in thread
From: thiago at kde dot org @ 2021-03-10 21:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
Bug ID: 99530
Summary: [i386] 'P' inline assembly operand modifier should
obey -fno-plt
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: thiago at kde dot org
Target Milestone: ---
$ cat test.c
extern void f(void);
void g() { asm("call %P0 ; asm" : : "X" (f)); }
int h() { f(); return 0; }
The normal modes work:
$ gcc -fno-pic -S -o - -O2 test.c| grep call
call f ; asm
call f
$ gcc -fPIC -S -o - -O2 test.c| grep call
call f@PLT ; asm
call f@PLT
But the -fno-plt modes still generate PLT references:
$ gcc -fno-pic -fno-plt -S -o - -O2 test.c| grep call
call f ; asm
call *f@GOTPCREL(%rip)
$ gcc -fPIC -fno-plt -S -o - -O2 test.c| grep call
call f@PLT ; asm
call *f@GOTPCREL(%rip)
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
@ 2021-03-10 22:04 ` thiago at kde dot org
2021-03-11 13:31 ` hjl.tools at gmail dot com
` (13 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: thiago at kde dot org @ 2021-03-10 22:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
--- Comment #1 from Thiago Macieira <thiago at kde dot org> ---
Matching Clang/LLVM bug report:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
2021-03-10 22:04 ` [Bug target/99530] " thiago at kde dot org
@ 2021-03-11 13:31 ` hjl.tools at gmail dot com
2021-03-11 15:02 ` hjl.tools at gmail dot com
` (12 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: hjl.tools at gmail dot com @ 2021-03-11 13:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-03-11
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |hjl.tools at gmail dot com
CC| |hjl.tools at gmail dot com
--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
It is OK to use indirect branch via GOT in 64-bit. But it isn't OK for 32-bit
since PIC register may not be available at call site.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
2021-03-10 22:04 ` [Bug target/99530] " thiago at kde dot org
2021-03-11 13:31 ` hjl.tools at gmail dot com
@ 2021-03-11 15:02 ` hjl.tools at gmail dot com
2021-03-11 16:00 ` thiago at kde dot org
` (11 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: hjl.tools at gmail dot com @ 2021-03-11 15:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> ---
Created attachment 50366
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50366&action=edit
A patch
I am testing this.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (2 preceding siblings ...)
2021-03-11 15:02 ` hjl.tools at gmail dot com
@ 2021-03-11 16:00 ` thiago at kde dot org
2021-03-11 16:01 ` thiago at kde dot org
` (10 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: thiago at kde dot org @ 2021-03-11 16:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
--- Comment #4 from Thiago Macieira <thiago at kde dot org> ---
(In reply to H.J. Lu from comment #3)
> Created attachment 50366 [details]
> A patch
>
> I am testing this.
The same string pattern for loading from the GOT exists elsewhere in the file.
Maybe this is an opportunity to merge them into a common function?
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (3 preceding siblings ...)
2021-03-11 16:00 ` thiago at kde dot org
@ 2021-03-11 16:01 ` thiago at kde dot org
2021-03-11 16:06 ` thiago at kde dot org
` (9 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: thiago at kde dot org @ 2021-03-11 16:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
--- Comment #5 from Thiago Macieira <thiago at kde dot org> ---
(In reply to Thiago Macieira from comment #1)
> Matching Clang/LLVM bug report:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
Bad copy & paste. That's https://bugs.llvm.org/show_bug.cgi?id=49525
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (4 preceding siblings ...)
2021-03-11 16:01 ` thiago at kde dot org
@ 2021-03-11 16:06 ` thiago at kde dot org
2021-03-11 19:02 ` hjl.tools at gmail dot com
` (8 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: thiago at kde dot org @ 2021-03-11 16:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
--- Comment #6 from Thiago Macieira <thiago at kde dot org> ---
(In reply to H.J. Lu from comment #3)
> Created attachment 50366 [details]
> A patch
>
> I am testing this.
This has now changed to:
$ ~/dev/gcc/bin/gcc -fPIC -fno-plt -S -o - -O2 test.c | grep call
call f@GOTPCREL(%rip)
call *f@GOTPCREL(%rip)
The * is missing for indirect calls in AT&T syntax. Intel syntax looks correct:
$ ~/dev/gcc/bin/gcc -masm=intel -fPIC -fno-plt -S -o - -O2 test.c | grep call
call [QWORD PTR f@GOTPCREL[rip]]
call [QWORD PTR f@GOTPCREL[rip]]
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (5 preceding siblings ...)
2021-03-11 16:06 ` thiago at kde dot org
@ 2021-03-11 19:02 ` hjl.tools at gmail dot com
2021-03-11 21:03 ` thiago at kde dot org
` (7 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: hjl.tools at gmail dot com @ 2021-03-11 19:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #50366|0 |1
is obsolete| |
--- Comment #7 from H.J. Lu <hjl.tools at gmail dot com> ---
Created attachment 50369
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50369&action=edit
The v2 patch
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (6 preceding siblings ...)
2021-03-11 19:02 ` hjl.tools at gmail dot com
@ 2021-03-11 21:03 ` thiago at kde dot org
2021-03-11 21:53 ` hjl.tools at gmail dot com
` (6 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: thiago at kde dot org @ 2021-03-11 21:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
--- Comment #8 from Thiago Macieira <thiago at kde dot org> ---
(In reply to H.J. Lu from comment #7)
> Created attachment 50369 [details]
> The v2 patch
Code generation with "call %P0" is now identical to what GCC generates on its
own.
Even the alignment is now right, somehow, though it also added a newline?
$ ~/dev/gcc/bin/gcc -fPIC -fno-plt -S -o - -O2 -xc - <<<'extern void f(void);
void g() { asm("cmp %P0,$0" : : "X" (f)); }' | grep -A1 GOTPC
cmp *f@GOTPCREL(%rip)
,$0
That's probably not right.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (7 preceding siblings ...)
2021-03-11 21:03 ` thiago at kde dot org
@ 2021-03-11 21:53 ` hjl.tools at gmail dot com
2021-03-11 22:14 ` thiago at kde dot org
` (5 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: hjl.tools at gmail dot com @ 2021-03-11 21:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
--- Comment #9 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Thiago Macieira from comment #8)
> (In reply to H.J. Lu from comment #7)
> > Created attachment 50369 [details]
> > The v2 patch
>
> Code generation with "call %P0" is now identical to what GCC generates on
> its own.
>
> Even the alignment is now right, somehow, though it also added a newline?
>
> $ ~/dev/gcc/bin/gcc -fPIC -fno-plt -S -o - -O2 -xc - <<<'extern void
> f(void); void g() { asm("cmp %P0,$0" : : "X" (f)); }' | grep -A1 GOTPC
>
> cmp *f@GOTPCREL(%rip)
> ,$0
>
> That's probably not right.
Don't use %P with cmp.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (8 preceding siblings ...)
2021-03-11 21:53 ` hjl.tools at gmail dot com
@ 2021-03-11 22:14 ` thiago at kde dot org
2021-03-11 22:27 ` hjl.tools at gmail dot com
` (4 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: thiago at kde dot org @ 2021-03-11 22:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
--- Comment #10 from Thiago Macieira <thiago at kde dot org> ---
(In reply to H.J. Lu from comment #9)
> Don't use %P with cmp.
I know, but that's besides the point. I was merely trying to find something
that would have a reason to type more after the %P and show that a newline
could be wrong.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (9 preceding siblings ...)
2021-03-11 22:14 ` thiago at kde dot org
@ 2021-03-11 22:27 ` hjl.tools at gmail dot com
2021-03-11 22:28 ` hjl.tools at gmail dot com
` (3 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: hjl.tools at gmail dot com @ 2021-03-11 22:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2021-March/5
| |66651.html
--- Comment #11 from H.J. Lu <hjl.tools at gmail dot com> ---
A patch is posted at
https://gcc.gnu.org/pipermail/gcc-patches/2021-March/566651.html
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (10 preceding siblings ...)
2021-03-11 22:27 ` hjl.tools at gmail dot com
@ 2021-03-11 22:28 ` hjl.tools at gmail dot com
2021-03-11 22:38 ` thiago at kde dot org
` (2 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: hjl.tools at gmail dot com @ 2021-03-11 22:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
--- Comment #12 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Thiago Macieira from comment #10)
> (In reply to H.J. Lu from comment #9)
> > Don't use %P with cmp.
>
> I know, but that's besides the point. I was merely trying to find something
> that would have a reason to type more after the %P and show that a newline
> could be wrong.
Since my patch uses output_asm_insn to finish the instruction, %P must be
the last operand.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (11 preceding siblings ...)
2021-03-11 22:28 ` hjl.tools at gmail dot com
@ 2021-03-11 22:38 ` thiago at kde dot org
2021-03-13 16:42 ` hjl.tools at gmail dot com
2021-03-17 14:32 ` hjl.tools at gmail dot com
14 siblings, 0 replies; 16+ messages in thread
From: thiago at kde dot org @ 2021-03-11 22:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
--- Comment #13 from Thiago Macieira <thiago at kde dot org> ---
> Since my patch uses output_asm_insn to finish the instruction, %P must be
> the last operand.
Okay.
If I wanted to abuse, I could just swap it around:
$ ~/dev/gcc/bin/gcc -fPIC -fno-plt -S -o - -O2 -xc - <<<'extern void f(void);
void g() { asm("cmp%z0 $0, %P0" : : "X" (f)); }' | grep GOTPC
cmpq $0, *f@GOTPCREL(%rip)
I can't see the need to do that.
The reason I needed to "call %P0" was to call an assembly function that did not
respect the ABI (intel-ipsec-mb's sha512_x8_avx512). The code looks like this:
#ifdef _WIN32
# define EXTRA_CLOBBER "rsi", "rdi",
# define OUT0 "+c" /* rcx */
# define OUT1 "+d" /* rdx */
#else
# define EXTRA_CLOBBER "rcx", "rdx",
# define OUT0 "+D" /* rdi */
# define OUT1 "+S" /* rsi */
#endif
extern void sha512_x8_avx512(void *data, size_t size_in_blocks);
__asm__ volatile ("call %P[func]"
: OUT0 (data),
OUT1 (size_in_blocks),
"+m" (*(char (*)[])data)
: [func] "X" (sha512_x8_avx512)
:
// caller-save registers
"rax", "r8", "r9", "r10", "r11",
EXTRA_CLOBBER
// the current implementation does not use RBX and RBP
// "rbx", "rbp",
// the current implementation does clobber these callee-save registers
"r12", "r13", "r14", "r15"
);
https://github.com/intel/intel-ipsec-mb/blob/master/lib/avx512/sha512_x8_avx512.asm#L417
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (12 preceding siblings ...)
2021-03-11 22:38 ` thiago at kde dot org
@ 2021-03-13 16:42 ` hjl.tools at gmail dot com
2021-03-17 14:32 ` hjl.tools at gmail dot com
14 siblings, 0 replies; 16+ messages in thread
From: hjl.tools at gmail dot com @ 2021-03-13 16:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #50369|0 |1
is obsolete| |
--- Comment #14 from H.J. Lu <hjl.tools at gmail dot com> ---
Created attachment 50381
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50381&action=edit
The v3 patch
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug target/99530] [i386] 'P' inline assembly operand modifier should obey -fno-plt
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
` (13 preceding siblings ...)
2021-03-13 16:42 ` hjl.tools at gmail dot com
@ 2021-03-17 14:32 ` hjl.tools at gmail dot com
14 siblings, 0 replies; 16+ messages in thread
From: hjl.tools at gmail dot com @ 2021-03-17 14:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99530
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|--- |11.0
Status|NEW |RESOLVED
--- Comment #15 from H.J. Lu <hjl.tools at gmail dot com> ---
It is fixed by
The master branch has been updated by H.J. Lu <hjl@gcc.gnu.org>:
https://gcc.gnu.org/g:adf14bdbc10d4114865a08cf20020a2616039057
commit r11-7701-gadf14bdbc10d4114865a08cf20020a2616039057
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Thu Mar 11 06:48:24 2021 -0800
x86: Update 'P' operand modifier for -fno-plt
Update 'P' operand modifier for -fno-plt to support inline assembly
statements. In 64-bit, we can always load function address with
@GOTPCREL. In 32-bit, we load function address with @GOT only for
non-PIC since PIC register may not be available at call site.
gcc/
PR target/99504
* config/i386/i386.c (ix86_force_load_from_GOT_p): Support
inline assembly statements.
(ix86_print_operand): Update 'P' handling for -fno-plt.
gcc/testsuite/
PR target/99504
* gcc.target/i386/pr99530-1.c: New test.
* gcc.target/i386/pr99530-2.c: Likewise.
* gcc.target/i386/pr99530-3.c: Likewise.
* gcc.target/i386/pr99530-4.c: Likewise.
* gcc.target/i386/pr99530-5.c: Likewise.
* gcc.target/i386/pr99530-6.c: Likewise.
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2021-03-17 14:32 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10 21:51 [Bug target/99530] New: [i386] 'P' inline assembly operand modifier should obey -fno-plt thiago at kde dot org
2021-03-10 22:04 ` [Bug target/99530] " thiago at kde dot org
2021-03-11 13:31 ` hjl.tools at gmail dot com
2021-03-11 15:02 ` hjl.tools at gmail dot com
2021-03-11 16:00 ` thiago at kde dot org
2021-03-11 16:01 ` thiago at kde dot org
2021-03-11 16:06 ` thiago at kde dot org
2021-03-11 19:02 ` hjl.tools at gmail dot com
2021-03-11 21:03 ` thiago at kde dot org
2021-03-11 21:53 ` hjl.tools at gmail dot com
2021-03-11 22:14 ` thiago at kde dot org
2021-03-11 22:27 ` hjl.tools at gmail dot com
2021-03-11 22:28 ` hjl.tools at gmail dot com
2021-03-11 22:38 ` thiago at kde dot org
2021-03-13 16:42 ` hjl.tools at gmail dot com
2021-03-17 14:32 ` hjl.tools at gmail dot com
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).