From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id A83AD3858D20 for ; Thu, 16 Nov 2023 01:52:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A83AD3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A83AD3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700099537; cv=none; b=gytbG2xlm1jJyx15c0ioOpNPkMVNQTZJvkspj59mpyT/+jvns1wwiH3yh/9I2u/lpieIrkA77r3kN4mm+CWxU8f5ZFcmsbwGsU+fUBc+cPwVTDO67eoZQOKHgsNHBwA0TPgDbIGhDNJYYSKvx6crHGPz716O3CLEArY1qYJXjw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700099537; c=relaxed/simple; bh=g+PtlZ/tzMrLfKI5zWeF3d6wKovHuCxDqixCzT1QZ5I=; h=DKIM-Signature:From:Message-Id:Mime-Version:Subject:Date:To; b=u9kgYYWpqPId3YtFXkSIiXPt2fPhECsHtegETzpYgoZJlnlwUfNSm8zmzmxNKlHfSqWxNCjz2PYpjkIkk4nN08p2vaGQigDrboqAg4bLaLjA5AQiRyq/t9dsvJ/ndF8JldBglPw3EU1RdVxD5RoT4uJy/T0m7xU6rd345QeE7Ik= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6bcef66f9caso39739b3a.0 for ; Wed, 15 Nov 2023 17:52:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700099531; x=1700704331; darn=gcc.gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=xA8fATAltQFimsH97UXld/k0IEO51f4xi2tYt7s39vc=; b=iJGwp+I6IMLY0tdAM3H5MfJKAVGtRlvFxuPePuJH9nDYxX1296+Oxk4gXT4UyARNLo eW6B4ZiFC2ui0QLBZE8JZ4FOhCNROjtYFC06Grdo0MrpW222IF+z6D1Dz5Jgy0yZGQDi OsNlXos1i3fonAeYlvvsAF2cUgtaNlo5oKtaS6iMjNiRL7J34SLTK3CgY63j+segqmNx Kwk61NmHil9dYpCzj850Kq2AAPLwJr/GTTXjXAW51L40BIwnlKwSuIMjrknfvfOqyUGi 3I32e/vmWfQfwy3Ln6F3XAxJsbm35v31m21FK5feR290O50t1Ouk65ytWz0i2m/0Sw8K nNdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700099531; x=1700704331; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xA8fATAltQFimsH97UXld/k0IEO51f4xi2tYt7s39vc=; b=gHIn2/I0qgVWI1eeHGvOaOIBi4ST2GpUxiPc8fEcQSjp4h6/1zuJsWrdJYmefwhtIX Eo88LBfemTn8FDCQSKzowCc2jZuklxokl9EQ6VZ9FI+ZRsN8ftrTHE8JL1JkV0ja71i4 J37XE2HqcJtdfj3xhBdLduxxHH/W8H34K7eG04owVW+usZoAi0eT6XjZ25moB0mv5GGX reQSsNwI4xndQDbZbdgXtvX6e1YJHZp75SFTCNoMlbEOQ++EWsUXHB4BLw1OUXqIgCYu zPl3cFp6TF4JeR4Y7oUkwfhL3XTXq82Z9fKY4/f+W6NfWuDWDk5woGTW743+mcPoZGxR d0qw== X-Gm-Message-State: AOJu0Ywwtm2vpwcEGH1PQNsioOYbgmK/OQ6OydZg5T3v+VTIlquk0XCi eMx5hnx58mhBCBrcF4Fhhos= X-Google-Smtp-Source: AGHT+IFXyDGPrjNn6iqxFHBjkUDRvV+uwUhwhou6+o4Esn5A+I43ju5MWTXJl9Cnusz0X60M5vPTJA== X-Received: by 2002:a05:6a21:339c:b0:185:a0eb:8574 with SMTP id yy28-20020a056a21339c00b00185a0eb8574mr4124740pzb.5.1700099531378; Wed, 15 Nov 2023 17:52:11 -0800 (PST) Received: from smtpclient.apple (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id a4-20020a17090abe0400b00262eb0d141esm461110pjs.28.2023.11.15.17.52.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Nov 2023 17:52:10 -0800 (PST) From: Tatsuyuki Ishi Message-Id: <549C3D78-7D43-4D7D-B0E1-0271B1E4CBDA@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_3D6F0445-C4FD-4ED2-B30B-5673AA9932E4" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.200.91.1.1\)) Subject: Re: [PATCH v2] RISC-V: Implement TLS Descriptors. Date: Thu, 16 Nov 2023 10:51:58 +0900 In-Reply-To: <54cba99d-fa53-4ecd-b850-f8f7e2c8a21a@gmail.com> Cc: gcc-patches@gcc.gnu.org, Rui Ueyama , ruiu@bluewhale.systems, kito.cheng@gmail.com To: Jeff Law References: <20230817181308.122802-2-ishitatsuyuki@gmail.com> <20230908104923.31154-1-ishitatsuyuki@gmail.com> <54cba99d-fa53-4ecd-b850-f8f7e2c8a21a@gmail.com> X-Mailer: Apple Mail (2.3774.200.91.1.1) X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,KAM_STOCKGEN,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URIBL_BLACK autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --Apple-Mail=_3D6F0445-C4FD-4ED2-B30B-5673AA9932E4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Nov 16, 2023, at 10:07, Jeff Law wrote: >=20 >=20 >=20 > 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 configur= ed >> with --with_tls=3D{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 defa= ult >> 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 sequen= ce >> length data for TLSDESC. >> (riscv_legitimize_tls_address): Add lowering of TLSDESC. >> --- >=20 >> @@ -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=3D$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=E2=80=99ll fix it in the next version. >=20 >> @@ -1869,6 +1870,24 @@ >> [(set_attr "got" "load") >> (set_attr "mode" "")]) >> +(define_insn "@tlsdesc" >> + [(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)\;" >> + "\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" "")]) > Hmm, I would be a bit worried about explicitly using $a0 here. That's ge= nerally 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 cove= rs the whole sequence. Ideally we should do the first, but then there=E2=80= =99s the label issue and it=E2=80=99s quite a bit more complicated. So I=E2= =80=99m 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 s= ufficient 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 perhap= s the formatting fix in config.guess. Sorry for all the delay on this. My progress has been (and still) blocked o= n supporting relaxation of TLSDESC in binutils (turns out you can=E2=80=99t= run static binaries without relaxing it first). But that doesn=E2=80=99t s= eem exactly easy to do either, because relaxation that involves GOT elimina= tion isn=E2=80=99t something we have in the RISC-V backend. I=E2=80=99ll 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 whet= her they could accept the basic part of the implementation without relaxati= on first. Thanks, Tatsuyuki.=20 > jeff --Apple-Mail=_3D6F0445-C4FD-4ED2-B30B-5673AA9932E4--