public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nelson Chu <nelson@rivosinc.com>
To: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
Cc: binutils@sourceware.org, i@maskray.me, rui314@gmail.com,
	 ruiu@bluewhale.systems
Subject: Re: [PATCH v3 3/9] RISC-V: Add assembly support for TLSDESC.
Date: Mon, 19 Feb 2024 09:44:06 +0800	[thread overview]
Message-ID: <CAPpQWtChDY922B65g8qF1c+dJjmzyb=W+CS=9Ok_LnyW5b7Fnw@mail.gmail.com> (raw)
In-Reply-To: <20231128085109.28422-4-ishitatsuyuki@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 7455 bytes --]

On Tue, Nov 28, 2023 at 4:51 PM Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
wrote:

> gas/
>     * tc-riscv.c (percent_op_*): Add support for %tlsdesc_hi,
>     %tlsdesc_load_lo, %tlsdesc_add_lo and %tlsdesc_call. percent_op_rtype
>     renamed to percent_op_relax_only as this matcher is extended to handle
>     jalr as well which is not R-type.
>     (riscv_ip): Apply the percent_op_relax_only rename and update comment.
>     (md_apply_fix): Add TLSDESC_* to relaxable list. Add TLSDESC_HI20 to
>     TLS relocation check list.
>     * testsuite/gas/riscv/tlsdesc.*: New test cases for TLSDESC relocation
>     generation.
> opcodes/
>     * riscv-opc.c (riscv_opcodes): Add a new syntax for jalr with
>     %tlsdesc_call annotations.
> ---
>  gas/config/tc-riscv.c             | 18 +++++++++++++-----
>  gas/testsuite/gas/riscv/tlsdesc.d | 22 ++++++++++++++++++++++
>  gas/testsuite/gas/riscv/tlsdesc.s | 24 ++++++++++++++++++++++++
>  opcodes/riscv-opc.c               |  1 +
>  4 files changed, 60 insertions(+), 5 deletions(-)
>  create mode 100644 gas/testsuite/gas/riscv/tlsdesc.d
>  create mode 100644 gas/testsuite/gas/riscv/tlsdesc.s
>
> diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
> index 04738d5e00c..376d2a34530 100644
> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -2113,6 +2113,7 @@ static const struct percent_op_match
> percent_op_utype[] =
>    {"tprel_hi", BFD_RELOC_RISCV_TPREL_HI20},
>    {"pcrel_hi", BFD_RELOC_RISCV_PCREL_HI20},
>    {"got_pcrel_hi", BFD_RELOC_RISCV_GOT_HI20},
> +  {"tlsdesc_hi", BFD_RELOC_RISCV_TLSDESC_HI20},
>    {"tls_ie_pcrel_hi", BFD_RELOC_RISCV_TLS_GOT_HI20},
>    {"tls_gd_pcrel_hi", BFD_RELOC_RISCV_TLS_GD_HI20},
>    {"hi", BFD_RELOC_RISCV_HI20},
> @@ -2124,6 +2125,8 @@ static const struct percent_op_match
> percent_op_itype[] =
>    {"lo", BFD_RELOC_RISCV_LO12_I},
>    {"tprel_lo", BFD_RELOC_RISCV_TPREL_LO12_I},
>    {"pcrel_lo", BFD_RELOC_RISCV_PCREL_LO12_I},
> +  {"tlsdesc_load_lo", BFD_RELOC_RISCV_TLSDESC_LOAD_LO12},
> +  {"tlsdesc_add_lo", BFD_RELOC_RISCV_TLSDESC_ADD_LO12},
>    {0, 0}
>  };
>
> @@ -2135,8 +2138,9 @@ static const struct percent_op_match
> percent_op_stype[] =
>    {0, 0}
>  };
>
> -static const struct percent_op_match percent_op_rtype[] =
> +static const struct percent_op_match percent_op_relax_only[] =
>  {
> +  {"tlsdesc_call", BFD_RELOC_RISCV_TLSDESC_CALL},
>    {"tprel_add", BFD_RELOC_RISCV_TPREL_ADD},
>    {0, 0}
>  };
> @@ -3244,10 +3248,10 @@ riscv_ip (char *str, struct riscv_cl_insn *ip,
> expressionS *imm_expr,
>               *imm_reloc = BFD_RELOC_RISCV_LO12_I;
>               goto load_store;
>             case '1':
> -             /* This is used for TLS, where the fourth operand is
> -                %tprel_add, to get a relocation applied to an add
> -                instruction, for relaxation to use.  */
> -             p = percent_op_rtype;
> +             /* This is used for TLS relocations that acts as relaxation
> +                markers and do not change the instruction encoding,
> +                i.e. %tprel_add and %tlsdesc_call.  */
> +             p = percent_op_relax_only;
>

Okay, looks good.


>               goto alu_op;
>             case '0': /* AMO displacement, which must be zero.  */
>             load_store:
> @@ -4036,6 +4040,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg
> ATTRIBUTE_UNUSED)
>      case BFD_RELOC_RISCV_TPREL_LO12_I:
>      case BFD_RELOC_RISCV_TPREL_LO12_S:
>      case BFD_RELOC_RISCV_TPREL_ADD:
> +    case BFD_RELOC_RISCV_TLSDESC_HI20:
>        relaxable = true;
>        /* Fall through.  */
>
> @@ -4209,6 +4214,9 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg
> ATTRIBUTE_UNUSED)
>
>      case BFD_RELOC_RISCV_CALL:
>      case BFD_RELOC_RISCV_CALL_PLT:
> +    case BFD_RELOC_RISCV_TLSDESC_LOAD_LO12:
> +    case BFD_RELOC_RISCV_TLSDESC_ADD_LO12:
> +    case BFD_RELOC_RISCV_TLSDESC_CALL:
>        relaxable = true;
>        break;
>
> diff --git a/gas/testsuite/gas/riscv/tlsdesc.d
> b/gas/testsuite/gas/riscv/tlsdesc.d
> new file mode 100644
> index 00000000000..11872953d23
> --- /dev/null
> +++ b/gas/testsuite/gas/riscv/tlsdesc.d
> @@ -0,0 +1,22 @@
> +#as: -march=rv32ia
>

Probably can remove the architecture setting, so that we can test more
situations.


> +#source: tlsdesc.s
> +#readelf: -Wr
>

#objdump: -dr maye be better.


> +
> +Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 16 entries:
> + +Offset +Info +Type +Sym. Value +Symbol's Name \+ Addend
> +0+ +0+a3e +R_RISCV_TLSDESC_HI20 +0+ +sg1 \+ 0
> +0+ +0+33 +R_RISCV_RELAX + 0
> +0+4 +0+63f +R_RISCV_TLSDESC_LOAD_LO12 0+ +\.desc1 \+ 0
> +0+4 +0+33 +R_RISCV_RELAX + 0
> +0+8 +0+640 +R_RISCV_TLSDESC_ADD_LO12 0+ +\.desc1 \+ 0
> +0+8 +0+33 +R_RISCV_RELAX + 0
> +0+c +0+641 +R_RISCV_TLSDESC_CALL +0+ +\.desc1 \+ 0
> +0+c +0+33 +R_RISCV_RELAX + 0
> +0+10 +0+53e +R_RISCV_TLSDESC_HI20 +0+4 +sl1 \+ 0
> +0+10 +0+33 +R_RISCV_RELAX + 0
> +0+14 +0+83f +R_RISCV_TLSDESC_LOAD_LO12 0+10 +\.desc2 \+ 0
> +0+14 +0+33 +R_RISCV_RELAX + 0
> +0+18 +0+840 +R_RISCV_TLSDESC_ADD_LO12 0+10 +\.desc2 \+ 0
> +0+18 +0+33 +R_RISCV_RELAX +0
> +0+1c +0+841 +R_RISCV_TLSDESC_CALL +0+10 +\.desc2 \+ 0
> +0+1c +0+33 +R_RISCV_RELAX +0


[ ] means [space+tab]

0+000 <_start>:
[ ]+0:[ ]+[0-9a-f]+[ ]+auipc[ ]+a0,0x0
[ ]+0:[ ]+R_RISCV_TLSDESC_HI20[ ]+sg1
[ ]+0:[ ]+R_RISCV_RELAX[ ]+0
...




> diff --git a/gas/testsuite/gas/riscv/tlsdesc.s
> b/gas/testsuite/gas/riscv/tlsdesc.s
> new file mode 100644
> index 00000000000..15468d5f947
> --- /dev/null
> +++ b/gas/testsuite/gas/riscv/tlsdesc.s
> @@ -0,0 +1,24 @@
> +       .section        .tbss,"awT",@nobits
> +       .global sg1
> +sg1:
> +       .zero   4
> +sl1:
> +       .zero   4
> +
> +       .text
> +       .globl  _start
> +       .type   _start,@function
> +_start:
> +.desc1:
> +       auipc   a0, %tlsdesc_hi(sg1)
> +       lw      t0, %tlsdesc_load_lo(.desc1)(a0)
> +       addi    a0, a0, %tlsdesc_add_lo(.desc1)
> +       jalr    t0, t0, %tlsdesc_call(.desc1)
> +
> +.desc2:
> +       auipc   a0, %tlsdesc_hi(sl1)
> +       lw      t0, %tlsdesc_load_lo(.desc2)(a0)
> +       addi    a0, a0, %tlsdesc_add_lo(.desc2)
> +       jalr    t0, t0, %tlsdesc_call(.desc2)
> +
> +       ret
> diff --git a/opcodes/riscv-opc.c b/opcodes/riscv-opc.c
> index bf19978e025..edaf4b0c8b5 100644
> --- a/opcodes/riscv-opc.c
> +++ b/opcodes/riscv-opc.c
> @@ -372,6 +372,7 @@ const struct riscv_opcode riscv_opcodes[] =
>  {"jalr",        0, INSN_CLASS_I, "s,j",       MATCH_JALR|(X_RA <<
> OP_SH_RD), MASK_JALR|MASK_RD, match_opcode, INSN_ALIAS|INSN_JSR },
>  {"jalr",        0, INSN_CLASS_I, "d,s",       MATCH_JALR,
> MASK_JALR|MASK_IMM, match_opcode, INSN_ALIAS|INSN_JSR },
>  {"jalr",        0, INSN_CLASS_I, "d,o(s)",    MATCH_JALR, MASK_JALR,
> match_opcode, INSN_JSR },
> +{"jalr",        0, INSN_CLASS_I, "d,s,1",     MATCH_JALR,
> MASK_JALR|MASK_IMM, match_opcode, INSN_JSR },
>  {"jalr",        0, INSN_CLASS_I, "d,s,j",     MATCH_JALR, MASK_JALR,
> match_opcode, INSN_JSR },
>  {"j",           0, INSN_CLASS_C, "Ca",        MATCH_C_J, MASK_C_J,
> match_opcode, INSN_ALIAS|INSN_BRANCH },
>  {"j",           0, INSN_CLASS_I, "a",         MATCH_JAL,
> MASK_JAL|MASK_RD, match_opcode, INSN_ALIAS|INSN_BRANCH },
> --
> 2.43.0
>
>

  reply	other threads:[~2024-02-19  1:44 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-17 18:08 [PATCH 0/4] RISC-V: Implement TLS Descriptors Tatsuyuki Ishi
2023-08-17 18:08 ` [PATCH 1/4] RISC-V: Add TLSDESC reloc definitions Tatsuyuki Ishi
2023-08-17 18:08 ` [PATCH 2/4] RISC-V: Add assembly support for TLSDESC Tatsuyuki Ishi
2023-08-17 18:08 ` [PATCH 3/4] RISC-V: Define and use GOT entry size constants for TLS Tatsuyuki Ishi
2023-08-17 18:08 ` [PATCH 4/4] RISC-V: Initial ld.bfd support for TLSDESC Tatsuyuki Ishi
2023-08-18  0:22 ` [PATCH 0/4] RISC-V: Implement TLS Descriptors Nelson Chu
2023-08-18  7:13   ` Fangrui Song
2023-08-31 17:13 ` [PATCH v2 0/5] " Tatsuyuki Ishi
2023-08-31 17:13   ` [PATCH v2 1/5] RISC-V: Fix local GOT and reloc size calculation for TLS Tatsuyuki Ishi
2024-02-21  0:49     ` Nelson Chu
2024-02-21  7:04       ` Nelson Chu
2023-08-31 17:13   ` [PATCH v2 2/5] RISC-V: Add TLSDESC reloc definitions Tatsuyuki Ishi
2023-08-31 17:13   ` [PATCH v2 3/5] RISC-V: Add assembly support for TLSDESC Tatsuyuki Ishi
2023-08-31 17:13   ` [PATCH v2 4/5] RISC-V: Define and use GOT entry size constants for TLS Tatsuyuki Ishi
2023-08-31 17:13   ` [PATCH v2 5/5] RISC-V: Initial ld.bfd support for TLSDESC Tatsuyuki Ishi
2023-11-28  8:51 ` [PATCH v3 0/9] RISC-V: Implement TLS Descriptors Tatsuyuki Ishi
2023-11-28  8:51   ` [PATCH v3 1/9] RISC-V: Fix local GOT and reloc size calculation for TLS Tatsuyuki Ishi
2023-11-28  8:51   ` [PATCH v3 2/9] RISC-V: Add TLSDESC reloc definitions Tatsuyuki Ishi
2024-02-19  0:49     ` Nelson Chu
2024-02-20 17:28       ` Tatsuyuki Ishi
2023-11-28  8:51   ` [PATCH v3 3/9] RISC-V: Add assembly support for TLSDESC Tatsuyuki Ishi
2024-02-19  1:44     ` Nelson Chu [this message]
2024-02-20 17:29       ` Tatsuyuki Ishi
2023-11-28  8:51   ` [PATCH v3 4/9] RISC-V: Define and use GOT entry size constants for TLS Tatsuyuki Ishi
2024-02-19  1:57     ` Nelson Chu
2024-02-20 17:32       ` Tatsuyuki Ishi
2023-11-28  8:51   ` [PATCH v3 5/9] RISC-V: Initial ld.bfd support for TLSDESC Tatsuyuki Ishi
2024-02-19  4:33     ` Nelson Chu
2024-02-20 17:36       ` Tatsuyuki Ishi
2023-11-28  8:51   ` [PATCH v3 6/9] RISC-V: Move STATIC_TLS handling into record_tls_type Tatsuyuki Ishi
2023-11-28  8:51   ` [PATCH v3 7/9] RISC-V: Unify TLS handling in check_relocs Tatsuyuki Ishi
2023-11-28  8:51   ` [PATCH v3 8/9] RISC-V: Add elf_link_hash_entry to relax_func args Tatsuyuki Ishi
2023-11-28  8:51   ` [PATCH v3 9/9] RISC-V: Introduce TLSDESC relaxation Tatsuyuki Ishi
2023-12-05 16:44   ` [PATCH v3 0/9] RISC-V: Implement TLS Descriptors Tatsuyuki Ishi
2023-12-06  0:33     ` Nelson Chu
2023-12-07  3:35       ` Fangrui Song
2023-12-13  0:27         ` Palmer Dabbelt
2023-12-13  1:53           ` Tatsuyuki Ishi
2024-01-27  0:57             ` Fangrui Song
2024-02-20 17:55 ` [PATCH v4 " Tatsuyuki Ishi
2024-02-20 17:55   ` [PATCH v4 1/9] RISC-V: Fix local GOT and reloc size calculation for TLS Tatsuyuki Ishi
2024-02-20 17:55   ` [PATCH v4 2/9] RISC-V: Add TLSDESC reloc definitions Tatsuyuki Ishi
2024-02-20 17:55   ` [PATCH v4 3/9] RISC-V: Add assembly support for TLSDESC Tatsuyuki Ishi
2024-02-20 17:55   ` [PATCH v4 4/9] RISC-V: Define and use GOT entry size constants for TLS Tatsuyuki Ishi
2024-02-20 17:55   ` [PATCH v4 5/9] RISC-V: Initial ld.bfd support for TLSDESC Tatsuyuki Ishi
2024-02-20 17:55   ` [PATCH v4 6/9] RISC-V: Move STATIC_TLS handling into record_tls_type Tatsuyuki Ishi
2024-02-20 17:55   ` [PATCH v4 7/9] RISC-V: Unify TLS handling in check_relocs Tatsuyuki Ishi
2024-02-20 17:55   ` [PATCH v4 8/9] RISC-V: Add elf_link_hash_entry to relax_func args Tatsuyuki Ishi
2024-02-20 17:55   ` [PATCH v4 9/9] RISC-V: Introduce TLSDESC relaxation Tatsuyuki Ishi
2024-02-29  7:06   ` [PATCH v4 0/9] RISC-V: Implement TLS Descriptors Nelson Chu
2024-02-29  7:14     ` Tatsuyuki Ishi
2024-03-29  6:22       ` Tatsuyuki Ishi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPpQWtChDY922B65g8qF1c+dJjmzyb=W+CS=9Ok_LnyW5b7Fnw@mail.gmail.com' \
    --to=nelson@rivosinc.com \
    --cc=binutils@sourceware.org \
    --cc=i@maskray.me \
    --cc=ishitatsuyuki@gmail.com \
    --cc=rui314@gmail.com \
    --cc=ruiu@bluewhale.systems \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).