On Tue, Feb 13, 2024 at 10:36 PM Fangrui Song <mask...@google.com> wrote:
>
> The constraints "i" and "s" can be used with a symbol that binds
> externally, e.g.
> ```
> namespace ns { extern int var, a[4]; }
> void foo() {
>   asm(".pushsection .xxx,\"aw\"; .dc.a %0; .popsection" :: "s"(&ns::var));
>   asm(".reloc ., BFD_RELOC_NONE, %0" :: "s"(&ns::a[3]));
> }
> ```
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/riscv/asm-raw-symbol.c: New test.
> ---
>  gcc/doc/md.texi                                 |  2 +-
>  gcc/testsuite/gcc.target/riscv/asm-raw-symbol.c | 14 ++++++++++++++
>  2 files changed, 15 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/asm-raw-symbol.c
>
> diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
> index b0c61925120..c75e5bf259d 100644
> --- a/gcc/doc/md.texi
> +++ b/gcc/doc/md.texi
> @@ -1947,7 +1947,7 @@ Integer constant that is valid as an immediate operand 
> in a 64-bit @code{MOV}
>  pseudo instruction
>
>  @item S
> -An absolute symbolic address or a label reference
> +A symbolic reference or label reference.
>
>  @item Y
>  Floating point constant zero
> diff --git a/gcc/testsuite/gcc.target/riscv/asm-raw-symbol.c 
> b/gcc/testsuite/gcc.target/riscv/asm-raw-symbol.c
> new file mode 100644
> index 00000000000..28305a8b1f0
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/asm-raw-symbol.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-fpic" } */
> +
> +extern int var, arr[2][2];
> +
> +void
> +test (void)
> +{
> +  __asm__ ("@ %0" : : "i"(&var));
> +  __asm__ ("@ %0 %1 %2" : : "s"(&var), "s"(&arr[1][1]), "s"(test));
> +}
> +
> +/* { dg-final { scan-assembler "@ var arr\\+12 test" } } */
> +/* { dg-final { scan-assembler "@ var" } } */
> --
> 2.43.0.687.g38aa6559b0-goog
>

Ping:)


-- 
宋方睿

Reply via email to