From patchwork Tue Dec 5 07:01:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 173749 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3253914vqy; Mon, 4 Dec 2023 23:02:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IG4Jf6mUTKB/7BaOXRJ6RHNrviRGqOa+/VXfA5tU99+VJD3AvUiwxmEhrriDr4biWQw01hF X-Received: by 2002:ac8:7d50:0:b0:425:4043:5f18 with SMTP id h16-20020ac87d50000000b0042540435f18mr1038913qtb.86.1701759755849; Mon, 04 Dec 2023 23:02:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701759755; cv=pass; d=google.com; s=arc-20160816; b=rNNsjsi4iMLAJTPcKlvdLT9yXlT1zsunDPM2uvWCsDz3op7GmVyCG3yDh5Yb1TvVFB 2Kl09cQDfsREx1kxLCYOvuSRt2r3vdeeU1FAEPemIaMaYVekgTRX6fD/shnDHoqYsL8x A9W3GE9XmXrwD1r+w2KhIBsVXSOQuGExPyw3m+fCAgbi4yy7+wdB0otTrgxHDfv6C5IA 0L4aL6hfZFgpP7GjBP6lzqglGyoO0kcHduAGSCBKLuZqJ0JNOldpz1VWR6D+HeLKffvi oJK1NVpxvl0wMw6eOGsxL+73pK3rOFLQVqCqb9AJAxQwSnoCVwivmjb1cH+MwYCBQKH0 uePQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=Y1zHnBMWcZpPAtO0fjOVz/1p/S73L9ZQpg2IYbOcJtY=; fh=FLKBA2ktXPIKbYU33X6z9OJd0Q9yBkAp7mwtYJaIcrc=; b=nnErrc5b9i+VTjzWTsJk1gcKsUFrLvmzGHzMEKhBW0bJmBpihVaer4NAXj3ggAXtrD ICufT48sjEFBzWEWOBejQ94ow0SWX4lrFpogNE8US+nnSHVy+hY63gSxBRfyaAP2xaow XE3oiYhVcp9LUdx80VvtN7wW5sRZf4cFRHUwuQxjXF4cbpj99Exnhx29dAzZ4geIHNkl Wt6FXqL8wSOIda7/EORJ33VqzjAGn+msZ+FCtxsia0jRzdzoY/gYdRx0GiCceFx3PydW BwrGgsqUey0AFY9AM6KPMj2c31Ob9Uw9NVFUnJ1AXboEaW8oJ0HUUzlMVO5hi9bfEhMC RXAw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="G8WN/E9P"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fh15-20020a05622a588f00b004236de0b3adsi11881266qtb.511.2023.12.04.23.02.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:02:35 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="G8WN/E9P"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4D9138312E4 for ; Tue, 5 Dec 2023 07:02:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id E81333861012 for ; Tue, 5 Dec 2023 07:01:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E81333861012 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 E81333861012 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701759726; cv=none; b=D74d5xMB1zMpdTQTUGe528BXZb8Hhjr+oZrZc4jy5BHFeqyDcoWP4QQ+hMj4/6NV20YnUYL/zRi0P/f+2gkW5kfJpZWiKjpNECjN2UVGrRjAHqtYsb9UwKu2MoFtgxm45Lp8NaHXBVBs46U+2xhbvYd0UmJJ93zaK+gJxBL2EFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701759726; c=relaxed/simple; bh=/tFJJXAHjTKfLgZqPw+IUkeZ94KFnVlHQuVLxC69ZEg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=RLOBj8F0ki7r6Id5LXCyr5ctgkclp5SJLuetaBotL9bqPVyC8HoQ+VRZ/7TqOzEzXy7gJ/o0k+a1tIJxtpTKoLxkOap3jS93P/O7ATYHqnuXyAC3CsaxTiJgEqmMkoLYN2kSCWbrTh5gLyVVDQAlo4XAS2IgH/thymorT5jLqBg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-5a0dc313058so739783a12.0 for ; Mon, 04 Dec 2023 23:01:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701759718; x=1702364518; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y1zHnBMWcZpPAtO0fjOVz/1p/S73L9ZQpg2IYbOcJtY=; b=G8WN/E9PIKLxS9cZCxWZ8vkX75ryi+x44XoqvfVp54B9z1EZ4xdKgwI3e4ikBAhccJ Us2J+7GeTpwGMsTXdgjD7MzisrdUUDnrh/2j84O7Rp+mi9gSyequAQ7nd9IgiAanf169 CdDqjbufFqcYmz2fB7K0ou2XKE5xwYieqWSgUY5JEUmfAjep+6gveb7SdB8KJyXlrD3X LDNwvKE2sVzBBwwg0R1kIztpeMTXZisGft2NqT+Bt90iE3CuHJDN5yRnowZEsC1dmNh3 Dnb84V9eJuARvCHgoLEdvozHW5fPLPLuwLjEESwnlxWSCHna31heuWJ4f7gtfk8uJ00i tYgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701759718; x=1702364518; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y1zHnBMWcZpPAtO0fjOVz/1p/S73L9ZQpg2IYbOcJtY=; b=ZSqL9jGn1zC6G4UCvRuzutY5Pj2FiV9MCai6OP0wchru72GOv/pWHxN83nZwWb7FtM QkZltJyrnjIuSEg4pQGA7VSxtMO9Ltzj/sG/JlZUDlcPWceBvSIaWG35cRT7+4hVH4km bf6zK8THI6UNXvLd1fMP+gcd8Q2igLT6fgo2tU9KoTbZsO595rtyX8QVo3V1F58dr121 Inj+ROHc7RHtERLWLJrgLFpoFpfQ/uHvsej3+aogAHa5o17y9r2VeYjFB56d0ZTrPmDr 2Xh/MLcO8HI2QRLMkQhAg/vLS3s56Xv+3lEKuhiUhLTpQXAs3PU8aVHYHkvqulDa0o4G im9A== X-Gm-Message-State: AOJu0YyAVMQd5Lv6Nft9WnxmwBdXFO5vFcBdNSEv+ITDvvjXajsZIfb4 zsKfQ0OOwCybR0t8MGCwNneG+cuSWgPSVaW9 X-Received: by 2002:a05:6a20:3d1e:b0:18b:1f5d:b105 with SMTP id y30-20020a056a203d1e00b0018b1f5db105mr42705201pzi.6.1701759717693; Mon, 04 Dec 2023 23:01:57 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id r7-20020aa79ec7000000b006cdd00f91fdsm5090085pfq.185.2023.12.04.23.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:01:56 -0800 (PST) From: Tatsuyuki Ishi To: ishitatsuyuki@gmail.com Cc: gcc-patches@gcc.gnu.org, rui314@gmail.com, ruiu@bluewhale.systems, kito.cheng@gmail.com, jeffreyalaw@gmail.com Subject: [PATCH v4] RISC-V: Implement TLS Descriptors. Date: Tue, 5 Dec 2023 16:01:52 +0900 Message-ID: <20231205070152.38360-1-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20230817181308.122802-2-ishitatsuyuki@gmail.com> References: <20230817181308.122802-2-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774501063388314626 X-GMAIL-MSGID: 1784424438138270877 This implements TLS Descriptors (TLSDESC) as specified in [1]. The 4-instruction sequence is implemented as a single RTX insn for simplicity, but this can be revisited later if instruction scheduling or more flexible RA is desired. 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. * doc/install.texi: Document --with-tls for RISC-V. * doc/invoke.texi: Document -mtls-dialect for RISC-V. * testsuite/gcc.target/riscv/tls_1.x: Add TLSDESC GD test case. * testsuite/gcc.target/riscv/tlsdesc.c: Same as above. Reviewed-by: Fangrui Song --- No regression in gcc tests for rv64gc, tested alongside the binutils and glibc implementation. Tested with --with_tls=desc. v2: Add with_tls configuration option, and a few readability improvements. Added Changelog. v3: Add documentation per Kito's suggestion. Fix minor issues pointed out by Kito and Jeff. Thanks Kito Cheng and Jeff Law for review. v4: Add TLSDESC GD assembly test. Rebase on top of trunk. gcc/config.gcc | 15 ++++++++++++++- gcc/config/riscv/riscv-opts.h | 6 ++++++ gcc/config/riscv/riscv-protos.h | 5 +++-- gcc/config/riscv/riscv.cc | 24 ++++++++++++++++++++---- gcc/config/riscv/riscv.h | 9 +++++++-- gcc/config/riscv/riscv.md | 20 +++++++++++++++++++- gcc/config/riscv/riscv.opt | 14 ++++++++++++++ gcc/doc/install.texi | 3 +++ gcc/doc/invoke.texi | 13 ++++++++++++- gcc/testsuite/gcc.target/riscv/tls_1.x | 5 +++++ gcc/testsuite/gcc.target/riscv/tlsdesc.c | 12 ++++++++++++ 11 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/tls_1.x create mode 100644 gcc/testsuite/gcc.target/riscv/tlsdesc.c diff --git a/gcc/config.gcc b/gcc/config.gcc index 748430194f3..8bb22e9f590 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -2490,6 +2490,7 @@ riscv*-*-linux*) # Force .init_array support. The configure script cannot always # automatically detect that GAS supports it, yet we require it. gcc_cv_initfini_array=yes + with_tls=${with_tls:-trad} ;; riscv*-*-elf* | riscv*-*-rtems*) tm_file="elfos.h newlib-stdint.h ${tm_file} riscv/elf.h" @@ -2532,6 +2533,7 @@ riscv*-*-freebsd*) # Force .init_array support. The configure script cannot always # automatically detect that GAS supports it, yet we require it. gcc_cv_initfini_array=yes + with_tls=${with_tls:-trad} ;; loongarch*-*-linux*) @@ -4658,7 +4660,7 @@ case "${target}" in ;; riscv*-*-*) - supported_defaults="abi arch tune riscv_attribute isa_spec" + supported_defaults="abi arch tune riscv_attribute isa_spec tls" case "${target}" in riscv-* | riscv32*) xlen=32 ;; @@ -4788,6 +4790,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 # Handle --with-multilib-list. if test "x${with_multilib_list}" != xdefault; then diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h index 30efebbf07b..b2551968be0 100644 --- a/gcc/config/riscv/riscv-opts.h +++ b/gcc/config/riscv/riscv-opts.h @@ -138,4 +138,10 @@ enum stringop_strategy_enum { #define TARGET_MAX_LMUL \ (int) (riscv_autovec_lmul == RVV_DYNAMIC ? RVV_M8 : riscv_autovec_lmul) +/* TLS types. */ +enum riscv_tls_type { + TLS_TRADITIONAL, + TLS_DESCRIPTORS +}; + #endif /* ! GCC_RISCV_OPTS_H */ diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index 695ee24ad6f..f0d8f88dad7 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -33,9 +33,10 @@ enum riscv_symbol_type { SYMBOL_TLS, SYMBOL_TLS_LE, SYMBOL_TLS_IE, - SYMBOL_TLS_GD + SYMBOL_TLS_GD, + SYMBOL_TLSDESC, }; -#define NUM_SYMBOL_TYPES (SYMBOL_TLS_GD + 1) +#define NUM_SYMBOL_TYPES (SYMBOL_TLSDESC + 1) /* Classifies an address. diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 3f111fa0393..639a77922d9 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -892,6 +892,7 @@ static int riscv_symbol_insns (enum riscv_symbol_type type) case SYMBOL_ABSOLUTE: return 2; /* LUI + the reference. */ case SYMBOL_PCREL: return 2; /* AUIPC + the reference. */ case SYMBOL_TLS_LE: return 3; /* LUI + ADD TP + the reference. */ + case SYMBOL_TLSDESC: return 6; /* 4-instruction call + ADD TP + the reference. */ case SYMBOL_GOT_DISP: return 3; /* AUIPC + LD GOT + the reference. */ default: gcc_unreachable (); } @@ -1996,7 +1997,7 @@ riscv_call_tls_get_addr (rtx sym, rtx result) static rtx riscv_legitimize_tls_address (rtx loc) { - rtx dest, tp, tmp; + rtx dest, tp, tmp, a0; enum tls_model model = SYMBOL_REF_TLS_MODEL (loc); #if 0 @@ -2012,9 +2013,24 @@ riscv_legitimize_tls_address (rtx loc) /* Rely on section anchors for the optimization that LDM TLS provides. The anchor's address is loaded with GD TLS. */ case TLS_MODEL_GLOBAL_DYNAMIC: - tmp = gen_rtx_REG (Pmode, GP_RETURN); - dest = gen_reg_rtx (Pmode); - emit_libcall_block (riscv_call_tls_get_addr (loc, tmp), dest, tmp, loc); + if (TARGET_TLSDESC) + { + static unsigned seqno; + tp = gen_rtx_REG (Pmode, THREAD_POINTER_REGNUM); + a0 = gen_rtx_REG (Pmode, GP_ARG_FIRST); + dest = gen_reg_rtx (Pmode); + + emit_insn (gen_tlsdesc (Pmode, loc, GEN_INT (seqno))); + emit_insn (gen_add3_insn (dest, a0, tp)); + seqno++; + } + else + { + tmp = gen_rtx_REG (Pmode, GP_RETURN); + dest = gen_reg_rtx (Pmode); + emit_libcall_block (riscv_call_tls_get_addr (loc, tmp), dest, tmp, + loc); + } break; case TLS_MODEL_INITIAL_EXEC: diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index 6df9ec73c5e..5eb08c21cf4 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -62,6 +62,7 @@ extern const char *riscv_multi_lib_check (int argc, const char **argv); --with-abi is ignored if -mabi is specified. --with-tune is ignored if -mtune or -mcpu is specified. --with-isa-spec is ignored if -misa-spec is specified. + --with-tls is ignored if -mtls-dialect is specified. But using default -march/-mtune value if -mcpu don't have valid option. */ #define OPTION_DEFAULT_SPECS \ @@ -71,8 +72,9 @@ extern const char *riscv_multi_lib_check (int argc, const char **argv); {"arch", "%{!march=*:" \ " %{!mcpu=*:-march=%(VALUE)}" \ " %{mcpu=*:%:riscv_expand_arch_from_cpu(%* %(VALUE))}}" }, \ - {"abi", "%{!mabi=*:-mabi=%(VALUE)}" }, \ - {"isa_spec", "%{!misa-spec=*:-misa-spec=%(VALUE)}" }, \ + {"abi", "%{!mabi=*:-mabi=%(VALUE)}" }, \ + {"isa_spec", "%{!misa-spec=*:-misa-spec=%(VALUE)}" }, \ + {"tls", "%{!mtls-dialect=*:-mtls-dialect=%(VALUE)}"}, \ #ifdef IN_LIBGCC2 #undef TARGET_64BIT @@ -1215,4 +1217,7 @@ extern void riscv_remove_unneeded_save_restore_calls (void); #define HAVE_POST_MODIFY_DISP TARGET_XTHEADMEMIDX #define HAVE_PRE_MODIFY_DISP TARGET_XTHEADMEMIDX +/* Check TLS Descriptors mechanism is selected. */ +#define TARGET_TLSDESC (riscv_tls_dialect == TLS_DESCRIPTORS) + #endif /* ! GCC_RISCV_H */ diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index a98918dfd43..c3676d751df 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -47,7 +47,7 @@ UNSPEC_TLS_LE UNSPEC_TLS_IE UNSPEC_TLS_GD - + UNSPEC_TLSDESC ;; High part of PC-relative address. UNSPEC_AUIPC @@ -2017,6 +2017,24 @@ (set_attr "type" "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:P 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" "")]) + (define_insn "auipc" [(set (match_operand:P 0 "register_operand" "=r") (unspec:P diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index 59ce7106ecf..8de2e8628d8 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -556,3 +556,17 @@ Enum(stringop_strategy) String(vector) Value(STRATEGY_VECTOR) mstringop-strategy= Target RejectNegative Joined Enum(stringop_strategy) Var(stringop_strategy) Init(STRATEGY_AUTO) Specify stringop expansion strategy. + +Enum +Name(tls_type) Type(enum riscv_tls_type) +The possible TLS dialects: + +EnumValue +Enum(tls_type) String(trad) Value(TLS_TRADITIONAL) + +EnumValue +Enum(tls_type) String(desc) Value(TLS_DESCRIPTORS) + +mtls-dialect= +Target RejectNegative Joined Enum(tls_type) Var(riscv_tls_dialect) Init(TLS_TRADITIONAL) Save +Specify TLS dialect. diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index c1128d9274c..3b549ab62da 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -1184,6 +1184,9 @@ Specify the default TLS dialect, for systems were there is a choice. For ARM targets, possible values for @var{dialect} are @code{gnu} or @code{gnu2}, which select between the original GNU dialect and the GNU TLS descriptor-based dialect. +For RISC-V targets, possible values for @var{dialect} are @code{trad} or +@code{desc}, which select between the traditional GNU dialect and the GNU TLS +descriptor-based dialect. @item --enable-multiarch Specify whether to enable or disable multiarch support. The default is diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 681e3f3f466..62c8bf9061b 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1252,7 +1252,8 @@ See RS/6000 and PowerPC Options. -minline-atomics -mno-inline-atomics -minline-strlen -mno-inline-strlen -minline-strcmp -mno-inline-strcmp --minline-strncmp -mno-inline-strncmp} +-minline-strncmp -mno-inline-strncmp +-mtls-dialect=desc -mtls-dialect=trad} @emph{RL78 Options} @gccoptlist{-msim -mmul=none -mmul=g13 -mmul=g14 -mallregs @@ -29988,6 +29989,16 @@ which register to use as base register for reading the canary, and from what offset from that base register. There is no default register or offset as this is entirely for use within the Linux kernel. + +@opindex mtls-dialect=desc +@item -mtls-dialect=desc +Use TLS descriptors as the thread-local storage mechanism for dynamic accesses +of TLS variables. + +@opindex mtls-dialect=trad +@item -mtls-dialect=trad +Use traditional TLS as the thread-local storage mechanism for dynamic accesses +of TLS variables. This is the default. @end table @node RL78 Options diff --git a/gcc/testsuite/gcc.target/riscv/tls_1.x b/gcc/testsuite/gcc.target/riscv/tls_1.x new file mode 100644 index 00000000000..cf334ef55ed --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/tls_1.x @@ -0,0 +1,5 @@ +extern __thread unsigned gd; + +unsigned get() { + return gd; +} diff --git a/gcc/testsuite/gcc.target/riscv/tlsdesc.c b/gcc/testsuite/gcc.target/riscv/tlsdesc.c new file mode 100644 index 00000000000..f9ac9fe0d6d --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/tlsdesc.c @@ -0,0 +1,12 @@ +/* { dg-require-effective-target tls_native } */ +/* { dg-options "-O2 -fpic -mtls-dialect=desc --save-temps" } */ +/* { dg-require-effective-target fpic } */ + +#include "tls_1.x" + +/* { dg-final { scan-assembler-times "auipc\t\[a-x0-9\]+,%tlsdesc_hi" 1 } } */ +/* { dg-final { scan-assembler-times "lw\t\[a-x0-9\]+,%tlsdesc_load_lo" 1 { target { rv32 } } } } */ +/* { dg-final { scan-assembler-times "ld\t\[a-x0-9\]+,%tlsdesc_load_lo" 1 { target { rv64 } } } }*/ +/* { dg-final { scan-assembler-times "addi\ta0,\[a-x0-9\]+,%tlsdesc_add_lo" 1 } } */ +/* { dg-final { scan-assembler-times "jalr\tt0,\[a-x0-9\]+,%tlsdesc_call" 1 } } */ +/* { dg-final { cleanup-saved-temps } } */