public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1318] i386: Do not emit segment overrides for %p and %P [PR100936]
@ 2021-06-09  7:46 Uros Bizjak
  0 siblings, 0 replies; only message in thread
From: Uros Bizjak @ 2021-06-09  7:46 UTC (permalink / raw)
  To: gcc-cvs

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.

Diff:
---
 gcc/config/i386/i386.c                   |  6 +++---
 gcc/testsuite/gcc.target/i386/pr100936.c | 34 ++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index b0d19a61a76..05b8dc806cd 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;
 
diff --git a/gcc/testsuite/gcc.target/i386/pr100936.c b/gcc/testsuite/gcc.target/i386/pr100936.c
new file mode 100644
index 00000000000..c076cbb2405
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr100936.c
@@ -0,0 +1,34 @@
+/* PR target/100936 */
+/* { dg-do assemble } */
+/* { dg-options "-O2" } */
+
+__seg_gs int var;
+
+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;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-09  7:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09  7:46 [gcc r12-1318] i386: Do not emit segment overrides for %p and %P [PR100936] Uros Bizjak

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).