Message ID | 20240111034415.431657-1-maskray@google.com |
---|---|
State | New |
Headers | show |
Series | i386: Add "z" constraint for symbolic address/label reference [PR105576] | expand |
On Thu, Jan 11, 2024 at 4:44 AM Fangrui Song <maskray@google.com> wrote: > > 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 "z". Please use W-prefixed multi-letter constraint name. Uros. > > gcc/ChangeLog: > > PR target/105576 > * config/i386/constraints.md: Define constraint 'z'. > * doc/md.texi: Document it. > > gcc/testsuite/ChangeLog: > > * gcc.target/i386/asm-raw-symbol.c: New testcase. > --- > gcc/config/i386/constraints.md | 5 ++++- > gcc/doc/md.texi | 4 ++++ > gcc/testsuite/gcc.target/i386/asm-raw-symbol.c | 13 +++++++++++++ > 3 files changed, 21 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.target/i386/asm-raw-symbol.c > > diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md > index 0c6e662df25..64330dfdf01 100644 > --- a/gcc/config/i386/constraints.md > +++ b/gcc/config/i386/constraints.md > @@ -19,7 +19,6 @@ > > ;;; Unused letters: > ;;; H > -;;; z > > ;; Integer register constraints. > ;; It is not necessary to define 'r' here. > @@ -438,3 +437,7 @@ (define_constraint "je" > "@internal constant that do not allow any unspec global offsets" > (and (match_operand 0 "x86_64_immediate_operand") > (match_test "!x86_poff_operand_p (op)"))) > + > +(define_constraint "z" > + "A symbolic reference or label reference." > + (match_code "const,symbol_ref,label_ref")) > diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi > index 47a87d6ceec..bbfec024311 100644 > --- a/gcc/doc/md.texi > +++ b/gcc/doc/md.texi > @@ -4286,6 +4286,10 @@ VSIB address operand. > @item Ts > Address operand without segment register. > > +@item z > +A symbolic reference or label reference. > +You can use the @code{%p} modifier to print the raw symbol. > + > @end table > > @item Xstormy16---@file{config/stormy16/stormy16.h} > 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 > index 00000000000..ce88f3baee6 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/asm-raw-symbol.c > @@ -0,0 +1,13 @@ > +/* { dg-do compile } */ > + > +extern int var; > + > +void > +func (void) > +{ > + __asm__ ("@ %p0" : : "z" (func)); > + __asm__ ("@ %p0" : : "z" (&var + 1)); > +} > + > +/* { dg-final { scan-assembler "@ func" } } */ > +/* { dg-final { scan-assembler "@ var\\+4" } } */ > -- > 2.43.0.275.g3460e3d667-goog >
On 2024-01-11, Uros Bizjak wrote: >On Thu, Jan 11, 2024 at 4:44 AM Fangrui Song <maskray@google.com> wrote: >> >> 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 "z". > >Please use W-prefixed multi-letter constraint name. > >Uros. Sounds good. How about "Ws"? (I've asked overseers@gcc.gnu.org whether I can get gcc access (I already have binutils-gdb/glibc access), so that I can land approved patches myself in the future) From ad7bf3dce026bf226e22ab709c9326c611a4b745 Mon Sep 17 00:00:00 2001 From: Fangrui Song <maskray@google.com> Date: Wed, 10 Jan 2024 18:49:45 -0800 Subject: [PATCH] i386: Add "Ws" constraint for symbolic address/label reference [PR105576] 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" :: "S"(&var)); asm (".reloc ., BFD_RELOC_NONE, %0" :: "S"(&var)); ``` gcc/ChangeLog: PR target/105576 * config/i386/constraints.md: Define constraint "Ws". * doc/md.texi: Document it. gcc/testsuite/ChangeLog: * gcc.target/i386/asm-raw-symbol.c: New testcase. --- gcc/config/i386/constraints.md | 4 ++++ gcc/doc/md.texi | 4 ++++ gcc/testsuite/gcc.target/i386/asm-raw-symbol.c | 13 +++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/asm-raw-symbol.c diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md index 0c6e662df25..280e4c8e36c 100644 --- a/gcc/config/i386/constraints.md +++ b/gcc/config/i386/constraints.md @@ -348,6 +348,10 @@ (define_constraint "Wf" 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 diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi index 47a87d6ceec..b0c61925120 100644 --- a/gcc/doc/md.texi +++ b/gcc/doc/md.texi @@ -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 index 00000000000..b7854567dd9 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/asm-raw-symbol.c @@ -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" } } */
On Thu, Jan 11, 2024 at 9:33 AM Fangrui Song <maskray@google.com> wrote: > > On 2024-01-11, Uros Bizjak wrote: > >On Thu, Jan 11, 2024 at 4:44 AM Fangrui Song <maskray@google.com> wrote: > >> > >> 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 "z". > > > >Please use W-prefixed multi-letter constraint name. > > > >Uros. > > Sounds good. How about "Ws"? Yes, LGTM. Thanks, Uros. > > (I've asked overseers@gcc.gnu.org whether I can get gcc access (I > already have binutils-gdb/glibc access), so that I can land approved > patches myself in the future) > > > From ad7bf3dce026bf226e22ab709c9326c611a4b745 Mon Sep 17 00:00:00 2001 > From: Fangrui Song <maskray@google.com> > Date: Wed, 10 Jan 2024 18:49:45 -0800 > Subject: [PATCH] i386: Add "Ws" constraint for symbolic address/label > reference [PR105576] > > 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" :: "S"(&var)); > asm (".reloc ., BFD_RELOC_NONE, %0" :: "S"(&var)); > ``` > > gcc/ChangeLog: > > PR target/105576 > * config/i386/constraints.md: Define constraint "Ws". > * doc/md.texi: Document it. > > gcc/testsuite/ChangeLog: > > * gcc.target/i386/asm-raw-symbol.c: New testcase. > --- > gcc/config/i386/constraints.md | 4 ++++ > gcc/doc/md.texi | 4 ++++ > gcc/testsuite/gcc.target/i386/asm-raw-symbol.c | 13 +++++++++++++ > 3 files changed, 21 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/i386/asm-raw-symbol.c > > diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md > index 0c6e662df25..280e4c8e36c 100644 > --- a/gcc/config/i386/constraints.md > +++ b/gcc/config/i386/constraints.md > @@ -348,6 +348,10 @@ (define_constraint "Wf" > 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 > diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi > index 47a87d6ceec..b0c61925120 100644 > --- a/gcc/doc/md.texi > +++ b/gcc/doc/md.texi > @@ -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 > index 00000000000..b7854567dd9 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/asm-raw-symbol.c > @@ -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" } } */ > -- > 2.43.0.275.g3460e3d667-goog >
diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md index 0c6e662df25..64330dfdf01 100644 --- a/gcc/config/i386/constraints.md +++ b/gcc/config/i386/constraints.md @@ -19,7 +19,6 @@ ;;; Unused letters: ;;; H -;;; z ;; Integer register constraints. ;; It is not necessary to define 'r' here. @@ -438,3 +437,7 @@ (define_constraint "je" "@internal constant that do not allow any unspec global offsets" (and (match_operand 0 "x86_64_immediate_operand") (match_test "!x86_poff_operand_p (op)"))) + +(define_constraint "z" + "A symbolic reference or label reference." + (match_code "const,symbol_ref,label_ref")) diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi index 47a87d6ceec..bbfec024311 100644 --- a/gcc/doc/md.texi +++ b/gcc/doc/md.texi @@ -4286,6 +4286,10 @@ VSIB address operand. @item Ts Address operand without segment register. +@item z +A symbolic reference or label reference. +You can use the @code{%p} modifier to print the raw symbol. + @end table @item Xstormy16---@file{config/stormy16/stormy16.h} 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 index 00000000000..ce88f3baee6 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/asm-raw-symbol.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +extern int var; + +void +func (void) +{ + __asm__ ("@ %p0" : : "z" (func)); + __asm__ ("@ %p0" : : "z" (&var + 1)); +} + +/* { dg-final { scan-assembler "@ func" } } */ +/* { dg-final { scan-assembler "@ var\\+4" } } */