public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
To: Jeff Law <jeffreyalaw@gmail.com>
Cc: gcc-patches@gcc.gnu.org, Rui Ueyama <rui314@gmail.com>,
	ruiu@bluewhale.systems, kito.cheng@gmail.com
Subject: Re: [PATCH v2] RISC-V: Implement TLS Descriptors.
Date: Thu, 16 Nov 2023 10:51:58 +0900	[thread overview]
Message-ID: <549C3D78-7D43-4D7D-B0E1-0271B1E4CBDA@gmail.com> (raw)
In-Reply-To: <54cba99d-fa53-4ecd-b850-f8f7e2c8a21a@gmail.com>

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

> On Nov 16, 2023, at 10:07, Jeff Law <jeffreyalaw@gmail.com> wrote:
> 
> 
> 
> On 9/8/23 04:49, Tatsuyuki Ishi via Gcc-patches wrote:
>> This implements TLS Descriptors (TLSDESC) as specified in [1].
>> In TLSDESC instruction sequence, the first instruction relocates against
>> the target TLS variable, while subsequent instructions relocates against
>> the address of the first. Such usage of labels are not well-supported
>> within GCC. Due to this, the 4-instruction sequence is implemented as a
>> single RTX insn.
>> The default remains to be the traditional TLS model, but can be configured
>> with --with_tls={trad,desc}. The choice can be revisited once toolchain
>> and libc support ships.
>> [1]: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/373.
>> gcc/Changelog:
>>     * config/riscv/riscv.opt: Add -mtls-dialect to configure TLS flavor.
>>     * config.gcc: Add --with_tls configuration option to change the default
>>     TLS flavor.
>>     * config/riscv/riscv.h: Add TARGET_TLSDESC determined from
>>     -mtls-dialect and with_tls defaults.
>>     * config/riscv/riscv-opts.h: Define enum riscv_tls_type for the two TLS
>>     flavors.
>>     * config/riscv/riscv-protos.h: Define SYMBOL_TLSDESC symbol type.
>>     * config/riscv/riscv.md: Add instruction sequence for TLSDESC.
>>     * config/riscv/riscv.cc (riscv_symbol_insns): Add instruction sequence
>>     length data for TLSDESC.
>>     (riscv_legitimize_tls_address): Add lowering of TLSDESC.
>> ---
> 
>> @@ -4694,6 +4696,17 @@ case "${target}" in
>>  				;;
>>  			esac
>>  		fi
>> +		# Handle --with-tls.
>> +		case "$with_tls" in
>> +        "" \
>> +        | trad | desc)
>> +            # OK
>> +            ;;
>> +        *)
>> +            echo "Unknown TLS method used in --with-tls=$with_tls" 1>&2
>> +            exit 1
>> +            ;;
>> +        esac
> Is there a reason why this isn't formatted like the other cases?

Sorry, this was an oversight. I’ll fix it in the next version.

> 
>> @@ -1869,6 +1870,24 @@
>>    [(set_attr "got" "load")
>>     (set_attr "mode" "<MODE>")])
>>  +(define_insn "@tlsdesc<mode>"
>> +  [(set (reg:P A0_REGNUM)
>> +	    (unspec:P
>> +			[(match_operand:P 0 "symbolic_operand" "")
>> +			 (match_operand:P 1 "const_int_operand")]
>> +			UNSPEC_TLSDESC))
>> +   (clobber (reg:SI T0_REGNUM))]
>> +  "TARGET_TLSDESC"
>> +  {
>> +    return ".LT%1: auipc\ta0, %%tlsdesc_hi(%0)\;"
>> +           "<load>\tt0,%%tlsdesc_load_lo(.LT%1)(a0)\;"
>> +           "addi\ta0,a0,%%tlsdesc_add_lo(.LT%1)\;"
>> +           "jalr\tt0,t0,%%tlsdesc_call(.LT%1)";
>> +  }
>> +  [(set_attr "type" "multi")
>> +   (set_attr "length" "16")
>> +   (set_attr "mode" "<MODE>")])
> Hmm, I would be a bit worried about explicitly using $a0 here.  That's generally frowned upon, but probably unavoidable in this case since this is a call under the hood.

Based on what I have read in the AArch64 backend, there are two ways to do this: introduce a custom calling convention, or put in a RTX insn that covers the whole sequence. Ideally we should do the first, but then there’s the label issue and it’s quite a bit more complicated. So I’m sticking with this for now.

> This needs changes to invoke.texi since it introduces new options.  I don't think it has to be anything terribly verbose.  A one liner is probably sufficient and I wouldn't be surprised if other ports have suitable text we could copy.

Ack.

> So overall if Kito's OK, then I am with the trivial doc change and perhaps the formatting fix in config.guess.

Sorry for all the delay on this. My progress has been (and still) blocked on supporting relaxation of TLSDESC in binutils (turns out you can’t run static binaries without relaxing it first). But that doesn’t seem exactly easy to do either, because relaxation that involves GOT elimination isn’t something we have in the RISC-V backend.

I’ll try to send a new version of this patch and get this unblocked on GCC side first.
Presumably this still needs the associated gas and ld support in place, so let me know if you want to merge this soon. I will ask on binutils for whether they could accept the basic part of the implementation without relaxation first.

Thanks,
Tatsuyuki. 

> jeff


  reply	other threads:[~2023-11-16  1:52 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-17 18:12 [PATCH] " Tatsuyuki Ishi
2023-08-29 13:40 ` Kito Cheng
2023-09-08 10:49 ` [PATCH v2] " Tatsuyuki Ishi
2023-10-02 14:10   ` Kito Cheng
2023-11-16  1:17     ` Fangrui Song
2023-11-16  1:39       ` Tatsuyuki Ishi
2023-11-16  5:21         ` Jeff Law
2023-11-16  5:18       ` Jeff Law
2023-11-16  1:07   ` Jeff Law
2023-11-16  1:51     ` Tatsuyuki Ishi [this message]
2023-11-16  5:23       ` Jeff Law
2023-11-16  5:33         ` Fangrui Song
2023-11-16  5:36           ` Jeff Law
2023-11-16  5:37           ` Tatsuyuki Ishi
2023-11-20 13:17 ` [PATCH v3] " Tatsuyuki Ishi
2023-11-21  6:59   ` Fangrui Song
2023-11-21  7:07     ` Tatsuyuki Ishi
2023-12-05 16:49     ` Tatsuyuki Ishi
2023-11-23 10:57   ` Florian Weimer
2023-11-23 11:34     ` Tatsuyuki Ishi
2023-11-23 11:40       ` Florian Weimer
2023-12-05  7:01 ` [PATCH v4] " Tatsuyuki Ishi
2024-01-27  3:24   ` Fangrui Song
2024-03-29  5:52 ` [PATCH v5] " Tatsuyuki Ishi
2024-03-29  6:32   ` Kito Cheng
2024-04-08 14:31     ` Kito Cheng

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=549C3D78-7D43-4D7D-B0E1-0271B1E4CBDA@gmail.com \
    --to=ishitatsuyuki@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=kito.cheng@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).