From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id E598E3858D28 for ; Mon, 8 Apr 2024 14:32:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E598E3858D28 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 E598E3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712586725; cv=none; b=IvUaSyxmibMpwcgKSSUQlMEf7OmHMFafBCASS4mq8fx4swD8VYhLohHt4OEnYofub3wHXdVlh2wFzfs2zTM0kPfaZdch/NkdfJM6qT2gRcww4UsZw7gSOh2ZONMeGozeTf6CBBWP/oMNq5zRxtSDQqaLkooxYXjPevL8OlfSliw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712586725; c=relaxed/simple; bh=dSE4bnMTXVddRN2dDuZBRw8x7g8+29jut6Qw3wnTcJU=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=A28NCzpLinWlQtfbniCrJYvwivAvN+MLFd33RS+pJ3ZpjO7vmFZoDYsFtd4zOivxF6kDUQMQijr9ynpffRslXtsizq25afjRam58Ycv+Hbw4bbjTXCL2CezWzJ1B9NlHTYYOFKTZpGfYoTAMMoW3JEjANA8ZG9SySlhROsyUBoI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a51addddbd4so307058966b.0 for ; Mon, 08 Apr 2024 07:32:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712586720; x=1713191520; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mMWWBEYDgpTzxO7Yn8JK4QtYG7dOvV1T7Uy4YIne/lw=; b=TV5yG7RxPoXG1XUckw4008KzlgNz3w7yUKx7iTjNTHMupERSd/0zWG0OCquXGSusKl hr56AV3HPEbUc1Ttzjg6/QD/Z+9BaUlTpGAX83pSNh9pY7XDFfftD0TisQgTB4CHgBoL Zek+TK92ZOfCeXqBjbzIC+EQbLAbZLGSZHGqlGUiOp5PfOO9bw9D5MRdMdsYvzcK5tWj tYG0Be4Tf/F4s+KE/R5eW67FrLDldiVS7kQlhcaIYDdTaYy1g/m/UkB86TxSM+Cf7CyH sy2aIDaM+sNUp7HnbsnJXIn/h8L7qyg6MEEHpS2ZJeEiFkHbl0sEOobWnJXP0mPLFchs ac9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712586720; x=1713191520; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mMWWBEYDgpTzxO7Yn8JK4QtYG7dOvV1T7Uy4YIne/lw=; b=K3XzphBmi9HLrr52/T5CjtWJxiTMaJzuelS7IFx4bn2DrGOYH2VWYGqP0GX2cvt3qT 1w9Hb7y6V5uE4W0HFNuXz4etRHu0bWc/50nfdCbLZxb9OeRwH47ZmhW4SNj3ZSKpvyRx jptjSHaPEDCHm0BFSEZYNUyJidGOKVcYi27hwY3hEOBEL1bWZGI0V1ExESd0QQis7eEF 8lEh6pecngd9poQdofsldv+J0lWf2G+q9goRqsAixgyoiyILMKRPcgGMyyEUKRQzFvDo e7YbgpQ8k8mNYlCyjQ1YlGwozfN0hVGefaUA1yzmG+RiTTxu9l5MChWvtYGC+P4XRAQ0 ooNA== X-Gm-Message-State: AOJu0YxUksQwp59VgnIhmLW8N8DuEa8DN7UTRJQY1hsZTWb8+H/vzrpA 8dzYFuKNdM3gidlktWcZ4GpDLSdP4aIeofPOKAnoXU6fHs1YqNn/C0EJ3lUUjVdMIpKbBlUNNnB +6TeYihyCvN2ojgl+LjVHEFiZlf4MTTLPgKz7NQ== X-Google-Smtp-Source: AGHT+IERBd/Jk47e9Pzi0hW6oxP9Th+FpRpt/cZh7oIV7PKuJbzbK/8pg5+YBwmboFuXYb6sjBTXTUTD2gZwZm4jN50= X-Received: by 2002:a17:907:d92:b0:a51:c1e0:2ba9 with SMTP id go18-20020a1709070d9200b00a51c1e02ba9mr4846341ejc.11.1712586720079; Mon, 08 Apr 2024 07:32:00 -0700 (PDT) MIME-Version: 1.0 References: <20230817181308.122802-2-ishitatsuyuki@gmail.com> <20240329055239.29719-1-ishitatsuyuki@gmail.com> In-Reply-To: From: Kito Cheng Date: Mon, 8 Apr 2024 22:31:48 +0800 Message-ID: Subject: Re: [PATCH v5] RISC-V: Implement TLS Descriptors. To: Tatsuyuki Ishi Cc: gcc-patches@gcc.gnu.org, rui314@gmail.com, ruiu@bluewhale.systems, jeffreyalaw@gmail.com, Palmer Dabbelt , Fangrui Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.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,URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Committed to trunk, thanks Tatsuyuki! On Fri, Mar 29, 2024 at 2:32=E2=80=AFPM Kito Cheng w= rote: > > Hi Tatsuyuki: > > Thanks for your hard work and keep updating, the patch set is LGTM, I > plan to commit this next week if no further comments :) > > Hi MaskRay: > > Thanks for your review on the patchset! just put you into the cc list > in case you have few more comments :) > > > On Fri, Mar 29, 2024 at 1:53=E2=80=AFPM Tatsuyuki Ishi wrote: > > > > 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 o= r > > more flexible RA is desired. > > > > The default remains to be the traditional TLS model, but can be configu= red > > with --with-tls=3D{trad,desc}. The choice can be revisited once toolcha= in > > 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 fl= avor. > > * 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 typ= e. > > * 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. > > --- > > No regression in gcc tests for rv32gcv and rv64gcv, tested alongside > > the binutils and glibc implementation. Tested with --with-tls=3Ddesc. > > > > v2: Add with_tls configuration option, and a few readability improvemen= ts. > > 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. > > v5: Trivial rebase on top of trunk. > > > > I have recently addressed relaxation concerns on binutils and RVV > > register save/restore on glibc, so I'm sending out a trivial rebase > > with the hope that the full set can be merged soon. > > > > 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 17873ac2103..1a5870672d2 100644 > > --- a/gcc/config.gcc > > +++ b/gcc/config.gcc > > @@ -2492,6 +2492,7 @@ riscv*-*-linux*) > > # Force .init_array support. The configure script cannot alway= s > > # automatically detect that GAS supports it, yet we require it. > > gcc_cv_initfini_array=3Dyes > > + with_tls=3D${with_tls:-trad} > > ;; > > riscv*-*-elf* | riscv*-*-rtems*) > > tm_file=3D"elfos.h newlib-stdint.h ${tm_file} riscv/elf.h" > > @@ -2534,6 +2535,7 @@ riscv*-*-freebsd*) > > # Force .init_array support. The configure script cannot alway= s > > # automatically detect that GAS supports it, yet we require it. > > gcc_cv_initfini_array=3Dyes > > + with_tls=3D${with_tls:-trad} > > ;; > > > > loongarch*-*-linux*) > > @@ -4671,7 +4673,7 @@ case "${target}" in > > ;; > > > > riscv*-*-*) > > - supported_defaults=3D"abi arch tune riscv_attribute isa= _spec" > > + supported_defaults=3D"abi arch tune riscv_attribute isa= _spec tls" > > > > case "${target}" in > > riscv-* | riscv32*) xlen=3D32 ;; > > @@ -4801,6 +4803,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 > > > > # Handle --with-multilib-list. > > if test "x${with_multilib_list}" !=3D xdefault; then > > diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opt= s.h > > index 392b9169240..1b2dd5757a8 100644 > > --- a/gcc/config/riscv/riscv-opts.h > > +++ b/gcc/config/riscv/riscv-opts.h > > @@ -154,4 +154,10 @@ enum rvv_vector_bits_enum { > > #define TARGET_MAX_LMUL = \ > > (int) (rvv_max_lmul =3D=3D RVV_DYNAMIC ? RVV_M8 : rvv_max_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-p= rotos.h > > index b8735593805..066a5a5a7cc 100644 > > --- a/gcc/config/riscv/riscv-protos.h > > +++ b/gcc/config/riscv/riscv-protos.h > > @@ -34,9 +34,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 fe9976bfffe..deac3e4e9e3 100644 > > --- a/gcc/config/riscv/riscv.cc > > +++ b/gcc/config/riscv/riscv.cc > > @@ -1072,6 +1072,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 + th= e reference. */ > > case SYMBOL_GOT_DISP: return 3; /* AUIPC + LD GOT + the reference.= */ > > case SYMBOL_FORCE_TO_MEM: return 3; /* AUIPC + LD + the reference.= */ > > default: gcc_unreachable (); > > @@ -2220,7 +2221,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 =3D SYMBOL_REF_TLS_MODEL (loc); > > > > #if 0 > > @@ -2236,9 +2237,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 =3D gen_rtx_REG (Pmode, GP_RETURN); > > - dest =3D gen_reg_rtx (Pmode); > > - emit_libcall_block (riscv_call_tls_get_addr (loc, tmp), dest, tm= p, loc); > > + if (TARGET_TLSDESC) > > + { > > + static unsigned seqno; > > + tp =3D gen_rtx_REG (Pmode, THREAD_POINTER_REGNUM); > > + a0 =3D gen_rtx_REG (Pmode, GP_ARG_FIRST); > > + dest =3D gen_reg_rtx (Pmode); > > + > > + emit_insn (gen_tlsdesc (Pmode, loc, GEN_INT (seqno))); > > + emit_insn (gen_add3_insn (dest, a0, tp)); > > + seqno++; > > + } > > + else > > + { > > + tmp =3D gen_rtx_REG (Pmode, GP_RETURN); > > + dest =3D 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 da089a03e9d..10ad4aedd70 100644 > > --- a/gcc/config/riscv/riscv.h > > +++ b/gcc/config/riscv/riscv.h > > @@ -64,6 +64,7 @@ extern const char *riscv_arch_help (int argc, const c= har **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 opt= ion. */ > > #define OPTION_DEFAULT_SPECS \ > > @@ -73,8 +74,9 @@ extern const char *riscv_arch_help (int argc, const c= har **argv); > > {"arch", "%{!march=3D*:" = \ > > " %{!mcpu=3D*:-march=3D%(VALUE)}" = \ > > " %{mcpu=3D*:%:riscv_expand_arch_from_cpu(%* %(VALUE))}}" }= , \ > > - {"abi", "%{!mabi=3D*:-mabi=3D%(VALUE)}" }, \ > > - {"isa_spec", "%{!misa-spec=3D*:-misa-spec=3D%(VALUE)}" }, \ > > + {"abi", "%{!mabi=3D*:-mabi=3D%(VALUE)}" }, = \ > > + {"isa_spec", "%{!misa-spec=3D*:-misa-spec=3D%(VALUE)}" }, = \ > > + {"tls", "%{!mtls-dialect=3D*:-mtls-dialect=3D%(VALUE)}"}, = \ > > > > #ifdef IN_LIBGCC2 > > #undef TARGET_64BIT > > @@ -1228,4 +1230,7 @@ extern void riscv_remove_unneeded_save_restore_ca= lls (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 =3D=3D TLS_DESCRIPTORS) > > + > > #endif /* ! GCC_RISCV_H */ > > diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md > > index 0346cc3859d..c2b4323c53a 100644 > > --- a/gcc/config/riscv/riscv.md > > +++ b/gcc/config/riscv/riscv.md > > @@ -48,7 +48,7 @@ > > UNSPEC_TLS_LE > > UNSPEC_TLS_IE > > UNSPEC_TLS_GD > > - > > + UNSPEC_TLSDESC > > ;; High part of PC-relative address. > > UNSPEC_AUIPC > > > > @@ -2089,6 +2089,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" "=3Dr") > > (unspec:P > > diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt > > index 7d625af02d5..8da0764eb4b 100644 > > --- a/gcc/config/riscv/riscv.opt > > +++ b/gcc/config/riscv/riscv.opt > > @@ -606,3 +606,17 @@ Enum(rvv_vector_bits) String(zvl) Value(RVV_VECTOR= _BITS_ZVL) > > mrvv-vector-bits=3D > > Target RejectNegative Joined Enum(rvv_vector_bits) Var(rvv_vector_bits= ) Init(RVV_VECTOR_BITS_SCALABLE) > > -mrvv-vector-bits=3D Set the kind of bits for an RVV vecto= r register. > > + > > +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=3D > > +Target RejectNegative Joined Enum(tls_type) Var(riscv_tls_dialect) Ini= t(TLS_TRADITIONAL) Save > > +Specify TLS dialect. > > diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi > > index 269fe7ec870..120bb045f4d 100644 > > --- a/gcc/doc/install.texi > > +++ b/gcc/doc/install.texi > > @@ -1187,6 +1187,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 i= s > > diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi > > index d09074e13de..e4112bbe61e 100644 > > --- a/gcc/doc/invoke.texi > > +++ b/gcc/doc/invoke.texi > > @@ -1262,7 +1262,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=3Ddesc -mtls-dialect=3Dtrad} > > > > @emph{RL78 Options} > > @gccoptlist{-msim -mmul=3Dnone -mmul=3Dg13 -mmul=3Dg14 -mallregs > > @@ -30975,6 +30976,16 @@ which register to use as base register for rea= ding 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=3Ddesc > > +@item -mtls-dialect=3Ddesc > > +Use TLS descriptors as the thread-local storage mechanism for dynamic = accesses > > +of TLS variables. > > + > > +@opindex mtls-dialect=3Dtrad > > +@item -mtls-dialect=3Dtrad > > +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/g= cc.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=3Ddesc --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_ad= d_lo" 1 } } */ > > +/* { dg-final { scan-assembler-times "jalr\tt0,\[a-x0-9\]+,%tlsdesc_ca= ll" 1 } } */ > > +/* { dg-final { cleanup-saved-temps } } */ > > -- > > 2.44.0 > >