From patchwork Thu Sep 14 08:40:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 75955 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 29E87385CC8F for ; Thu, 14 Sep 2023 08:42:09 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id B954C3858C2B for ; Thu, 14 Sep 2023 08:40:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B954C3858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1bf11a7cf9fso1048985ad.1 for ; Thu, 14 Sep 2023 01:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694680845; x=1695285645; darn=sourceware.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=LZUY8LgZfIP/hxZK+8oL5Jv7eakrZlaR2pRXdCIa3f8=; b=LA0Mp12e2x1BN9GgJHhfG0zoIrQkFFDcS2jkmShCC6K2Vs4b15+U2Z5heosb3SPejg IpXXn/BAFIBJwFCiJGNdxSfyItPyS1KdffsN4bVWE4S0pXQ7UL0zGKEZub5cHYLLe+gt DokHsNVnCj9dwW0nveBaf+pdtWlXMBsX06SzRa1flYqehJxUwWNbhYJccA6MSZo+kpkd k0vMi4+LG40DFBjdWlZhdOGaq2bva+Hep0ik1HDO5HheTjj4W9GcHHv6/w3OjvVrVohs dqK+SQc9RlDq4aYwbkl5t8GLVjBtkKXtY5cqsXWa6/zDqEnC7cTKdMH1S8IVzi6TTc3k lGgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694680845; x=1695285645; 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=LZUY8LgZfIP/hxZK+8oL5Jv7eakrZlaR2pRXdCIa3f8=; b=pLVLwIhPgDPiuLK3tHlbXdIs7ueVCODzAudF8b1RD3h4hEG6AYWcVH2WmPOXETphHb 81mPs7IJzRn/LGg47tenR5gYzRfYfsIJnF1zytbRkhT1gxjnuubPZBuIKVaaeSkJDX2D ykBiRqGG4DN/dPlyuIcqaVJ0dFR+paEAZgxxNA7iIx0S97Fn5rbLb4umjAdzW28oWjCz j8LetuWyEpcNi9VO3dz8h6/nohK4lkgQnF2+KPof+Y6X+hlUuaReQnGkx3ZIJHgm+3Fg Ic+fTCEs0oMCF0rm2PtAu0YKt0rxR5vMcMbmWxphzgdtsys2FdAx3LE6YG6+9clB1pc+ rh4A== X-Gm-Message-State: AOJu0YzPPr8AxchBaHhN5Ttg0aYzhSXxwu10c94tQhu0dYKIf9DaKRZR bEEJQnp719N16BoakH7S6wI= X-Google-Smtp-Source: AGHT+IFJlAX4ZCVsD2pr4uOXdDZ8iKAytpmqzxtT8xpOZ4zvCWAnXVnUkRKB/Tm0JRT8qevjnZUdHQ== X-Received: by 2002:a17:902:ecc3:b0:1b3:d8ac:8db3 with SMTP id a3-20020a170902ecc300b001b3d8ac8db3mr5270538plh.6.1694680844741; Thu, 14 Sep 2023 01:40:44 -0700 (PDT) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id a5-20020a170902ecc500b001c1f4edfb9csm1006183plh.173.2023.09.14.01.40.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 01:40:44 -0700 (PDT) From: Tatsuyuki Ishi To: ishitatsuyuki@gmail.com Cc: libc-alpha@sourceware.org, rui314@gmail.com, ruiu@bluewhale.systems, schwab@linux-m68k.org, adhemerval.zanella@linaro.org, andrew@sifive.com Subject: [PATCH v4 1/3] RISC-V: Add include guard for dl-tls.h. Date: Thu, 14 Sep 2023 17:40:31 +0900 Message-ID: <20230914084033.222120-2-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914084033.222120-1-ishitatsuyuki@gmail.com> References: <20230817181228.122674-2-ishitatsuyuki@gmail.com> <20230914084033.222120-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org --- sysdeps/riscv/dl-tls.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sysdeps/riscv/dl-tls.h b/sysdeps/riscv/dl-tls.h index 67c8ae639c..f11f335edf 100644 --- a/sysdeps/riscv/dl-tls.h +++ b/sysdeps/riscv/dl-tls.h @@ -16,6 +16,8 @@ License along with the GNU C Library. If not, see . */ +#ifndef _DL_TLS_H +# define _DL_TLS_H 1 /* Type used for the representation of TLS information in the GOT. */ typedef struct @@ -46,3 +48,5 @@ extern void *__tls_get_addr (tls_index *ti); /* Value used for dtv entries for which the allocation is delayed. */ #define TLS_DTV_UNALLOCATED ((void *) -1l) + +#endif /* _DL_TLS_H */ From patchwork Thu Sep 14 08:40:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 75956 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1CFD385AC09 for ; Thu, 14 Sep 2023 08:42:59 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 8061A3857031 for ; Thu, 14 Sep 2023 08:40:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8061A3857031 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6bf3850bcd2so44775a34.1 for ; Thu, 14 Sep 2023 01:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694680848; x=1695285648; darn=sourceware.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=Ks5++2ava2C8GY0Xtuu2vGQC97tG7v2vx78WzqIxzIc=; b=add79Ih3JCsJ9XyWWpUFsK2iENVy/Xa5IFu7xyYEijj8p437M2TGoo8Pn+Cc9fk/Hj C8tEDRF6cYK3PvYO4Fi7UxRpUBWI29i691qzLtgKspuwgXuIawttMxLd06c7JAbTFMgO pXw18sSiZDMKnsvVDc4o0iNhmNzhDA1iMQURYisiLggs1RN4T/KHFeFOaj27AMui9Qow X6psSTwhc+muqv3xb82TzC/NOqkmaCUZ0qMf2/rCBHd+ZjEsVZpcS5axsu+pOB43kZ0l Mkrfk8enIYJkIwNnNTe267rDcnzcWItyMCbLg5vj2nc9KXimXJhTDn6ccZalD3xaKuF5 5tKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694680848; x=1695285648; 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=Ks5++2ava2C8GY0Xtuu2vGQC97tG7v2vx78WzqIxzIc=; b=JQxeiXW0r6N0tAQ8MqRWD8pk5R/sLabEdx4Ue211TygHYymt9UKY2aEFcZQH9nROXl 856foqnH3iYezLDtOk6iXYrbIN06H9u/yC+y5TJL48bSKp/OGqVO64lhnKKSwvHVSlZD mAn0rNqxufuH5+oZXZDiL38mzLY0R1v9xg9JsOTpx7JOa9aO63+X6Jea/Dtqh1vGGXx1 JlKB08N+nyvyPeNcE8uoMdLEEe7P4DlAYL1RGRgtoXRTnG6iPuC1dt7VjUw/Xgy+EwtO uUX6uLOR6Yja+MFdY59D/HJ+zFJFL16SjUL0OXRvK+06KtJcrVy7iZBC9wJ7a6tNfBRw 0GVA== X-Gm-Message-State: AOJu0Yx0BYI96FAcFJ0sU4C1DT8Vw3450itKZk37up6i0THZL5J5hyuy 0Yent5kQ9mUV0cu+JdrZUbzSz9MPEv8z2WIH X-Google-Smtp-Source: AGHT+IHRJPnwSdW6pt9sA+NpM99TyHH24jYXEDUbuBz6zod48YkSyk9sBFIhl8ZF+szz3uDtKUEgAA== X-Received: by 2002:a05:6870:468a:b0:1d5:aed5:659f with SMTP id a10-20020a056870468a00b001d5aed5659fmr5763318oap.4.1694680847713; Thu, 14 Sep 2023 01:40:47 -0700 (PDT) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id l9-20020a633e09000000b00563ff7d9c4bsm732896pga.73.2023.09.14.01.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 01:40:47 -0700 (PDT) From: Tatsuyuki Ishi To: ishitatsuyuki@gmail.com Cc: libc-alpha@sourceware.org, rui314@gmail.com, ruiu@bluewhale.systems, schwab@linux-m68k.org, adhemerval.zanella@linaro.org, andrew@sifive.com Subject: [PATCH v4 2/3] RISC-V: Add TLSDESC reloc definitions. Date: Thu, 14 Sep 2023 17:40:32 +0900 Message-ID: <20230914084033.222120-3-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914084033.222120-1-ishitatsuyuki@gmail.com> References: <20230817181228.122674-2-ishitatsuyuki@gmail.com> <20230914084033.222120-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org --- elf/elf.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/elf/elf.h b/elf/elf.h index 9c51073f75..c6247c1bae 100644 --- a/elf/elf.h +++ b/elf/elf.h @@ -3959,6 +3959,7 @@ enum #define R_RISCV_TLS_DTPREL64 9 #define R_RISCV_TLS_TPREL32 10 #define R_RISCV_TLS_TPREL64 11 +#define R_RISCV_TLSDESC 12 #define R_RISCV_BRANCH 16 #define R_RISCV_JAL 17 #define R_RISCV_CALL 18 @@ -4005,6 +4006,10 @@ enum #define R_RISCV_PLT32 59 #define R_RISCV_SET_ULEB128 60 #define R_RISCV_SUB_ULEB128 61 +#define R_RISCV_TLSDESC_HI20 62 +#define R_RISCV_TLSDESC_LOAD_LO12 63 +#define R_RISCV_TLSDESC_ADD_LO12 64 +#define R_RISCV_TLSDESC_CALL 65 #define R_RISCV_NUM 62 From patchwork Thu Sep 14 08:40:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 75957 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C28138560AA for ; Thu, 14 Sep 2023 08:43:44 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 76DC6385697D for ; Thu, 14 Sep 2023 08:40:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76DC6385697D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1c40110d91eso1008935ad.1 for ; Thu, 14 Sep 2023 01:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694680850; x=1695285650; darn=sourceware.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=x/V01im5H3cFQDGUZzJbniuHOj+ucmuqdwmYojQ4rFM=; b=nY7GKMELofgAchkYjzIjUQ9qWHWSI0I/Q0NqSk3KQll/oE42t7URDgW8oCSR1LS6qh iVUS6Uc5aDS6OMhECjvobQZiBUeRY1zHKzTpSWjh72LfDVO/Ntxs95BCkL6AXLBMsPdL LLgMZ0GsTPgoIxHmgS06q6Jg8DsPM/dDOMg9mPBZBEPQEgmeO2fNRo5bFOqcggPIcULv hsdrzoFPZnBqDHm1g5akgO4V8r8GfAzeZ90kEwmH3vq/n1u5nCAN3tmyzVo+ATt5+Q0m REJ+qtuf/Oq6kTZATAsvBtgx7P2spHjjVScVnW80k9qktgdaNzqadUnFeHI+BQHdfvIC BTIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694680850; x=1695285650; 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=x/V01im5H3cFQDGUZzJbniuHOj+ucmuqdwmYojQ4rFM=; b=cnAJefRqS4xtRpjyjPkJhwjG8lbLN7Q7StQJ/skD+GSPHDzK8VMUZcdzI9oR9ZwIIq T4Os/3FQk2dd89EQ+eBpGwYN26pzm+zAM7vQnkTTwHFGF7OzZnnQ4+5IhgiaTAS5a4H/ FZFSheKr3LUNOj4XUYssO+4OocYCJ0+Rerx2fcrGI8u9xOD79/w6Js1WiUAiHKAr9m9b xY8p9Bea+R0/f39qxP1x+rFuGHSu0tYCipF8yGsYTz6qVPyieTBPbGIOFFzaRJ5tY2AP zhgxE2v0ioyQyB7sdZCKuQqLy0NuFW35qgdQtXGzqHnT89dZjGF8qsQssdh3QDkfYA4V S7kQ== X-Gm-Message-State: AOJu0YzD2DEMAVAUyU51GP20t4dAM6dyHVwWstnB1wXS85+yJi3VT2c+ OxrWEXEn/RGNkWl0o6hu7ic= X-Google-Smtp-Source: AGHT+IG62KsPsi8oQZ9S05kiM5FkQQ9C1hGFeGbEpQiz+8Zu55GIklPLmq+l83Xe/pOhrkVQQgv98w== X-Received: by 2002:a17:902:d111:b0:1c4:1cd3:8062 with SMTP id w17-20020a170902d11100b001c41cd38062mr185749plw.2.1694680850294; Thu, 14 Sep 2023 01:40:50 -0700 (PDT) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id l7-20020a170903120700b001b87bedcc6fsm1014002plh.93.2023.09.14.01.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 01:40:49 -0700 (PDT) From: Tatsuyuki Ishi To: ishitatsuyuki@gmail.com Cc: libc-alpha@sourceware.org, rui314@gmail.com, ruiu@bluewhale.systems, schwab@linux-m68k.org, adhemerval.zanella@linaro.org, andrew@sifive.com Subject: [PATCH v4 3/3] RISC-V: Implement TLS Descriptors. Date: Thu, 14 Sep 2023 17:40:33 +0900 Message-ID: <20230914084033.222120-4-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230914084033.222120-1-ishitatsuyuki@gmail.com> References: <20230817181228.122674-2-ishitatsuyuki@gmail.com> <20230914084033.222120-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org This is mostly based off AArch64 implementation, with some adaptations to different TLS DTV offsets and calling conventions. --- sysdeps/riscv/Makefile | 13 ++ sysdeps/riscv/dl-lookupcfg.h | 27 +++ sysdeps/riscv/dl-machine.h | 50 ++++- sysdeps/riscv/dl-tlsdesc.S | 205 ++++++++++++++++++++ sysdeps/riscv/dl-tlsdesc.h | 48 +++++ sysdeps/riscv/linkmap.h | 1 + sysdeps/riscv/tlsdesc.c | 38 ++++ sysdeps/riscv/tlsdesc.sym | 19 ++ sysdeps/unix/sysv/linux/riscv/localplt.data | 2 + 9 files changed, 402 insertions(+), 1 deletion(-) create mode 100644 sysdeps/riscv/dl-lookupcfg.h create mode 100644 sysdeps/riscv/dl-tlsdesc.S create mode 100644 sysdeps/riscv/dl-tlsdesc.h create mode 100644 sysdeps/riscv/tlsdesc.c create mode 100644 sysdeps/riscv/tlsdesc.sym diff --git a/sysdeps/riscv/Makefile b/sysdeps/riscv/Makefile index 8fb10b164f..0fa1664cb1 100644 --- a/sysdeps/riscv/Makefile +++ b/sysdeps/riscv/Makefile @@ -2,6 +2,19 @@ ifeq ($(subdir),misc) sysdep_headers += sys/asm.h endif +ifeq ($(subdir),elf) +sysdep-dl-routines += \ + dl-tlsdesc \ + tlsdesc \ + # routines +endif + +ifeq ($(subdir),csu) +gen-as-const-headers += \ + tlsdesc.sym \ + # gen-as-const-headers +endif + # RISC-V's assembler also needs to know about PIC as it changes the definition # of some assembler macros. ASFLAGS-.os += $(pic-ccflag) diff --git a/sysdeps/riscv/dl-lookupcfg.h b/sysdeps/riscv/dl-lookupcfg.h new file mode 100644 index 0000000000..d75a48f50c --- /dev/null +++ b/sysdeps/riscv/dl-lookupcfg.h @@ -0,0 +1,27 @@ +/* Configuration of lookup functions. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#define DL_UNMAP_IS_SPECIAL + +#include_next + +struct link_map; + +extern void _dl_unmap (struct link_map *map); + +#define DL_UNMAP(map) _dl_unmap (map) diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h index c0c9bd93ad..9f10160dbb 100644 --- a/sysdeps/riscv/dl-machine.h +++ b/sysdeps/riscv/dl-machine.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -50,7 +51,8 @@ || (__WORDSIZE == 32 && (type) == R_RISCV_TLS_TPREL32) \ || (__WORDSIZE == 64 && (type) == R_RISCV_TLS_DTPREL64) \ || (__WORDSIZE == 64 && (type) == R_RISCV_TLS_DTPMOD64) \ - || (__WORDSIZE == 64 && (type) == R_RISCV_TLS_TPREL64))) \ + || (__WORDSIZE == 64 && (type) == R_RISCV_TLS_TPREL64) \ + || ((type) == R_RISCV_TLSDESC))) \ | (ELF_RTYPE_CLASS_COPY * ((type) == R_RISCV_COPY))) /* Return nonzero iff ELF header is compatible with the running host. */ @@ -219,6 +221,34 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[], } break; + case R_RISCV_TLSDESC: + struct tlsdesc *td = (struct tlsdesc *) addr_field; + if (sym == NULL) + { + td->entry = _dl_tlsdesc_undefweak; + td->arg = (void *) reloc->r_addend; + } + else + { +# ifndef SHARED + CHECK_STATIC_TLS (map, sym_map); +# else + if (!TRY_STATIC_TLS (map, sym_map)) + { + td->entry = _dl_tlsdesc_dynamic; + td->arg = _dl_make_tlsdesc_dynamic ( + sym_map, sym->st_value + reloc->r_addend); + } + else +# endif + { + td->entry = _dl_tlsdesc_return; + td->arg + = (void *) (TLS_TPREL_VALUE (sym_map, sym) + reloc->r_addend); + } + } + break; + case R_RISCV_COPY: { if (__glibc_unlikely (sym == NULL)) @@ -289,6 +319,24 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[], else *reloc_addr = map->l_mach.plt; } + else if (__glibc_likely (r_type == R_RISCV_TLSDESC)) + { + const Elf_Symndx symndx = ELFW (R_SYM) (reloc->r_info); + const ElfW (Sym) *symtab = (const void *)D_PTR (map, l_info[DT_SYMTAB]); + const ElfW (Sym) *sym = &symtab[symndx]; + const struct r_found_version *version = NULL; + + if (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL) + { + const ElfW (Half) *vernum = + (const void *)D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]); + version = &map->l_versions[vernum[symndx] & 0x7fff]; + } + + /* Always initialize TLS descriptors completely, because lazy + initialization requires synchronization at every TLS access. */ + elf_machine_rela (map, scope, reloc, sym, version, reloc_addr, skip_ifunc); + } else if (__glibc_unlikely (r_type == R_RISCV_IRELATIVE)) { ElfW(Addr) value = map->l_addr + reloc->r_addend; diff --git a/sysdeps/riscv/dl-tlsdesc.S b/sysdeps/riscv/dl-tlsdesc.S new file mode 100644 index 0000000000..06fe134a38 --- /dev/null +++ b/sysdeps/riscv/dl-tlsdesc.S @@ -0,0 +1,205 @@ +/* Thread-local storage handling in the ELF dynamic linker. + RISC-V version. + Copyright (C) 2023 Free Software Foundation, Inc. + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +#define FRAME_SIZE_FAST (-((-3 * SZREG) & ALMASK)) + +#ifdef __riscv_float_abi_soft +# define FRAME_SIZE_SLOW (-((-12 * SZREG) & ALMASK)) +#else +# define FRAME_SIZE_SLOW (-((-12 * SZREG - 20 * SZFREG) & ALMASK)) +#endif + + .text + + /* Compute the thread pointer offset for symbols in the static + TLS block. The offset is the same for all threads. + Prototype: + _dl_tlsdesc_return (tlsdesc *) ; + */ +ENTRY (_dl_tlsdesc_return) + REG_L a0, TLSDESC_ARG(a0) + jr t0 +END (_dl_tlsdesc_return) + + /* Handler for undefined weak TLS symbols. + Prototype: + _dl_tlsdesc_undefweak (tlsdesc *); + + The second word of the descriptor contains the addend. + Return the addend minus the thread pointer. This ensures + that when the caller adds on the thread pointer it gets back + the addend. */ + +ENTRY (_dl_tlsdesc_undefweak) + REG_L a0, TLSDESC_ARG(a0) + sub a0, a0, tp + jr t0 +END (_dl_tlsdesc_undefweak) + +#ifdef SHARED + /* Handler for dynamic TLS symbols. + Prototype: + _dl_tlsdesc_dynamic (tlsdesc *) ; + + The second word of the descriptor points to a + tlsdesc_dynamic_arg structure. + + Returns the offset between the thread pointer and the + object referenced by the argument. + + unsigned long + _dl_tlsdesc_dynamic (struct tlsdesc *tdp) + { + struct tlsdesc_dynamic_arg *td = tdp->arg; + dtv_t *dtv = *(dtv_t **)((char *)__thread_pointer + TCBHEAD_DTV); + if (__builtin_expect (td->gen_count <= dtv[0].counter + && (dtv[td->tlsinfo.ti_module].pointer.val + != TLS_DTV_UNALLOCATED), + 1)) + return dtv[td->tlsinfo.ti_module].pointer.val + + td->tlsinfo.ti_offset + - __thread_pointer; + + return ___tls_get_addr (&td->tlsinfo) - __thread_pointer; + } + */ + +ENTRY (_dl_tlsdesc_dynamic) + /* Save just enough registers to support fast path, if we fall + into slow path we will save additional registers. */ + add sp, sp, -FRAME_SIZE_FAST + REG_S t0, 0*SZREG(sp) + REG_S t1, 1*SZREG(sp) + REG_S t2, 2*SZREG(sp) + + /* t0 = dtv */ + REG_L t0, TCBHEAD_DTV(tp) + /* a0 = tdp->arg */ + REG_L a0, TLSDESC_ARG(a0) + /* t1 = td->gen_count */ + REG_L t1, TLSDESC_GEN_COUNT(a0) + /* t2 = dtv[0].counter */ + REG_L t2, DTV_COUNTER(t0) + bltu t2, t1, .Lslow + /* t1 = td->tlsinfo.ti_module */ + REG_L t1, TLSDESC_MODID(a0) + slli t1, t1, PTRLOG + 1 /* sizeof(dtv_t) == sizeof(void*) * 2 */ + add t1, t1, t0 + /* t1 = dtv[td->tlsinfo.ti_module].pointer.val */ + REG_L t1, 0(t1) + li t2, TLS_DTV_UNALLOCATED + beq t1, t2, .Lslow + /* t2 = td->tlsinfo.ti_offset */ + REG_L t2, TLSDESC_MODOFF(a0) + add a0, t1, t2 +.Lret: + sub a0, a0, tp + REG_L t0, 0*SZREG(sp) + REG_L t1, 1*SZREG(sp) + REG_L t2, 2*SZREG(sp) + add sp, sp, FRAME_SIZE_FAST + jr t0 +.Lslow: + /* This is the slow path. We need to call __tls_get_addr() which + means we need to save and restore all the register that the + callee will trash. */ + + /* Save the remaining registers that we must treat as caller save. */ + addi sp, sp, -FRAME_SIZE_SLOW + REG_S ra, 0*SZREG(sp) + REG_S a1, 1*SZREG(sp) + REG_S a2, 2*SZREG(sp) + REG_S a3, 3*SZREG(sp) + REG_S a4, 4*SZREG(sp) + REG_S a5, 5*SZREG(sp) + REG_S a6, 6*SZREG(sp) + REG_S a7, 7*SZREG(sp) + REG_S t3, 8*SZREG(sp) + REG_S t4, 9*SZREG(sp) + REG_S t5, 10*SZREG(sp) + REG_S t6, 11*SZREG(sp) +#ifndef __riscv_float_abi_soft + FREG_S ft0, (12*SZREG + 0*SZFREG)(sp) + FREG_S ft1, (12*SZREG + 1*SZFREG)(sp) + FREG_S ft2, (12*SZREG + 2*SZFREG)(sp) + FREG_S ft3, (12*SZREG + 3*SZFREG)(sp) + FREG_S ft4, (12*SZREG + 4*SZFREG)(sp) + FREG_S ft5, (12*SZREG + 5*SZFREG)(sp) + FREG_S ft6, (12*SZREG + 6*SZFREG)(sp) + FREG_S ft7, (12*SZREG + 7*SZFREG)(sp) + FREG_S fa0, (12*SZREG + 8*SZFREG)(sp) + FREG_S fa1, (12*SZREG + 9*SZFREG)(sp) + FREG_S fa2, (12*SZREG + 10*SZFREG)(sp) + FREG_S fa3, (12*SZREG + 11*SZFREG)(sp) + FREG_S fa4, (12*SZREG + 12*SZFREG)(sp) + FREG_S fa5, (12*SZREG + 13*SZFREG)(sp) + FREG_S fa6, (12*SZREG + 14*SZFREG)(sp) + FREG_S fa7, (12*SZREG + 15*SZFREG)(sp) + FREG_S ft8, (12*SZREG + 16*SZFREG)(sp) + FREG_S ft9, (12*SZREG + 17*SZFREG)(sp) + FREG_S ft10, (12*SZREG + 18*SZFREG)(sp) + FREG_S ft11, (12*SZREG + 19*SZFREG)(sp) +#endif + + call __tls_get_addr + addi a0, a0, -TLS_DTV_OFFSET + + REG_L ra, 0*SZREG(sp) + REG_L a1, 1*SZREG(sp) + REG_L a2, 2*SZREG(sp) + REG_L a3, 3*SZREG(sp) + REG_L a4, 4*SZREG(sp) + REG_L a5, 5*SZREG(sp) + REG_L a6, 6*SZREG(sp) + REG_L a7, 7*SZREG(sp) + REG_L t3, 8*SZREG(sp) + REG_L t4, 9*SZREG(sp) + REG_L t5, 10*SZREG(sp) + REG_L t6, 11*SZREG(sp) +#ifndef __riscv_float_abi_soft + FREG_L ft0, (12*SZREG + 0*SZFREG)(sp) + FREG_L ft1, (12*SZREG + 1*SZFREG)(sp) + FREG_L ft2, (12*SZREG + 2*SZFREG)(sp) + FREG_L ft3, (12*SZREG + 3*SZFREG)(sp) + FREG_L ft4, (12*SZREG + 4*SZFREG)(sp) + FREG_L ft5, (12*SZREG + 5*SZFREG)(sp) + FREG_L ft6, (12*SZREG + 6*SZFREG)(sp) + FREG_L ft7, (12*SZREG + 7*SZFREG)(sp) + FREG_L fa0, (12*SZREG + 8*SZFREG)(sp) + FREG_L fa1, (12*SZREG + 9*SZFREG)(sp) + FREG_L fa2, (12*SZREG + 10*SZFREG)(sp) + FREG_L fa3, (12*SZREG + 11*SZFREG)(sp) + FREG_L fa4, (12*SZREG + 12*SZFREG)(sp) + FREG_L fa5, (12*SZREG + 13*SZFREG)(sp) + FREG_L fa6, (12*SZREG + 14*SZFREG)(sp) + FREG_L fa7, (12*SZREG + 15*SZFREG)(sp) + FREG_L ft8, (12*SZREG + 16*SZFREG)(sp) + FREG_L ft9, (12*SZREG + 17*SZFREG)(sp) + FREG_L ft10, (12*SZREG + 18*SZFREG)(sp) + FREG_L ft11, (12*SZREG + 19*SZFREG)(sp) +#endif + addi sp, sp, FRAME_SIZE_SLOW + j .Lret +END (_dl_tlsdesc_dynamic) +#endif diff --git a/sysdeps/riscv/dl-tlsdesc.h b/sysdeps/riscv/dl-tlsdesc.h new file mode 100644 index 0000000000..0c9b83f43d --- /dev/null +++ b/sysdeps/riscv/dl-tlsdesc.h @@ -0,0 +1,48 @@ +/* Thread-local storage descriptor handling in the ELF dynamic linker. + RISC-V version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#ifndef _DL_TLSDESC_H +# define _DL_TLSDESC_H 1 + +#include + +/* Type used to represent a TLS descriptor in the GOT. */ +struct tlsdesc +{ + unsigned long (*entry) (struct tlsdesc *); + void *arg; +}; + +/* Type used as the argument in a TLS descriptor for a symbol that + needs dynamic TLS offsets. */ +struct tlsdesc_dynamic_arg +{ + tls_index tlsinfo; + size_t gen_count; +}; + +extern unsigned long _dl_tlsdesc_return (struct tlsdesc *) attribute_hidden; +extern unsigned long _dl_tlsdesc_undefweak (struct tlsdesc *) attribute_hidden; + +# ifdef SHARED +extern void *_dl_make_tlsdesc_dynamic (struct link_map *, size_t); +extern unsigned long _dl_tlsdesc_dynamic (struct tlsdesc *) attribute_hidden; +# endif + +#endif /* _DL_TLSDESC_H */ diff --git a/sysdeps/riscv/linkmap.h b/sysdeps/riscv/linkmap.h index ac170bb342..2fa3f6d43f 100644 --- a/sysdeps/riscv/linkmap.h +++ b/sysdeps/riscv/linkmap.h @@ -1,4 +1,5 @@ struct link_map_machine { ElfW(Addr) plt; /* Address of .plt. */ + void *tlsdesc_table; /* Address of TLS descriptor hash table. */ }; diff --git a/sysdeps/riscv/tlsdesc.c b/sysdeps/riscv/tlsdesc.c new file mode 100644 index 0000000000..d013bc7135 --- /dev/null +++ b/sysdeps/riscv/tlsdesc.c @@ -0,0 +1,38 @@ +/* Manage TLS descriptors. RISC-V version. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include + +/* Unmap the dynamic object, but also release its TLS descriptor table + if there is one. */ + +void +_dl_unmap (struct link_map *map) +{ + _dl_unmap_segments (map); + +#ifdef SHARED + if (map->l_mach.tlsdesc_table) + htab_delete (map->l_mach.tlsdesc_table); +#endif +} diff --git a/sysdeps/riscv/tlsdesc.sym b/sysdeps/riscv/tlsdesc.sym new file mode 100644 index 0000000000..652e72ea58 --- /dev/null +++ b/sysdeps/riscv/tlsdesc.sym @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include +#include + +-- + +-- Abuse tls.h macros to derive offsets relative to the thread register. + +TLSDESC_ARG offsetof(struct tlsdesc, arg) +TLSDESC_GEN_COUNT offsetof(struct tlsdesc_dynamic_arg, gen_count) +TLSDESC_MODID offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_module) +TLSDESC_MODOFF offsetof(struct tlsdesc_dynamic_arg, tlsinfo.ti_offset) +TCBHEAD_DTV offsetof(tcbhead_t, dtv) - sizeof(tcbhead_t) - TLS_TCB_OFFSET +DTV_COUNTER offsetof(dtv_t, counter) +TLS_DTV_UNALLOCATED TLS_DTV_UNALLOCATED +TLS_DTV_OFFSET TLS_DTV_OFFSET diff --git a/sysdeps/unix/sysv/linux/riscv/localplt.data b/sysdeps/unix/sysv/linux/riscv/localplt.data index ea887042e0..01710df22d 100644 --- a/sysdeps/unix/sysv/linux/riscv/localplt.data +++ b/sysdeps/unix/sysv/linux/riscv/localplt.data @@ -6,3 +6,5 @@ libc.so: free libc.so: malloc libc.so: memset ? libc.so: realloc +# The dynamic loader needs __tls_get_addr for TLS. +ld.so: __tls_get_addr