On Thu, Dec 19, 2019 at 04:50:40PM +0100, Jan Hubicka wrote: > Outputting the move as RIP relative movq would work. > LC12 is string "s" and has nothing to do with stack protecting.
This should fix it by doing more carefully what *movdi_internal does. Will bootstrap/regtest it tonight. 2019-12-19 Jakub Jelinek <ja...@redhat.com> PR target/92841 * config/i386/i386.md (*stack_protect_set_3): For pic_32bit_operand always use lea{q}, no matter what value which_alternative has. * gcc.target/i386/pr92841-2.c: New test. --- gcc/config/i386/i386.md.jj 2019-12-19 13:31:52.424108730 +0100 +++ gcc/config/i386/i386.md 2019-12-19 18:12:54.064747056 +0100 @@ -19863,12 +19863,13 @@ (define_insn "*stack_protect_set_3" { output_asm_insn ("mov{q}\t{%3, %1|%1, %3}", operands); output_asm_insn ("mov{q}\t{%1, %0|%0, %1}", operands); - if (which_alternative == 0) + if (pic_32bit_operand (operands[2], DImode)) + return "lea{q}\t{%E2, %1|%1, %E2}"; + else if (which_alternative == 0) return "mov{l}\t{%k2, %k1|%k1, %k2}"; else if (which_alternative == 2) return "movabs{q}\t{%2, %1|%1, %2}"; - else if (pic_32bit_operand (operands[2], DImode) - || ix86_use_lea_for_mov (insn, operands + 1)) + else if (ix86_use_lea_for_mov (insn, operands + 1)) return "lea{q}\t{%E2, %1|%1, %E2}"; else return "mov{q}\t{%2, %1|%1, %2}"; --- gcc/testsuite/gcc.target/i386/pr92841-2.c.jj 2019-12-19 18:18:31.295587557 +0100 +++ gcc/testsuite/gcc.target/i386/pr92841-2.c 2019-12-19 18:19:37.800570175 +0100 @@ -0,0 +1,18 @@ +/* PR target/92841 */ +/* { dg-do compile { target { { { *-*-linux* } && lp64 } && fstack_protector } } } */ +/* { dg-options "-O2 -fpic -fstack-protector-strong -masm=att" } */ +/* { dg-final { scan-assembler "leaq\tbuf2\\\(%rip\\\)," } } */ + +static char buf2[64]; +void bar (char *, char *); + +void +foo () +{ + char buf[64]; + char *p = buf2; + asm ("" : "+a" (p)); + char *q = buf; + asm ("" : "+r" (q)); + bar (p, q); +} Jakub