public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/100936] New: %p and %P modifiers should not emit segment overrides
@ 2021-06-06 21:29 ubizjak at gmail dot com
  2021-06-06 21:30 ` [Bug target/100936] " ubizjak at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ubizjak at gmail dot com @ 2021-06-06 21:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100936

            Bug ID: 100936
           Summary: %p and %P modifiers should not emit segment overrides
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com
  Target Milestone: ---

Following testcase:

--cut here--
__seg_gs int var = 123;

static int
*foo (void)
{
  int *addr;

  asm ("lea %p1, %0" : "=r"(addr) : "m"(var));

  return addr;
}

static int
bar (int *addr)
{
  int val;

  asm ("mov %%gs:%1, %0" : "=r"(val) : "m"(*addr));

  return val;
}

int
baz (void)
{
  int *addr = foo();
  int val = bar (addr);

  return val;
}
--cut here--

emits assembly warning when compiled on x86 target:

gcc -O2 -c lea.c
lea.c: Assembler messages:
lea.c:8: Warning: segment override on `lea' is ineffectual

$ objdump -d lea.o

lea.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <baz>:
   0:   65 48 8d 04 25 00 00    lea    %gs:0x0,%rax
   7:   00 00 
   9:   65 8b 00                mov    %gs:(%rax),%eax
   c:   c3                      retq   

The problem is with %p operand modifier, which should emit raw symbol name:

   P -- if PIC, print an @PLT suffix.  For -fno-plt, load function
        address from GOT.
   p -- print raw symbol name.

but it also emits its segment override. As shown in the above example, it is
not possible to use LEA to load its address into a register.

Similar problem is with %P modifier, trying to CALL or JMP to overriden
symbol,e.g:

        call %gs:zzz
        jmp %gs:zzz

call.s:1: Warning: skipping prefixes on `call'
call.s:2: Warning: skipping prefixes on `jmp'

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

* [Bug target/100936] %p and %P modifiers should not emit segment overrides
  2021-06-06 21:29 [Bug target/100936] New: %p and %P modifiers should not emit segment overrides ubizjak at gmail dot com
@ 2021-06-06 21:30 ` ubizjak at gmail dot com
  2021-06-09  7:46 ` cvs-commit at gcc dot gnu.org
  2021-06-09  7:48 ` ubizjak at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: ubizjak at gmail dot com @ 2021-06-06 21:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100936

--- Comment #1 from Uroš Bizjak <ubizjak at gmail dot com> ---
Proposed patch:

--cut here--
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 04649b42122..0773a4a9ba8 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -13531,7 +13531,7 @@ ix86_print_operand_punct_valid_p (unsigned char code)

 static void
 ix86_print_operand_address_as (FILE *file, rtx addr,
-                              addr_space_t as, bool no_rip)
+                              addr_space_t as, bool raw)
 {
   struct ix86_address parts;
   rtx base, index, disp;
@@ -13570,7 +13570,7 @@ ix86_print_operand_address_as (FILE *file, rtx addr,
   else
     gcc_assert (ADDR_SPACE_GENERIC_P (parts.seg));

-  if (!ADDR_SPACE_GENERIC_P (as))
+  if (!ADDR_SPACE_GENERIC_P (as) && !raw)
     {
       if (ASSEMBLER_DIALECT == ASM_ATT)
        putc ('%', file);
@@ -13589,7 +13589,7 @@ ix86_print_operand_address_as (FILE *file, rtx addr,
     }

   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
-  if (TARGET_64BIT && !base && !index && !no_rip)
+  if (TARGET_64BIT && !base && !index && !raw)
     {
       rtx symbol = disp;

--cut here--

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

* [Bug target/100936] %p and %P modifiers should not emit segment overrides
  2021-06-06 21:29 [Bug target/100936] New: %p and %P modifiers should not emit segment overrides ubizjak at gmail dot com
  2021-06-06 21:30 ` [Bug target/100936] " ubizjak at gmail dot com
@ 2021-06-09  7:46 ` cvs-commit at gcc dot gnu.org
  2021-06-09  7:48 ` ubizjak at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-09  7:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100936

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:

https://gcc.gnu.org/g:267dbd42f42c52a515f49c0875d296a9cf5988fe

commit r12-1318-g267dbd42f42c52a515f49c0875d296a9cf5988fe
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Wed Jun 9 09:46:00 2021 +0200

    i386: Do not emit segment overrides for %p and %P [PR100936]

    Using %p to move the address of a symbol using LEA:

      asm ("lea %p1, %0" : "=r"(addr) : "m"(var));

    emits assembler warning when VAR is declared in a non-generic address
space:

      Warning: segment override on `lea' is ineffectual

    The problem is with %p operand modifier, which should emit raw symbol name:

      p -- print raw symbol name.

    Similar problem exists with %P modifier, trying to CALL or JMP to an
    overridden symbol,e.g:

            call %gs:zzz
            jmp %gs:zzz

    emits assembler warning:

      Warning: skipping prefixes on `call'
      Warning: skipping prefixes on `jmp'

    Ensure that %p and %P never emit segment overrides.

    2021-06-08  Uroš Bizjak  <ubizjak@gmail.com>

    gcc/
            PR target/100936
            * config/i386/i386.c (print_operand_address_as): Rename "no_rip"
            argument to "raw".  Do not emit segment overrides when "raw" is
true.

    gcc/testsuite/

            PR target/100936
            * gcc.target/i386/pr100936.c: New test.

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

* [Bug target/100936] %p and %P modifiers should not emit segment overrides
  2021-06-06 21:29 [Bug target/100936] New: %p and %P modifiers should not emit segment overrides ubizjak at gmail dot com
  2021-06-06 21:30 ` [Bug target/100936] " ubizjak at gmail dot com
  2021-06-09  7:46 ` cvs-commit at gcc dot gnu.org
@ 2021-06-09  7:48 ` ubizjak at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: ubizjak at gmail dot com @ 2021-06-09  7:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100936

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |ubizjak at gmail dot com
             Status|UNCONFIRMED                 |RESOLVED
   Target Milestone|---                         |12.0

--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
Fixed.

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

end of thread, other threads:[~2021-06-09  7:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-06 21:29 [Bug target/100936] New: %p and %P modifiers should not emit segment overrides ubizjak at gmail dot com
2021-06-06 21:30 ` [Bug target/100936] " ubizjak at gmail dot com
2021-06-09  7:46 ` cvs-commit at gcc dot gnu.org
2021-06-09  7:48 ` ubizjak 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).