]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Add "Ws" constraint for symbolic address/label reference [PR105576]
authorFangrui Song <maskray@google.com>
Thu, 11 Jan 2024 18:24:25 +0000 (10:24 -0800)
committerH.J. Lu <(no_default)>
Tue, 30 Jan 2024 23:21:04 +0000 (15:21 -0800)
Printing the raw symbol is useful in inline asm (e.g. in C++ to get the
mangled name).  Similar constraints are available in other targets (e.g.
"S" for aarch64/riscv, "Cs" for m68k).

There isn't a good way for x86 yet, e.g. "i" doesn't work for
PIC/-mcmodel=large.  This patch adds "Ws".  Here are possible use cases:

```
namespace ns { extern int var; }
asm (".pushsection .xxx,\"aw\"; .dc.a %0; .popsection" :: "Ws"(&var));
asm (".reloc ., BFD_RELOC_NONE, %0" :: "Ws"(&var));
```

gcc/ChangeLog:

PR target/105576
* config/i386/constraints.md: Define constraint "Ws".
* doc/md.texi: Document it.

gcc/testsuite/ChangeLog:

PR target/105576
* gcc.target/i386/asm-raw-symbol.c: New testcase.

gcc/config/i386/constraints.md
gcc/doc/md.texi
gcc/testsuite/gcc.target/i386/asm-raw-symbol.c [new file with mode: 0644]

index 0c6e662df25f6b9953ec5b702b3283c8ba068448..280e4c8e36cc5258fb670c6202e183ff31da83b4 100644 (file)
    to double word size."
   (match_operand 0 "x86_64_dwzext_immediate_operand"))
 
+(define_constraint "Ws"
+  "A symbolic reference or label reference."
+  (match_code "const,symbol_ref,label_ref"))
+
 (define_constraint "Z"
   "32-bit unsigned integer constant, or a symbolic reference known
    to fit that range (for immediate operands in zero-extending x86-64
index 47a87d6ceecf8c3f3b8ede9767984f673f003f4b..b0c6192512085c20bbe4e476c56574dab4f4f92c 100644 (file)
@@ -4275,6 +4275,10 @@ require non-@code{VOIDmode} immediate operands).
 128-bit integer constant where both the high and low 64-bit word
 satisfy the @code{e} constraint.
 
+@item Ws
+A symbolic reference or label reference.
+You can use the @code{%p} modifier to print the raw symbol.
+
 @item Z
 32-bit unsigned integer constant, or a symbolic reference known
 to fit that range (for immediate operands in zero-extending x86-64
diff --git a/gcc/testsuite/gcc.target/i386/asm-raw-symbol.c b/gcc/testsuite/gcc.target/i386/asm-raw-symbol.c
new file mode 100644 (file)
index 0000000..b785456
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+
+extern int var;
+
+void
+func (void)
+{
+  __asm__ ("@ %p0" : : "Ws" (func));
+  __asm__ ("@ %p0" : : "Ws" (&var + 1));
+}
+
+/* { dg-final { scan-assembler "@ func" } } */
+/* { dg-final { scan-assembler "@ var\\+4" } } */