From patchwork Tue Feb 20 17:55:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 203727 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp571580dyc; Tue, 20 Feb 2024 10:02:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWy8tAHpI1X60q+Uq3x+CnXu3t+KuC9+IyIJDm5cCtTK0vLNcYbcSNlRWmggyQ1IKxEu33VAOoEOuIlrDqYyZ7LKK+Gvg== X-Google-Smtp-Source: AGHT+IEK18QD6NWxWElCLdt2P8JoPl7X5KyjknQTv2LG+0P1wPYy79ZIXTPDyzL5VH3G7WSxDQL7 X-Received: by 2002:a05:622a:1012:b0:42e:1765:9cfa with SMTP id d18-20020a05622a101200b0042e17659cfamr5924084qte.53.1708452101543; Tue, 20 Feb 2024 10:01:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708452101; cv=pass; d=google.com; s=arc-20160816; b=m0LB+ejeiR0bkumpUopCxvsrNIdSxdEQlG6hxPvS6Q4rMLPZTymWth3g52oOXCHC2F rYBTur5TvokTL6gJcp7amvsab/rWDbcMIKz0LFU1lAcJld4KuZYrryWWsEiR0IuuqibV UdiaDmJlD5p37iGDT7mqk3y/cvCJ7RmsWBP1ATkH2Q8nxsp1MzeGFOePgXyeq2D4Ld2U 4d38hHil1OMYl4chF6o2FpYCnZcJG/GaDvrSLsIM+8guAq1y7gWznifktsDPS6iViYII GFWbu1MUskLGFdj0Ix5zxuCoYLVhnrJz9wnnZHmJH0oRA063MYjnc8zC4OzQnzbpeL+n WPEg== 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=UiRSxTi8TM/Tl+/3x8cehvIuX14pv48E4y/UdtEFzb8=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=cQHvFRpX3G09okQ9ptCHD8CBWCIle79sO0KcZXo9LWVWZlwltZJosM77ToenA1NcVh rywdC/DUYuQIkNh22sr1wruHAAgsuPIjmtvl25qb/c1Nx9uc5+P1Lfg9ptkEKEOD7Tvq PErVYUCbAG+nRCiLx0XTrAPLuG4eAVrFbzF9ESMGCTUtzfUw31Vu+wR9JBvalAjWMc2y yYnkaFLgFi8aX9vXM3EaixeGyZUP6ZCDAsleVAOkTtQ4N+ZR9wFew6uGPiCKbtQuISyR ZsXqGZnx86hGYuRQlpRT85HFBvI8ubwErhXkkcS/VD9HSeVd5Wu9lUI5RVVh676U6dkL 150w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Px7V+8d8; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 l11-20020a05622a050b00b0042c2fcc55ebsi9591818qtx.24.2024.02.20.10.01.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 10:01:41 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.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=Px7V+8d8; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 00DBD384CBA1 for ; Tue, 20 Feb 2024 18:00:42 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by sourceware.org (Postfix) with ESMTPS id C9D853858C74 for ; Tue, 20 Feb 2024 17:56:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C9D853858C74 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 C9D853858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d2e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451787; cv=none; b=pBfiJXEwMJOvM5ucbCbTZKmv2WwaqmF1HrVZA6pcsVzaMYFpbJWWzkrqb1lz9Rj47CI/B3cJNH3g1br9VUBmNrRuObibODqqIEFJflRiLqLxKKe8Y0MGj1doZJFt0nLHRyVXxh6nAfejU1pbycT6NDCVHeeIOpoI74Pig9BzbUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451787; c=relaxed/simple; bh=OYIspJG2Pjccv/pC9DMXo/catUXJ4lcI9FExlkmi8W0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Dl+Zjun7mUA8MgZcanoezyz7SmyZzS8ShlEdMWru7TfQIshMPR0+sytieeKaK/HFALiwKuAOh+2gHPjORkv3m8012y8mDejRp0Muw4YiovswioiKsWkygXe6+cPaQHDGufPXhl08b9gURvzz0z5J141NJucpT7z9U+gGhdeWKRk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-7bf3283c18dso88456839f.0 for ; Tue, 20 Feb 2024 09:56:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708451782; x=1709056582; 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=UiRSxTi8TM/Tl+/3x8cehvIuX14pv48E4y/UdtEFzb8=; b=Px7V+8d8xDgcxhwcqdvOHdzuIFukFfLhShXStBzNWINAUivgEnQZN1A+QUAyP7J8NV Q4Z9uZ35qi1+VKYx7cbn6cwMOrlH6+xnfMcvtdRu6zq71Op3hh//t5d+j96W9P36G8fS h05K4rlJYU1l4N7Cq+jXjEl6ah7l8YFACqlTmiqWqxAiEdMOpAWpDaAJO+6oqTVVNVmg Us6cFxk3G6/DxxKlFwQtrND8dop4VwBiaMsAMI7LpBBtB9gxbFk8hKrmEq0GIl8D192y 9nMyims8LUTrVx1X9lKibJ6l1YdA13D3vBXWr8crGwFG+QXUGcbKdMMKTOft4xVCIBJW BmfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708451782; x=1709056582; 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=UiRSxTi8TM/Tl+/3x8cehvIuX14pv48E4y/UdtEFzb8=; b=EPCyNmtQ/dIxpudBCCqFMHHACGJF57jKO4qzuJ4BJ6gJduCZN8eNcgVZ0QcRbGvp+A Su2Z/DqTsHb9yTfszH9odWrcQPENLV7K94G76af27vKXePqimxmydo05BOIeRS9VKISX uqHQykKtHq+9+zStRC9T1I459Pag3moc5dNwIFjo2yAXweO5zEGKDCYGsF64aPGAw6++ /yEwOKYd4SoTfmS2D+LvHjrnJjxS+zXBaJlUqB9LLPGjeLxQuFzoGoBvx7WcD9qYOv/K CU9BEy+hcGy3aQegEu7q2olDmed9J+gC5RLjiEKXY9oi4FRGRsQka6PxvRgCQ35vn9pZ KSGQ== X-Gm-Message-State: AOJu0Yyfuhvi1ezjM0x2pMn0NpTQDwD2sWlN+Iiyj/Wcr7gjxg9+oSE3 /FOTKpNNAFVd32Wf4PikQLe5wQjmaXQ90uXw9ORbPYWdVTWA+Vj2I1xXQDVRsgKLcA== X-Received: by 2002:a05:6e02:218c:b0:363:c63a:7960 with SMTP id j12-20020a056e02218c00b00363c63a7960mr11548580ila.3.1708451781829; Tue, 20 Feb 2024 09:56:21 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id v18-20020a63f852000000b005dc87643cc3sm6872230pgj.27.2024.02.20.09.56.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:56:21 -0800 (PST) From: Tatsuyuki Ishi To: binutils@sourceware.org Cc: i@maskray.me, nelson@rivosinc.com, rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH v4 1/9] RISC-V: Fix local GOT and reloc size calculation for TLS. Date: Wed, 21 Feb 2024 02:55:48 +0900 Message-ID: <20240220175556.304692-2-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220175556.304692-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20240220175556.304692-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 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, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775765608571220163 X-GMAIL-MSGID: 1791441870577797732 The previous code did not account correctly for two cases: * A TLS symbol can be referenced with multiple TLS types (although rare), in which case it only allocated the maximum slot size among the types, instead of the sum. * TLS relocations are only needed for DLLs, unlike normal symbols which requires relocations for all PIE code. Modify the logic to account for the two cases. bfd/ * elfnn-riscv.c (riscv_elf_size_dynamic_sections): Handle relocation sizing for TLS and non-TLS symbols differently, with the former requiring relocs on DLL while the latter requiring on PIE. Allocate GOT slots and relocation slots for each TLS type separately, accounting for the possibility of a TLS variable getting referenced by multiple symbols. ld/ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated. * testsuite/ld-riscv-elf/tls*: New testcase for TLS GD and IE, with symbols referred by both types and global and local symbols. --- bfd/elfnn-riscv.c | 27 ++++++++++++++++----- ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp | 8 +++++++ ld/testsuite/ld-riscv-elf/tls.d | 15 ++++++++++++ ld/testsuite/ld-riscv-elf/tls.s | 28 ++++++++++++++++++++++ ld/testsuite/ld-riscv-elf/tlsbin.d | 7 ++++++ ld/testsuite/ld-riscv-elf/tlslib.s | 6 +++++ 6 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 ld/testsuite/ld-riscv-elf/tls.d create mode 100644 ld/testsuite/ld-riscv-elf/tls.s create mode 100644 ld/testsuite/ld-riscv-elf/tlsbin.d create mode 100644 ld/testsuite/ld-riscv-elf/tlslib.s diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 951b19a911d..e5cecd79cf3 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -1559,12 +1559,27 @@ riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) if (*local_got > 0) { *local_got = s->size; - s->size += RISCV_ELF_WORD_BYTES; - if (*local_tls_type & GOT_TLS_GD) - s->size += RISCV_ELF_WORD_BYTES; - if (bfd_link_pic (info) - || (*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE))) - srel->size += sizeof (ElfNN_External_Rela); + if (*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE)) + { + if (*local_tls_type & GOT_TLS_GD) + { + s->size += 2 * RISCV_ELF_WORD_BYTES; + if (bfd_link_dll (info)) + srel->size += sizeof (ElfNN_External_Rela); + } + if (*local_tls_type & GOT_TLS_IE) + { + s->size += RISCV_ELF_WORD_BYTES; + if (bfd_link_dll (info)) + srel->size += sizeof (ElfNN_External_Rela); + } + } + else + { + s->size += RISCV_ELF_WORD_BYTES; + if (bfd_link_pic (info)) + srel->size += sizeof (ElfNN_External_Rela); + } } else *local_got = (bfd_vma) -1; diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp index 7e1281d826b..a1dd0e5e37e 100644 --- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp +++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp @@ -319,4 +319,12 @@ if [istarget "riscv*-*-*"] { run_dump_test "pcrel-reloc-rel-pie" run_dump_test "pcrel-reloc-abs-nopie" run_dump_test "pcrel-reloc-abs-pie" + + run_ld_link_tests { + { "Build shared library for TLS runtime" + "-shared" "" "" {tlslib.s} + {} "tlslib.so" } + } + run_dump_test "tls" + run_dump_test "tlsbin" } diff --git a/ld/testsuite/ld-riscv-elf/tls.d b/ld/testsuite/ld-riscv-elf/tls.d new file mode 100644 index 00000000000..e7f20309bf1 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/tls.d @@ -0,0 +1,15 @@ +#source: tls.s +#ld: --shared tmpdir/tlslib.so +#readelf: -Wr + +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 5 entries: + +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ R_RISCV_TLS_DTPMOD64 +0 +[0-9a-f]+ +[0-9a-f]+ R_RISCV_TLS_TPREL64 +4 +[0-9a-f]+ +[0-9a-f]+ R_RISCV_TLS_DTPMOD64 +0+ sg1 \+ 0 +[0-9a-f]+ +[0-9a-f]+ R_RISCV_TLS_DTPREL64 +0+ sg1 \+ 0 +[0-9a-f]+ +[0-9a-f]+ R_RISCV_TLS_TPREL64 +0+ sg1 \+ 0 + +Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entry: + +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ R_RISCV_JUMP_SLOT +0+ __tls_get_addr \+ 0 diff --git a/ld/testsuite/ld-riscv-elf/tls.s b/ld/testsuite/ld-riscv-elf/tls.s new file mode 100644 index 00000000000..79e9bc20374 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/tls.s @@ -0,0 +1,28 @@ + .section .tbss,"awT",@nobits + .global sg1 +sg1: + .zero 4 +sl1: + .zero 4 + + .text + .globl _start + .type _start,@function +_start: + /* GD, global var */ + la.tls.gd a0,sg1 + call __tls_get_addr + + /* IE, global var */ + la.tls.ie a0,sg1 + add a0,a0,tp + + /* GD, local var */ + la.tls.gd a0,sl1 + call __tls_get_addr + + /* IE, local var */ + la.tls.ie a0,sl1 + add a0,a0,tp + + ret diff --git a/ld/testsuite/ld-riscv-elf/tlsbin.d b/ld/testsuite/ld-riscv-elf/tlsbin.d new file mode 100644 index 00000000000..cdcd51a9199 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/tlsbin.d @@ -0,0 +1,7 @@ +#source: tls.s +#ld: -no-pie tmpdir/tlslib.so +#readelf: -Wr + +Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entry: + +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ R_RISCV_JUMP_SLOT +[0-9a-f]+ __tls_get_addr \+ 0 diff --git a/ld/testsuite/ld-riscv-elf/tlslib.s b/ld/testsuite/ld-riscv-elf/tlslib.s new file mode 100644 index 00000000000..17c770786d0 --- /dev/null +++ b/ld/testsuite/ld-riscv-elf/tlslib.s @@ -0,0 +1,6 @@ + .text + /* Dummy. */ + .globl __tls_get_addr + .type __tls_get_addr,@function +__tls_get_addr: + ret From patchwork Tue Feb 20 17:55:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 203723 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp568932dyc; Tue, 20 Feb 2024 09:59:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW9hJzfAlJwy721Um+GInouAamIvPrZVO7tCCoJqmhWyezL/bSeDK4LiAdiJK1VvVWB8xmckY+UCOmR1QgB0qfbuX1gxQ== X-Google-Smtp-Source: AGHT+IEpeQE4gIMqbzcLGFvVyUbpJ9/2XK8E9Fe3fPv3szdRLdne6BrGOa73L2E9bR128Fh2/Vg/ X-Received: by 2002:a05:6830:13d7:b0:6e2:f6b9:bdf9 with SMTP id e23-20020a05683013d700b006e2f6b9bdf9mr15774210otq.15.1708451968387; Tue, 20 Feb 2024 09:59:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708451968; cv=pass; d=google.com; s=arc-20160816; b=kVrvcMW8SLSBMDaSyzJPwTYkmfhF8AoEd6myiPpYXFhaH2l6vAAG7AZekPoUSPqONB ZBxADp0K5Ri0UNxhwvBgB0rx/TshuAtDHAA0kMZyWzgviBJxAEp3N1tzuAQxDMOK516Y 1xeZ1fSg6D4C0eRZXmyrm2XW4d2JfX5NAdP3PGEh1f7BSjo9BiuQu38igRxwcyUVQ1ks cA1jYHxHKmVIIf/VGXQwrofdqj16Yv0Vp2h0k3nA7ktNNZOjsSkYRXmoGVl2T5hnu9do UEUequWdlGGdo8MWl7KgcSHHMHA7Md2bQ1IX9+NpHmG4KxJcRhicehsUsG/QxNU086V1 q9HQ== 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=pwdLL4zB7NO4bYN7Of7Jrm9zCz3qMIfhcZcBmDy5/pc=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=LbrcJ3O5dsOCxLfWqlVq16U59LZwrWmLeDaCDmqXZ3EaGGBTLgN0UuU+us69WHbWr+ Fyz/tilrEymzJvOSAOIfolmZrWX2DbYcCwoBH4khE6bgHAJytwFhYgLXm2Z9UZ9owCod zm7uQjTGrjejDOAD6r/L/CKywoazzDIiCguZ95ahkisJ4jlspHZq6UcObSMkcu30z6w1 kf/o8YOklf+TarGy8OFYE4iP9enG/t+VVnHd9j21cG0y3CYyFD8JisEk6uP8WmcT/RF6 qZU/Wpaxq79RsKlsRpfTz9u7HcUHwcpwg5ZNbalWry7iIvlQ1L7zFF70nQaz3tN6tPAP qudg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=k1yDnRbW; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 a22-20020ac87216000000b0042df55ba7f7si7849969qtp.32.2024.02.20.09.59.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:59:28 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.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=k1yDnRbW; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 B49E83857C5E for ; Tue, 20 Feb 2024 17:59:23 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id ED9633858D35 for ; Tue, 20 Feb 2024 17:56:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED9633858D35 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 ED9633858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451789; cv=none; b=gl2mAWqeB+hzzMo5egmTOYpM9C1iSrFZtSCjtAv0Ebi8GZFFo66htUZmdXkS9FeBiq6FcNBGYyjUq8iRLXAGKYa0ap7+WUJvvxq041RBIczbgy/+P+ODD+BY4/79oU6i90/VcG9IyUnIskYjvQgSo+a8ef5CWDTGFcMnzNUnK+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451789; c=relaxed/simple; bh=kNw6ZApoHx1cgnvBpnvDaejw1EUSw0LwX4x44Wv0XOU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=d8Vtesh4rSjLggqNlRL2bEEozIfDNKdfVzKzKqK7XgGq/fEUpDZxF2jvS6xzNaamzSJK0rNaNmy4JA4rUXfWPIn3fyV2XDUSsRkAE1k4pbEUctEBek2VEpC+fS2mTEEASdj3/ZWELL0u9Cavqe7x4gK4zizoxWMWrTYlaDaakt0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-29964f5c904so268836a91.0 for ; Tue, 20 Feb 2024 09:56:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708451785; x=1709056585; 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=pwdLL4zB7NO4bYN7Of7Jrm9zCz3qMIfhcZcBmDy5/pc=; b=k1yDnRbWqDhYIvFDu/J4hHgASPPj3pZ/p6/aOwlx9uT38Nh1JE+w59iRN8UfyAWqwE aG8x5TGbhypBTpq2sB8M2i7AA10puox/k3iO+mZapJcBAu5gd80aVdvE4IEevaVrlJk9 74+8n4tbVnPGSxhIUF9yIQbfrvvov7vth8z/O++N9uaboa3CbZpuLIEyLjgdCBKdW4pu SYmXnc+2VYL+qqnurPTwAWAuUV+72QR1/V8wSGOt6EMH1zVL/WUcQE08KRPugnSvgv/i xFecN2xSRf5itJwq54H7kpFrEfEPabJL1bOUvniaZTdxBfMW3IGZILePYjBqW+adLtFP a+Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708451785; x=1709056585; 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=pwdLL4zB7NO4bYN7Of7Jrm9zCz3qMIfhcZcBmDy5/pc=; b=gVpd2K3T58o1QZ6+RGpD9D9UJY/QxnX8kF95uoNTlxVyfiLlHtJPKeKxqPJrcQQLxU ETzsEVGquyyidB411KPGTShk4o6YPnElzWGYOPg98/3s8cqylwm42yI44oe20ZSEcOQU wbGSszMAjz1vVXg+0e5jqzeU3qrgIWpyQ7q2jP8i7NOKnfPfhQFBhT7JeWilWXijBpLk WfFT++jnAecU3rVAAvU0gfi0oW+waCZR1WrN190VfJ+cjV0xA2BLoclWRrIzraBa9jOk pltqkIvxAuTR/5hynZ/L9xW4bjqiHEkp/9Sjbc3iFPtVWhMP4jXpXMMtFrRdUXqvcAuH nh7A== X-Gm-Message-State: AOJu0YyvfljiO3UmzYpmGhzupbiXiBzxIg4LISuLuBmvoZcFmb890oes u3CZr1xSqAOxTY610TaOpVFk/90FSy9m8x+720gbCGpaNb56HC7GV92aopPCjELP4g== X-Received: by 2002:a17:90a:9903:b0:299:1ae1:51ae with SMTP id b3-20020a17090a990300b002991ae151aemr12329687pjp.3.1708451785346; Tue, 20 Feb 2024 09:56:25 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id qn11-20020a17090b3d4b00b00298f88c3e48sm7661885pjb.11.2024.02.20.09.56.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:56:24 -0800 (PST) From: Tatsuyuki Ishi To: binutils@sourceware.org Cc: i@maskray.me, nelson@rivosinc.com, rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH v4 2/9] RISC-V: Add TLSDESC reloc definitions. Date: Wed, 21 Feb 2024 02:55:49 +0900 Message-ID: <20240220175556.304692-3-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220175556.304692-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20240220175556.304692-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 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, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774500735283371203 X-GMAIL-MSGID: 1791441731100889041 bfd/ * elfxx-riscv.c: Add 5 TLSDESC reloc descriptions. * reloc.c: Likewise. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. include/ * elf/riscv.h: Add 5 TLSDESC reloc descriptions. --- v4: Fix complain_on_overflow and use complain_overflow_dont. bfd/bfd-in2.h | 4 +++ bfd/elfxx-riscv.c | 75 ++++++++++++++++++++++++++++++++++++++++++++- bfd/libbfd.h | 4 +++ bfd/reloc.c | 8 +++++ include/elf/riscv.h | 5 +++ 5 files changed, 95 insertions(+), 1 deletion(-) diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 37917845cf5..a335df522d2 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -5420,6 +5420,10 @@ enum bfd_reloc_code_real BFD_RELOC_RISCV_TLS_DTPREL64, BFD_RELOC_RISCV_TLS_TPREL32, BFD_RELOC_RISCV_TLS_TPREL64, + BFD_RELOC_RISCV_TLSDESC_HI20, + BFD_RELOC_RISCV_TLSDESC_LOAD_LO12, + BFD_RELOC_RISCV_TLSDESC_ADD_LO12, + BFD_RELOC_RISCV_TLSDESC_CALL, BFD_RELOC_RISCV_ALIGN, BFD_RELOC_RISCV_RVC_BRANCH, BFD_RELOC_RISCV_RVC_JUMP, diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index 9a121b47121..a4aa71fd809 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -218,7 +218,20 @@ static reloc_howto_type howto_table[] = MINUS_ONE, /* dst_mask */ false), /* pcrel_offset */ - EMPTY_HOWTO (12), + HOWTO (R_RISCV_TLSDESC, /* type */ + 0, /* rightshift */ + 0, /* size is handled by dynamic linker */ + 0, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_dont, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_TLSDESC", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + MINUS_ONE, /* dst_mask */ + false), /* pcrel_offset */ + EMPTY_HOWTO (13), EMPTY_HOWTO (14), EMPTY_HOWTO (15), @@ -808,6 +821,62 @@ static reloc_howto_type howto_table[] = 0, /* src_mask */ 0, /* dst_mask */ false), /* pcrel_offset */ + + HOWTO (R_RISCV_TLSDESC_HI20, /* type */ + 0, /* rightshift */ + 4, /* size */ + 32, /* bitsize */ + true, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_dont, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_TLSDESC_HI20", /* name */ + true, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_UTYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ + + HOWTO (R_RISCV_TLSDESC_LOAD_LO12, /* type */ + 0, /* rightshift */ + 4, /* size */ + 32, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_dont, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_TLSDESC_LOAD_LO12", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_ITYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ + + HOWTO (R_RISCV_TLSDESC_ADD_LO12, /* type */ + 0, /* rightshift */ + 4, /* size */ + 32, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_dont, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_TLSDESC_ADD_LO12", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_ITYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ + + HOWTO (R_RISCV_TLSDESC_CALL, /* type */ + 0, /* rightshift */ + 0, /* size */ + 0, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_dont, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_TLSDESC_CALL", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_ITYPE_IMM (-1U), /* dst_mask */ + false) /* pcrel_offset */ }; static reloc_howto_type howto_table_internal[] = @@ -935,6 +1004,10 @@ static const struct elf_reloc_map riscv_reloc_map[] = { BFD_RELOC_RISCV_TPREL_LO12_I, R_RISCV_TPREL_LO12_I }, { BFD_RELOC_RISCV_TLS_GOT_HI20, R_RISCV_TLS_GOT_HI20 }, { BFD_RELOC_RISCV_TLS_GD_HI20, R_RISCV_TLS_GD_HI20 }, + { BFD_RELOC_RISCV_TLSDESC_HI20, R_RISCV_TLSDESC_HI20 }, + { BFD_RELOC_RISCV_TLSDESC_LOAD_LO12, R_RISCV_TLSDESC_LOAD_LO12 }, + { BFD_RELOC_RISCV_TLSDESC_ADD_LO12, R_RISCV_TLSDESC_ADD_LO12 }, + { BFD_RELOC_RISCV_TLSDESC_CALL, R_RISCV_TLSDESC_CALL }, { BFD_RELOC_RISCV_ALIGN, R_RISCV_ALIGN }, { BFD_RELOC_RISCV_RVC_BRANCH, R_RISCV_RVC_BRANCH }, { BFD_RELOC_RISCV_RVC_JUMP, R_RISCV_RVC_JUMP }, diff --git a/bfd/libbfd.h b/bfd/libbfd.h index 40bbe6a3886..49f63a0b8e5 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -2409,6 +2409,10 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", "BFD_RELOC_RISCV_TLS_DTPREL64", "BFD_RELOC_RISCV_TLS_TPREL32", "BFD_RELOC_RISCV_TLS_TPREL64", + "BFD_RELOC_RISCV_TLSDESC_HI20", + "BFD_RELOC_RISCV_TLSDESC_LOAD_LO12", + "BFD_RELOC_RISCV_TLSDESC_ADD_LO12", + "BFD_RELOC_RISCV_TLSDESC_CALL", "BFD_RELOC_RISCV_ALIGN", "BFD_RELOC_RISCV_RVC_BRANCH", "BFD_RELOC_RISCV_RVC_JUMP", diff --git a/bfd/reloc.c b/bfd/reloc.c index 7583b7fd552..a187afe9b56 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -5002,6 +5002,14 @@ ENUMX BFD_RELOC_RISCV_TLS_TPREL32 ENUMX BFD_RELOC_RISCV_TLS_TPREL64 +ENUMX + BFD_RELOC_RISCV_TLSDESC_HI20 +ENUMX + BFD_RELOC_RISCV_TLSDESC_LOAD_LO12 +ENUMX + BFD_RELOC_RISCV_TLSDESC_ADD_LO12 +ENUMX + BFD_RELOC_RISCV_TLSDESC_CALL ENUMX BFD_RELOC_RISCV_ALIGN ENUMX diff --git a/include/elf/riscv.h b/include/elf/riscv.h index 2000cf21b9d..c1e73f7f5c0 100644 --- a/include/elf/riscv.h +++ b/include/elf/riscv.h @@ -44,6 +44,7 @@ START_RELOC_NUMBERS (elf_riscv_reloc_type) RELOC_NUMBER (R_RISCV_TLS_DTPREL64, 9) RELOC_NUMBER (R_RISCV_TLS_TPREL32, 10) RELOC_NUMBER (R_RISCV_TLS_TPREL64, 11) + RELOC_NUMBER (R_RISCV_TLSDESC, 12) /* Relocation types not used by the dynamic linker. */ RELOC_NUMBER (R_RISCV_BRANCH, 16) @@ -90,6 +91,10 @@ START_RELOC_NUMBERS (elf_riscv_reloc_type) /* Reserved 59 for R_RISCV_PLT32. */ RELOC_NUMBER (R_RISCV_SET_ULEB128, 60) RELOC_NUMBER (R_RISCV_SUB_ULEB128, 61) + RELOC_NUMBER (R_RISCV_TLSDESC_HI20, 62) + RELOC_NUMBER (R_RISCV_TLSDESC_LOAD_LO12, 63) + RELOC_NUMBER (R_RISCV_TLSDESC_ADD_LO12, 64) + RELOC_NUMBER (R_RISCV_TLSDESC_CALL, 65) END_RELOC_NUMBERS (R_RISCV_max) /* Internal relocations used exclusively by the relaxation pass. */ From patchwork Tue Feb 20 17:55:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 203734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp573924dyc; Tue, 20 Feb 2024 10:04:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXyCZHS++NPB3lYyhewGRlxTpUipPlIZGVY9PXbO3+4BYqo2O7Zwm+H26dGWNJPzrpKmahW/7iaxn6REibAl5UEByJoyA== X-Google-Smtp-Source: AGHT+IH8mfid9qeZCLiwqHJ3FAbmza54lVK++HSIRNY+Tsqvrh9ACe+Ed+PsPNfbnrA81psFztS4 X-Received: by 2002:ae9:e309:0:b0:785:af0a:54b7 with SMTP id v9-20020ae9e309000000b00785af0a54b7mr17287672qkf.11.1708452251996; Tue, 20 Feb 2024 10:04:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708452251; cv=pass; d=google.com; s=arc-20160816; b=QqVFTH74UdynL3QxJjdcfWv2eBGnnEcj4cBVmoGsZRvdhOlKQKjf+TwguZjNs/cKEN 7Xyh+L6KF41/Q+Driafpv1uhBP+6wyHqcHBFp3BDc0a0nbXf8ldhteBCyYirPEEW8TES 0quyE9adSuveAxNs2Q31bCoD2fhVm0veamV7NCjk2KD/D+D4dCVa+JMjFESb4Kreq2S9 x8E0oQl03oTfN6Gao3w6+YKSQxNavr3zVujdJmXcNQWhlwoQbsQfozVVorsR4K75Ky9u yJ3RFYY0LCEDyaRSHLKuVH1P5UlHUSYX4faPQ8V8uejRCELLpB923RFRubbCOiziGRxN GqNQ== 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=D7VclN+GWmO8MMSWo0Dp0TbyfivX9IDaVLooPsUNv4Y=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=LGwZdrojDWlIVItOfBNEPyOIYmJzoXiwMDJ12ZzIxKF0Kj25XcOHfjGcqmgsFGCKtM Dhm/JW/1BOHgg7567al+xoWOos8RIh4BbYPkexqMqm1FID778H6oR/Z6SNLWLOxgWqlZ ohx43Q76NkvE/Sa4DilFYJa2DdcAJznBogV6+ox3Pr6VPPW4qu+dydn3OHDxzYOrhUi6 6r32ygXrsUHS1UOZdV0tfpbTOSJUVd+F2D6LM4ItULdKUEzetGZu3d4wW45KsbVrc4qX 95eHtiUZFTaHfD1am9G1S0D0DD2hs1q/ynfORLZCRMQ7Rci7Wj8opksxBlUopQze0l20 G3nQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=b8+mgeUA; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c15-20020a37e10f000000b0078725c5dc13si8920482qkm.109.2024.02.20.10.04.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 10:04:11 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=b8+mgeUA; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 8CFAC3861838 for ; Tue, 20 Feb 2024 18:03:09 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 9EC3A3858C56 for ; Tue, 20 Feb 2024 17:56:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9EC3A3858C56 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 9EC3A3858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451791; cv=none; b=mJQytdMbYgL42L2ZcyiZ59AEphmclsZC+MHoOkwFRgRxFvhln0dphvG5Rcjd6yz+aMYpbRwukEroIedK1sZ7l/qTKKDLO/3BUiPn/beXngQzRkjhrWWEWGKw39Pcr2xLYP5QXbSWnndogm17s1MPexjPwCCrWmnexqTr156h41k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451791; c=relaxed/simple; bh=0BlLHj6R8Z5GZGNJhT3gr2QH6zg4djp/VheAlgPGrcE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=IoJFzRUfieTGTaatXzGEpVuco39Ar8O9BnYhwZgjSN6dICXB5zKvoDbCP80+0ZpDgZNAXZvGbUz9IMiTBYBnc2pLfKnz1trnWAbhBPM2/W1uq/N1787IHbCX4++/qjfNaa/cubPEcc/Jv7HmUCTYQSwP8FZ8R926dggEltJkTkQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6e28029f2b4so88364b3a.1 for ; Tue, 20 Feb 2024 09:56:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708451788; x=1709056588; 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=D7VclN+GWmO8MMSWo0Dp0TbyfivX9IDaVLooPsUNv4Y=; b=b8+mgeUAjH2B2pYZLkuol8IjLPFQvFdoPHsXDZhEhP4O9G+GW5JXxO56/HEoJOZELs TtgxB6mElx8NxFqvmQgQwiQsYFSUhMpdwxgO1dwV0D/GItx1UoAX4G1jwKivWMKCKdVT nYLVe47FrnQmQBin51+/Qoa6Bje4uupN5dsOT8dzMHVYJv8Uu+I5SW3VgF15vZrYmRDg OaVHAaGQY3Xpa81lvZ6QNtkYi1TjP/DdVcPoYJRQHsuMW22HJzFvBFy8HrUgnlHu9YWB V0MbwDqWqvJTGl51tPQezOOblEZzvpWjSnQD9cZhP3R9TMu094HrpT/P6oZBE3Mztcl5 BLJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708451788; x=1709056588; 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=D7VclN+GWmO8MMSWo0Dp0TbyfivX9IDaVLooPsUNv4Y=; b=E97b2TJ1QY7ifEaMiuaz8ca0zgbWNV1r4uf1sYWM67AIbWAzHqTVYxTcbHCuXxNUyv itp8wX0UopZZKtC2y5DwHUJrF9/1Bn466LJIdWKY6Kq6C40NRGrjYVf9lmUwBf3ANljh 2MD5k5oCXd8M4RmJtaTeLtV4QQWgidkTnhj+q+LdE0G7jg77Lv5TqFxRonAlDZ/AsRDP 7VMJGjL19GhD6NUj1WdQAw/z8kVmsoDTSnHEoiKHXBIUeLq3b8jJf0gknVUThMB2z07A +XZQ8gbSQQ74l1WwCN7CQEpw+G9qM+XlG8W8Icsk7sZuWrqToYp+VlWdnSniKdEU/f5+ Xj0g== X-Gm-Message-State: AOJu0YxnoWkJS1nDWgCKoQl6mlC2UIGKekcelNC72qlNXpDOTLpxv9nA dL5gbSzv3YiLH2ZjozBxFfkNoLG3iH25lcdDQiF7laj56NbIuz0FfSjLF51l9d1tJA== X-Received: by 2002:a05:6a21:7895:b0:1a0:b4fa:b90c with SMTP id bf21-20020a056a21789500b001a0b4fab90cmr2427389pzc.5.1708451787927; Tue, 20 Feb 2024 09:56:27 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id h4-20020a170902eec400b001db7ed7ac34sm6465631plb.297.2024.02.20.09.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:56:27 -0800 (PST) From: Tatsuyuki Ishi To: binutils@sourceware.org Cc: i@maskray.me, nelson@rivosinc.com, rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH v4 3/9] RISC-V: Add assembly support for TLSDESC. Date: Wed, 21 Feb 2024 02:55:50 +0900 Message-ID: <20240220175556.304692-4-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220175556.304692-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20240220175556.304692-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 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, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774500739865715451 X-GMAIL-MSGID: 1791442028283335250 gas/ * tc-riscv.c (percent_op_*): Add support for %tlsdesc_hi, %tlsdesc_load_lo, %tlsdesc_add_lo and %tlsdesc_call. percent_op_rtype renamed to percent_op_relax_only as this matcher is extended to handle jalr as well which is not R-type. (riscv_ip): Apply the percent_op_relax_only rename and update comment. (md_apply_fix): Add TLSDESC_* to relaxable list. Add TLSDESC_HI20 to TLS relocation check list. * testsuite/gas/riscv/tlsdesc.*: New test cases for TLSDESC relocation generation. opcodes/ * riscv-opc.c (riscv_opcodes): Add a new syntax for jalr with %tlsdesc_call annotations. --- v4: Change test case to use objdump: -dr, and remove the rv32 arch restriction. gas/config/tc-riscv.c | 18 +++++++++++----- gas/testsuite/gas/riscv/tlsdesc.d | 36 +++++++++++++++++++++++++++++++ gas/testsuite/gas/riscv/tlsdesc.s | 24 +++++++++++++++++++++ opcodes/riscv-opc.c | 1 + 4 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 gas/testsuite/gas/riscv/tlsdesc.d create mode 100644 gas/testsuite/gas/riscv/tlsdesc.s diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index a4161420128..55c527520d5 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -2202,6 +2202,7 @@ static const struct percent_op_match percent_op_utype[] = {"tprel_hi", BFD_RELOC_RISCV_TPREL_HI20}, {"pcrel_hi", BFD_RELOC_RISCV_PCREL_HI20}, {"got_pcrel_hi", BFD_RELOC_RISCV_GOT_HI20}, + {"tlsdesc_hi", BFD_RELOC_RISCV_TLSDESC_HI20}, {"tls_ie_pcrel_hi", BFD_RELOC_RISCV_TLS_GOT_HI20}, {"tls_gd_pcrel_hi", BFD_RELOC_RISCV_TLS_GD_HI20}, {"hi", BFD_RELOC_RISCV_HI20}, @@ -2213,6 +2214,8 @@ static const struct percent_op_match percent_op_itype[] = {"lo", BFD_RELOC_RISCV_LO12_I}, {"tprel_lo", BFD_RELOC_RISCV_TPREL_LO12_I}, {"pcrel_lo", BFD_RELOC_RISCV_PCREL_LO12_I}, + {"tlsdesc_load_lo", BFD_RELOC_RISCV_TLSDESC_LOAD_LO12}, + {"tlsdesc_add_lo", BFD_RELOC_RISCV_TLSDESC_ADD_LO12}, {0, 0} }; @@ -2224,8 +2227,9 @@ static const struct percent_op_match percent_op_stype[] = {0, 0} }; -static const struct percent_op_match percent_op_rtype[] = +static const struct percent_op_match percent_op_relax_only[] = { + {"tlsdesc_call", BFD_RELOC_RISCV_TLSDESC_CALL}, {"tprel_add", BFD_RELOC_RISCV_TPREL_ADD}, {0, 0} }; @@ -3386,10 +3390,10 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr, *imm_reloc = BFD_RELOC_RISCV_LO12_I; goto load_store; case '1': - /* This is used for TLS, where the fourth operand is - %tprel_add, to get a relocation applied to an add - instruction, for relaxation to use. */ - p = percent_op_rtype; + /* This is used for TLS relocations that acts as relaxation + markers and do not change the instruction encoding, + i.e. %tprel_add and %tlsdesc_call. */ + p = percent_op_relax_only; goto alu_op; case '0': /* AMO displacement, which must be zero. */ load_store: @@ -4252,6 +4256,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) case BFD_RELOC_RISCV_TPREL_LO12_I: case BFD_RELOC_RISCV_TPREL_LO12_S: case BFD_RELOC_RISCV_TPREL_ADD: + case BFD_RELOC_RISCV_TLSDESC_HI20: relaxable = true; /* Fall through. */ @@ -4425,6 +4430,9 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) case BFD_RELOC_RISCV_CALL: case BFD_RELOC_RISCV_CALL_PLT: + case BFD_RELOC_RISCV_TLSDESC_LOAD_LO12: + case BFD_RELOC_RISCV_TLSDESC_ADD_LO12: + case BFD_RELOC_RISCV_TLSDESC_CALL: relaxable = true; break; diff --git a/gas/testsuite/gas/riscv/tlsdesc.d b/gas/testsuite/gas/riscv/tlsdesc.d new file mode 100644 index 00000000000..5cd26ac3280 --- /dev/null +++ b/gas/testsuite/gas/riscv/tlsdesc.d @@ -0,0 +1,36 @@ +#source: tlsdesc.s +#objdump: -dr + +.*:[ ]+file format .* + + +Disassembly of section .text: + +0+00 <_start>: +[ ]+0:[ ]+00000517[ ]+auipc[ ]+a0,0x0 +[ ]+0:[ ]+R_RISCV_TLSDESC_HI20[ ]+sg1 +[ ]+0:[ ]+R_RISCV_RELAX[ ]+\*ABS\* +[ ]+4:[ ]+00052283[ ]+lw[ ]+t0,0\(a0\) # 0( <.*>)? +[ ]+4:[ ]+R_RISCV_TLSDESC_LOAD_LO12[ ]+\.desc1 +[ ]+4:[ ]+R_RISCV_RELAX[ ]+\*ABS\* +[ ]+8:[ ]+00050513[ ]+mv[ ]+a0,a0 +[ ]+8:[ ]+R_RISCV_TLSDESC_ADD_LO12[ ]+\.desc1 +[ ]+8:[ ]+R_RISCV_RELAX[ ]+\*ABS\* +[ ]+c:[ ]+000282e7[ ]+jalr[ ]+t0,t0 +[ ]+c:[ ]+R_RISCV_TLSDESC_CALL[ ]+\.desc1 +[ ]+c:[ ]+R_RISCV_RELAX[ ]+\*ABS\* + +0+10 <\.desc2>: +[ ]+10:[ ]+00000517[ ]+auipc[ ]+a0,0x0 +[ ]+10:[ ]+R_RISCV_TLSDESC_HI20[ ]+sl1 +[ ]+10:[ ]+R_RISCV_RELAX[ ]+\*ABS\* +[ ]+14:[ ]+00052283[ ]+lw[ ]+t0,0\(a0\) # 10( <.*>)? +[ ]+14:[ ]+R_RISCV_TLSDESC_LOAD_LO12[ ]+\.desc2 +[ ]+14:[ ]+R_RISCV_RELAX[ ]+\*ABS\* +[ ]+18:[ ]+00050513[ ]+mv[ ]+a0,a0 +[ ]+18:[ ]+R_RISCV_TLSDESC_ADD_LO12[ ]+\.desc2 +[ ]+18:[ ]+R_RISCV_RELAX[ ]+\*ABS\* +[ ]+1c:[ ]+000282e7[ ]+jalr[ ]+t0,t0 +[ ]+1c:[ ]+R_RISCV_TLSDESC_CALL[ ]+\.desc2 +[ ]+1c:[ ]+R_RISCV_RELAX[ ]+\*ABS\* +[ ]+20:[ ]+00008067[ ]+ret diff --git a/gas/testsuite/gas/riscv/tlsdesc.s b/gas/testsuite/gas/riscv/tlsdesc.s new file mode 100644 index 00000000000..15468d5f947 --- /dev/null +++ b/gas/testsuite/gas/riscv/tlsdesc.s @@ -0,0 +1,24 @@ + .section .tbss,"awT",@nobits + .global sg1 +sg1: + .zero 4 +sl1: + .zero 4 + + .text + .globl _start + .type _start,@function +_start: +.desc1: + auipc a0, %tlsdesc_hi(sg1) + lw t0, %tlsdesc_load_lo(.desc1)(a0) + addi a0, a0, %tlsdesc_add_lo(.desc1) + jalr t0, t0, %tlsdesc_call(.desc1) + +.desc2: + auipc a0, %tlsdesc_hi(sl1) + lw t0, %tlsdesc_load_lo(.desc2)(a0) + addi a0, a0, %tlsdesc_add_lo(.desc2) + jalr t0, t0, %tlsdesc_call(.desc2) + + ret diff --git a/opcodes/riscv-opc.c b/opcodes/riscv-opc.c index fdd05ac75dc..dcc592e1fc2 100644 --- a/opcodes/riscv-opc.c +++ b/opcodes/riscv-opc.c @@ -384,6 +384,7 @@ const struct riscv_opcode riscv_opcodes[] = {"jalr", 0, INSN_CLASS_I, "s,j", MATCH_JALR|(X_RA << OP_SH_RD), MASK_JALR|MASK_RD, match_opcode, INSN_ALIAS|INSN_JSR }, {"jalr", 0, INSN_CLASS_I, "d,s", MATCH_JALR, MASK_JALR|MASK_IMM, match_opcode, INSN_ALIAS|INSN_JSR }, {"jalr", 0, INSN_CLASS_I, "d,o(s)", MATCH_JALR, MASK_JALR, match_opcode, INSN_JSR }, +{"jalr", 0, INSN_CLASS_I, "d,s,1", MATCH_JALR, MASK_JALR|MASK_IMM, match_opcode, INSN_JSR }, {"jalr", 0, INSN_CLASS_I, "d,s,j", MATCH_JALR, MASK_JALR, match_opcode, INSN_JSR }, {"j", 0, INSN_CLASS_C, "Ca", MATCH_C_J, MASK_C_J, match_opcode, INSN_ALIAS|INSN_BRANCH }, {"j", 0, INSN_CLASS_I, "a", MATCH_JAL, MASK_JAL|MASK_RD, match_opcode, INSN_ALIAS|INSN_BRANCH }, From patchwork Tue Feb 20 17:55:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 203721 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp568755dyc; Tue, 20 Feb 2024 09:59:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWNfbGKeyhhTC1cUh9AFV7j7b7Der7192HUq5m3WpEXpcsELYRAS44pXu5IyuNVtmu4zuaba41BzFdDoNgYZ0zHeKc3Kg== X-Google-Smtp-Source: AGHT+IEc4CWquZyGUeMD44I508oypcAuwhhoAmmC57ruFLHokoJLZPW38STK/9bhXFh7SlNigTKW X-Received: by 2002:a05:6214:626:b0:68f:301b:5481 with SMTP id a6-20020a056214062600b0068f301b5481mr5484167qvx.13.1708451945311; Tue, 20 Feb 2024 09:59:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708451945; cv=pass; d=google.com; s=arc-20160816; b=SUmg3GTGrx1/x22htYVywFMabRqr+PdvYlGTiJZ5vGvJRVwDybBJqxdsY0JLSUL7go QxCROyKWG1Vh8S5aBnZN/5nVKjKfgSa6LWPLLgIObztbHR3xjHzBWICpLIe9GNOyjEDj IgL6smDU20ECiScaYxv5WW36EBsapQeYUijkB9SdIVnEfRc4aK83GixcfltFgGL1+i1Y ON3DrTMiI09tz6eIZpnSjXInfqdOUe4JXLh8n190x0kIFYEtxorc6JaaiAKuiwbtjkQ6 umH0CG1enVZkzGY3JTTbdH7qNM8nu1XoX15P9Ykz+XtWo7SWkIpE5YVnqcpjDFY97YaO LXCw== 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=ytrMX7M8wCHAzq3bbA4ODKo8vb46faf/l8fO4vYcxuM=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=JcM2Z5E66TDuueWT5+2sDui1g8DfMQazhJ71ax31bIeYrJPagEq02RZehHkEk9SE+g Q9OEX+1aUlcVg8tVwnXv8APldpYMvvXv7glEZKJefKboFFzD3ewCbMAxDYAYKGcYFYLE zoCIpAiaKMDNiPegOu72R1IdSqLQJTCcdHZTkFxE5n2e4gdNFtQxlnjihDGuNhk6C1Yy C8dHpEmnYRBMfaFI/1kFOxoyqqc1Tzn4EvqrPV69spzPvOB6HhfB931koWoYPp1RcmWP tMlG6mIaFk+4kvTiJX/xzevx2CDHErKoAFzw/OPcI44+PM22IeWbglfSbCTE0C8m205H 8uPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iQBZl2M+; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z10-20020a056214040a00b0068f07ff2506si9203099qvx.223.2024.02.20.09.59.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:59:05 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iQBZl2M+; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 2474838582A0 for ; Tue, 20 Feb 2024 17:59:03 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 2C2AB3858D39 for ; Tue, 20 Feb 2024 17:56:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C2AB3858D39 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 2C2AB3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451796; cv=none; b=rpa5giyIk3xPilfILGr/z4L5zjw8fl4kQXPltn4uIq6XSXtD8VcbAjtgMUaFQG+6BrIMbDqqbjCKrKHbMOVt7tvy9wnrjm55AFHb/P1FmHsF664ja4HjP/pG2ZeK5z93Bouf6ah5piLGuPgNIDLrz0MWY1vgVZ3vpV3th9wf3Dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451796; c=relaxed/simple; bh=z9ppKNL9EowFqG6WpswAh0qndDlORpnZVU99eS9Yr6w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=l7/LxU6EPn9wr+iAsOW4fyx9XnnaJ65d9rv/9KYtQOPOcYps3Cgq6cRc9vMahXOCVZMgbvn5L0xXNgpXajLd8ErHP0uoESYPS2QAHgZZQVu42rULi52dsIcCUdD06b2S3LMfbFjFwLRT7WHPfq+33sE9lmHFO8GZ2g9PBBEnRdM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6e45c698090so476893b3a.0 for ; Tue, 20 Feb 2024 09:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708451791; x=1709056591; 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=ytrMX7M8wCHAzq3bbA4ODKo8vb46faf/l8fO4vYcxuM=; b=iQBZl2M+ZsgTV4S7sbMuDMZBCgUDEexYSVxHXBQvMjb0jTfhLon4u03JMslKvONExw 4kL/2qg9nhneaNz3vd60yQ7zJjel1ZitydAHdYKc0+u3+EgT6YAxbJhZYI8M+pL1DHbg /0gF1cjlztNKj17W7VXmkidVPK0mFenBjlaNRmM3I9w1tk9RP7J9NkWqG057daJ5zsCt 2QznIE8dlVqb7mBO7G/IWY0iX7tNbc4cQd8qyAI5sanE3Cus1MoA8q4JPgVBvYEQGlb9 aySSPdmrXK33yxSWXIP0uvd5bFSe6itSG71ERXzyfzJIJ0suZcMR4Rinb6MQ3FqQygC1 pDoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708451791; x=1709056591; 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=ytrMX7M8wCHAzq3bbA4ODKo8vb46faf/l8fO4vYcxuM=; b=DitDgRUzQShnhsFmeQR9sJz3JG8rPHr87gnFC+w8DBITRHDO1QNTxG5HHCzww7qi+L XOK/bHrCi0FuBKAqKEbBUSDQbQFrFmEEAyw93kfprXO3p16IfOVWUPAGzfw1gtC+k0mF fYsWkkePz4MaUmtp/0FunxnxRNKH00h2xTsfiZoyU3Xbcw3BdpZfqJQg+v6JO2uHg/+t Qo59L0pLPTa9aHYvwfP54TM5yjmVX0Z3fubMLhjmH0827NmdrBVTbWDzAlD0gI3JeTmu JgPNHiyRRaQGBx34v5mLpx4ui2onR+Z/P4ZF4WxT6ktv7Az5dEXy4BGE/LInFGTlo0iY 0QCw== X-Gm-Message-State: AOJu0YyXzt2eO2G9s29tSrEKD/RBIIZzY+yRtOut5RuucGxGG7vGr7Tz JC5hNmAbshCVvS3PjDMypyooK1Nq+Sg8rdE1696ZHDe83rQwsROpdwAIxOgKB52S/g== X-Received: by 2002:a05:6a21:328a:b0:1a0:b20e:531b with SMTP id yt10-20020a056a21328a00b001a0b20e531bmr3893482pzb.4.1708451791196; Tue, 20 Feb 2024 09:56:31 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id lb26-20020a056a004f1a00b006dde1781800sm7358072pfb.94.2024.02.20.09.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:56:30 -0800 (PST) From: Tatsuyuki Ishi To: binutils@sourceware.org Cc: i@maskray.me, nelson@rivosinc.com, rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH v4 4/9] RISC-V: Define and use GOT entry size constants for TLS. Date: Wed, 21 Feb 2024 02:55:51 +0900 Message-ID: <20240220175556.304692-5-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220175556.304692-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20240220175556.304692-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 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, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774500850174321211 X-GMAIL-MSGID: 1791441706791281817 As the size calculation is split by global and local symbols, using a shared constant definition for its size improves clarity. bfd/ * elfnn-riscv.c: Add macros for sizes of a normal GOT entry, TLS GD and TLS IE entry. (allocate_dynrelocs): Replace GOT size expressions with the new constants. (riscv_elf_size_dynamic_sections): Likewise. (riscv_elf_relocate_section): Likewise. --- bfd/elfnn-riscv.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index e5cecd79cf3..17d44979d7e 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -298,6 +298,8 @@ riscv_is_insn_reloc (const reloc_howto_type *howto) #define PLT_HEADER_SIZE (PLT_HEADER_INSNS * 4) #define PLT_ENTRY_SIZE (PLT_ENTRY_INSNS * 4) #define GOT_ENTRY_SIZE RISCV_ELF_WORD_BYTES +#define TLS_GD_GOT_ENTRY_SIZE (RISCV_ELF_WORD_BYTES * 2) +#define TLS_IE_GOT_ENTRY_SIZE RISCV_ELF_WORD_BYTES /* Reserve two entries of GOTPLT for ld.so, one is used for PLT resolver, the other is used for link map. Other targets also reserve one more entry used for runtime profile? */ @@ -1320,7 +1322,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) /* TLS_GD needs two dynamic relocs and two GOT slots. */ if (tls_type & GOT_TLS_GD) { - s->size += 2 * RISCV_ELF_WORD_BYTES; + s->size += TLS_GD_GOT_ENTRY_SIZE; if (need_reloc) htab->elf.srelgot->size += 2 * sizeof (ElfNN_External_Rela); } @@ -1328,14 +1330,14 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) /* TLS_IE needs one dynamic reloc and one GOT slot. */ if (tls_type & GOT_TLS_IE) { - s->size += RISCV_ELF_WORD_BYTES; + s->size += TLS_IE_GOT_ENTRY_SIZE; if (need_reloc) htab->elf.srelgot->size += sizeof (ElfNN_External_Rela); } } else { - s->size += RISCV_ELF_WORD_BYTES; + s->size += GOT_ENTRY_SIZE; if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h) && ! UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) htab->elf.srelgot->size += sizeof (ElfNN_External_Rela); @@ -1563,20 +1565,20 @@ riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) { if (*local_tls_type & GOT_TLS_GD) { - s->size += 2 * RISCV_ELF_WORD_BYTES; + s->size += TLS_GD_GOT_ENTRY_SIZE; if (bfd_link_dll (info)) srel->size += sizeof (ElfNN_External_Rela); } if (*local_tls_type & GOT_TLS_IE) { - s->size += RISCV_ELF_WORD_BYTES; + s->size += TLS_IE_GOT_ENTRY_SIZE; if (bfd_link_dll (info)) srel->size += sizeof (ElfNN_External_Rela); } } else { - s->size += RISCV_ELF_WORD_BYTES; + s->size += GOT_ENTRY_SIZE; if (bfd_link_pic (info)) srel->size += sizeof (ElfNN_External_Rela); } @@ -2928,7 +2930,7 @@ riscv_elf_relocate_section (bfd *output_bfd, reference's GOT slot follows the GD reference's slots. */ ie_off = 0; if ((tls_type & GOT_TLS_GD) && (tls_type & GOT_TLS_IE)) - ie_off = 2 * GOT_ENTRY_SIZE; + ie_off = TLS_GD_GOT_ENTRY_SIZE; if ((off & 1) != 0) off &= ~1; From patchwork Tue Feb 20 17:55:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 203724 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp569612dyc; Tue, 20 Feb 2024 10:00:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUhVxmL5c0/52A6nfSHOAiZuWcOrwdtBaYRQbq6V4XbZoZjTHY2OImUn5+9qoJslU0MeKf64TueeihfbRXZtISmnlWo1w== X-Google-Smtp-Source: AGHT+IFkup//3j28Kq4mG3kQWbYL242Bi7K9zyjfgcu+YAw+ORF0mxFZ9XvEzGT8+PhgaLpi9CiW X-Received: by 2002:ae9:f109:0:b0:787:768a:db6 with SMTP id k9-20020ae9f109000000b00787768a0db6mr2781507qkg.16.1708452023646; Tue, 20 Feb 2024 10:00:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708452023; cv=pass; d=google.com; s=arc-20160816; b=r3YZcIPmpzMQuFjna+6ABmL7vynp4ffpcCZpO0+QPjuF142i6r+8UiyElqWOoQRGhP A4eefMnuLS1q5mM4vthsz6xKcV1aZC5WdqKY3g4Tfb26Muh5wZT6HW13yyEQDtINp+M+ /80qeRIwn0A5FtBYeGZTJ4Ob8pD0O3awL+AcmEf6KO2fw9o/q9M9HeAXS4uJCFn/mNSc tXVDhShQWQ9SU19zjJsMrmQuSFVyS2nGIaECOpbqcky+l02v/ryOSkvGHDkEHZWb5kpM SDUPIs+vtPBd1el018IL3QAH5bMfUeqaIZIXgsAyvYhFTYCc9pl3RV+AUBEyBHeN1k4V LWgA== 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=D/cXJaGSQmvE2V6Lu9MWVIwKfk0NquMNE7zI4nMY2Cc=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=vvCe5+4wBK4yhwA1H9Ac8UYhqhOuFNoc5P46FHOPUhuqitdsVkxEBjpI0xWjGaeT6Z VF0Yzav6Ec9U5JDpaDCk5NOXuUiskZ6EAmivxfJSG+AbhPLwFVm0s0TC1gylsCm+4Bxn Oqieu8kKNqsEd14LkylV6mcU7In6HPPkV1vCK2RZVx4p+Uduid6/jF3gHRT/0bhF8RpY gNYTU617YRlqUnMu2wFMFFhmiHDfioek1UHANBe0W5zbYE6rCjssBUmVOoC7zCphv1DI Efl658iQU1Dnti4D4BOHJmZiR/M4xJiDSFIB0Wzxd5jhfehgbSALb+6CFoQj7t4ZVwUA Bh3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mVjS1Rhv; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ea19-20020a05620a489300b0078773d45a03si3207143qkb.704.2024.02.20.10.00.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 10:00:23 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mVjS1Rhv; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 868E3385DC05 for ; Tue, 20 Feb 2024 18:00:01 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 539853858C30 for ; Tue, 20 Feb 2024 17:56:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 539853858C30 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 539853858C30 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451798; cv=none; b=IXm4fOTEmnylmIIWtDRCBNWm/P5gF1CbrvILFzekUJFi10Eq6yRI735fnRfDvODZlYXv4+kzpTLA4oUMIrw7jod7D4tz1TmIVjIdOdOJjUdXx6fp2Z2gyvoz/pcaE/87xVmKiAVwolWJ7Q7Kd9O6o62HX42ie/4TNMqiomw3DaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451798; c=relaxed/simple; bh=jQ0ADRuCZSC8Cu2tE24tsrYuF52AKdXLLHSsxd4sE/Q=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=U522WmyxVdaOe959pIaO0sDo4VWPhfrE/ED0koXVdzN6D3WQ8MfPlLXDIED2LMHeYt2I+LtSJgT4oBDTNE1drG/usDw3V00ec4GHts/quRWe6a9FelefTPdHAyfRFyAaief9gy80iC1sDyIHqqrbSnFVaEf2//zujXnFizjnosA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6e28029f2b4so88395b3a.1 for ; Tue, 20 Feb 2024 09:56:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708451794; x=1709056594; 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=D/cXJaGSQmvE2V6Lu9MWVIwKfk0NquMNE7zI4nMY2Cc=; b=mVjS1RhvdFl0iqucW2J5XvP6LGWv9oImR7acrQsJlFg3fWzDABCk9H70DyNUnfRyXB gjrRGL/zxAb5FtDoTpqEEegdDt+3yTT09z0b0NcZ3bMKIO+e/77ERioHeeFImlT06kIL clGxfxCX7S2wfDs16G+4mLTpDENfwqjtaKiQL4URO13AZEb5jVmEATFIgIjIhrMomW3N KsxmowQU9ceV6TvYexF3dYgLdQQcMrLgGEBLDwsqc8fEFvwp0xcwb6njb9VQjfOX6Mxr NmSt2VOQr4SonHbXRGh85MghfVpH+yo+emc/4cTREW5LPC8EuCB4hw/kDDmOoHLL2B7e iT2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708451794; x=1709056594; 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=D/cXJaGSQmvE2V6Lu9MWVIwKfk0NquMNE7zI4nMY2Cc=; b=Mo8TBcjqnabIez3m2TiQFdAeKmQBmhb0ujBIcXYxrFIPF9cHI9EE6yYGauL5BPZe0D eAw+ocHQEqkrapTiI4+5P66d6jnPn2tU2qX8Ftd7wtCkTcdinNj5m0ToCNIFFEofe7/U yzKc1nv21n1p00OqC41cL3nIWq4FJT76Mu1WNrx0GfUW4qpJol3prdJTumhkOAEsX25j kCCR1/ZsIr0FqGv4HYuLDJPwqHqZlo8xFCYfp94QhFc2Jw8h/S0Gy2GsJJxnndGb5Yc4 +l+zaiqGBFs0giPn6BoOaZZlbsP8sjPiXoZhcqdpmKBsnhL3prANb7lmmYaBVzYMSgaB OzgA== X-Gm-Message-State: AOJu0YxNoXoqHSPPwPXtP7ZWR8wNK4hyWZaaMmi3ix1VCqr0+oXshoA6 dVepaddRDjpZC77E8il0bqCZ4yXlMm87FTbithPAx7LYo8Y9agod8B5IFlLRDHw3ow== X-Received: by 2002:a05:6a20:3942:b0:1a0:b51c:bf82 with SMTP id r2-20020a056a20394200b001a0b51cbf82mr2373832pzg.4.1708451793777; Tue, 20 Feb 2024 09:56:33 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id c11-20020a62e80b000000b006e39d08cb3asm6075071pfi.167.2024.02.20.09.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:56:33 -0800 (PST) From: Tatsuyuki Ishi To: binutils@sourceware.org Cc: i@maskray.me, nelson@rivosinc.com, rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH v4 5/9] RISC-V: Initial ld.bfd support for TLSDESC. Date: Wed, 21 Feb 2024 02:55:52 +0900 Message-ID: <20240220175556.304692-6-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220175556.304692-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20240220175556.304692-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 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, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774500943007427688 X-GMAIL-MSGID: 1791441789034475291 Only relocation handling for now; relaxation is not implemented yet. bfd/ * elfnn-riscv.c (riscv_elf_check_relocs): Record GOT reference and paired relocation for TLSDESC_HI20. (riscv_elf_adjust_dynamic_symbol): Allocate GOT and reloc slots for TLSDESC symbols. (riscv_elf_size_dynamic_sections): Likewise but for local symbols. (tlsdescoff): New helper to determine static addend for R_TLSDESC. (riscv_elf_relocate_section): Ignore TLSDESC_CALL reloc for now (it is relaxation only). Handle TLSDESC_{LOAD,ADD}_LO12 as paired pcrel relocs. For TLS GOT slot generation, generalize the logic to handle any combination of (GD, IE, TLSDESC). Add TLSDESC Rela generation. * ld/testsuite/ld-riscv-elf/tls*: Add TLSDESC instruction sequences next to the existing GD and IE sequences. Update expectations. --- v4: Reject non-zero addend for LO12. Calculate offset correctly when DESC and GD is present but not IE. bfd/elfnn-riscv.c | 104 +++++++++++++++++++++++++---- ld/testsuite/ld-riscv-elf/tls.d | 4 +- ld/testsuite/ld-riscv-elf/tls.s | 14 ++++ ld/testsuite/ld-riscv-elf/tlsbin.d | 5 ++ 4 files changed, 114 insertions(+), 13 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 17d44979d7e..16394110c6a 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -163,6 +163,7 @@ struct riscv_elf_link_hash_entry #define GOT_TLS_GD 2 #define GOT_TLS_IE 4 #define GOT_TLS_LE 8 +#define GOT_TLSDESC 16 char tls_type; }; @@ -300,6 +301,7 @@ riscv_is_insn_reloc (const reloc_howto_type *howto) #define GOT_ENTRY_SIZE RISCV_ELF_WORD_BYTES #define TLS_GD_GOT_ENTRY_SIZE (RISCV_ELF_WORD_BYTES * 2) #define TLS_IE_GOT_ENTRY_SIZE RISCV_ELF_WORD_BYTES +#define TLSDESC_GOT_ENTRY_SIZE (RISCV_ELF_WORD_BYTES * 2) /* Reserve two entries of GOTPLT for ld.so, one is used for PLT resolver, the other is used for link map. Other targets also reserve one more entry used for runtime profile? */ @@ -855,6 +857,12 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, return false; break; + case R_RISCV_TLSDESC_HI20: + if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx) + || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLSDESC)) + return false; + break; + case R_RISCV_CALL: case R_RISCV_CALL_PLT: /* These symbol requires a procedure linkage table entry. @@ -1313,7 +1321,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) s = htab->elf.sgot; h->got.offset = s->size; dyn = htab->elf.dynamic_sections_created; - if (tls_type & (GOT_TLS_GD | GOT_TLS_IE)) + if (tls_type & (GOT_TLS_GD | GOT_TLS_IE | GOT_TLSDESC)) { int indx = 0; bool need_reloc = false; @@ -1334,6 +1342,14 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) if (need_reloc) htab->elf.srelgot->size += sizeof (ElfNN_External_Rela); } + + /* TLSDESC needs one dynamic reloc and two GOT slots. */ + if (tls_type & GOT_TLSDESC) + { + s->size += TLSDESC_GOT_ENTRY_SIZE; + /* TLSDESC always use dynamic relocs. */ + htab->elf.srelgot->size += sizeof (ElfNN_External_Rela); + } } else { @@ -1561,7 +1577,7 @@ riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) if (*local_got > 0) { *local_got = s->size; - if (*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE)) + if (*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE | GOT_TLSDESC)) { if (*local_tls_type & GOT_TLS_GD) { @@ -1575,6 +1591,11 @@ riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) if (bfd_link_dll (info)) srel->size += sizeof (ElfNN_External_Rela); } + if (*local_tls_type & GOT_TLSDESC) + { + s->size += TLSDESC_GOT_ENTRY_SIZE; + srel->size += sizeof (ElfNN_External_Rela); + } } else { @@ -1725,6 +1746,17 @@ tpoff (struct bfd_link_info *info, bfd_vma address) return address - elf_hash_table (info)->tls_sec->vma - TP_OFFSET; } +/* Return the relocation value for a static TLSDESC relocation. */ + +static bfd_vma +tlsdescoff (struct bfd_link_info *info, bfd_vma address) +{ + /* If tls_sec is NULL, we should have signalled an error already. */ + if (elf_hash_table (info)->tls_sec == NULL) + return 0; + return address - elf_hash_table (info)->tls_sec->vma; +} + /* Return the global pointer's value, or 0 if it is not in use. */ static bfd_vma @@ -1764,6 +1796,7 @@ perform_relocation (const reloc_howto_type *howto, case R_RISCV_GOT_HI20: case R_RISCV_TLS_GOT_HI20: case R_RISCV_TLS_GD_HI20: + case R_RISCV_TLSDESC_HI20: if (ARCH_SIZE > 32 && !VALID_UTYPE_IMM (RISCV_CONST_HIGH_PART (value))) return bfd_reloc_overflow; value = ENCODE_UTYPE_IMM (RISCV_CONST_HIGH_PART (value)); @@ -1774,6 +1807,8 @@ perform_relocation (const reloc_howto_type *howto, case R_RISCV_TPREL_LO12_I: case R_RISCV_TPREL_I: case R_RISCV_PCREL_LO12_I: + case R_RISCV_TLSDESC_LOAD_LO12: + case R_RISCV_TLSDESC_ADD_LO12: value = ENCODE_ITYPE_IMM (value); break; @@ -2192,8 +2227,8 @@ riscv_elf_relocate_section (bfd *output_bfd, bfd_vma relocation; bfd_reloc_status_type r = bfd_reloc_ok; const char *name = NULL; - bfd_vma off, ie_off; - bool unresolved_reloc, is_ie = false; + bfd_vma off, ie_off, desc_off; + bool unresolved_reloc, is_ie = false, is_desc = false; bfd_vma pc = sec_addr (input_section) + rel->r_offset; int r_type = ELFNN_R_TYPE (rel->r_info), tls_type; reloc_howto_type *howto = riscv_elf_rtype_to_howto (input_bfd, r_type); @@ -2496,6 +2531,7 @@ riscv_elf_relocate_section (bfd *output_bfd, case R_RISCV_NONE: case R_RISCV_RELAX: case R_RISCV_TPREL_ADD: + case R_RISCV_TLSDESC_CALL: case R_RISCV_COPY: case R_RISCV_JUMP_SLOT: case R_RISCV_RELATIVE: @@ -2843,6 +2879,22 @@ riscv_elf_relocate_section (bfd *output_bfd, relocation = dtpoff (info, relocation); break; + case R_RISCV_TLSDESC_LOAD_LO12: + case R_RISCV_TLSDESC_ADD_LO12: + if (rel->r_addend) + { + msg = _("%tlsdesc_lo with addend"); + r = bfd_reloc_dangerous; + break; + } + + if (riscv_record_pcrel_lo_reloc (&pcrel_relocs, relocation, rel, + input_section, info, howto, + contents)) + continue; + r = bfd_reloc_overflow; + break; + case R_RISCV_32: /* Non ABS symbol should be blocked in check_relocs. */ if (ARCH_SIZE > 32) @@ -2908,11 +2960,16 @@ riscv_elf_relocate_section (bfd *output_bfd, } break; + case R_RISCV_TLSDESC_HI20: + is_desc = true; + goto tls; + case R_RISCV_TLS_GOT_HI20: is_ie = true; - /* Fall through. */ + goto tls; case R_RISCV_TLS_GD_HI20: + tls: if (h != NULL) { off = h->got.offset; @@ -2925,12 +2982,16 @@ riscv_elf_relocate_section (bfd *output_bfd, } tls_type = _bfd_riscv_elf_tls_type (input_bfd, h, r_symndx); - BFD_ASSERT (tls_type & (GOT_TLS_IE | GOT_TLS_GD)); - /* If this symbol is referenced by both GD and IE TLS, the IE - reference's GOT slot follows the GD reference's slots. */ + BFD_ASSERT (tls_type & (GOT_TLS_IE | GOT_TLS_GD | GOT_TLSDESC)); + /* When more than one TLS type is used, the GD slot comes first, + then IE, then finally TLSDESC. */ ie_off = 0; - if ((tls_type & GOT_TLS_GD) && (tls_type & GOT_TLS_IE)) - ie_off = TLS_GD_GOT_ENTRY_SIZE; + if (tls_type & GOT_TLS_GD) + ie_off += TLS_GD_GOT_ENTRY_SIZE; + + desc_off = ie_off; + if (tls_type & GOT_TLS_IE) + desc_off += TLS_IE_GOT_ENTRY_SIZE; if ((off & 1) != 0) off &= ~1; @@ -3012,10 +3073,29 @@ riscv_elf_relocate_section (bfd *output_bfd, htab->elf.sgot->contents + off + ie_off); } } + + if (tls_type & GOT_TLSDESC) + { + /* TLSDESC is always handled by the dynamic linker and always need + * a relocation. */ + bfd_put_NN (output_bfd, 0, + htab->elf.sgot->contents + off + desc_off); + outrel.r_offset = sec_addr (htab->elf.sgot) + + off + desc_off; + outrel.r_addend = 0; + if (indx == 0) + outrel.r_addend = tlsdescoff (info, relocation); + outrel.r_info = ELFNN_R_INFO (indx, R_RISCV_TLSDESC); + riscv_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel); + } } BFD_ASSERT (off < (bfd_vma) -2); - relocation = sec_addr (htab->elf.sgot) + off + (is_ie ? ie_off : 0); + relocation = sec_addr (htab->elf.sgot) + off; + if (is_ie) + relocation += ie_off; + else if (is_desc) + relocation += desc_off; if (!riscv_record_pcrel_hi_reloc (&pcrel_relocs, pc, relocation, r_type, false)) @@ -3235,7 +3315,7 @@ riscv_elf_finish_dynamic_symbol (bfd *output_bfd, } if (h->got.offset != (bfd_vma) -1 - && !(riscv_elf_hash_entry (h)->tls_type & (GOT_TLS_GD | GOT_TLS_IE)) + && !(riscv_elf_hash_entry (h)->tls_type & (GOT_TLS_GD | GOT_TLS_IE | GOT_TLSDESC)) && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) { asection *sgot; diff --git a/ld/testsuite/ld-riscv-elf/tls.d b/ld/testsuite/ld-riscv-elf/tls.d index e7f20309bf1..6cf008ac7a0 100644 --- a/ld/testsuite/ld-riscv-elf/tls.d +++ b/ld/testsuite/ld-riscv-elf/tls.d @@ -2,13 +2,15 @@ #ld: --shared tmpdir/tlslib.so #readelf: -Wr -Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 5 entries: +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 7 entries: +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend [0-9a-f]+ +[0-9a-f]+ R_RISCV_TLS_DTPMOD64 +0 [0-9a-f]+ +[0-9a-f]+ R_RISCV_TLS_TPREL64 +4 +[0-9a-f]+ +[0-9a-f]+ R_RISCV_TLSDESC +4 [0-9a-f]+ +[0-9a-f]+ R_RISCV_TLS_DTPMOD64 +0+ sg1 \+ 0 [0-9a-f]+ +[0-9a-f]+ R_RISCV_TLS_DTPREL64 +0+ sg1 \+ 0 [0-9a-f]+ +[0-9a-f]+ R_RISCV_TLS_TPREL64 +0+ sg1 \+ 0 +[0-9a-f]+ +[0-9a-f]+ R_RISCV_TLSDESC +0+ sg1 \+ 0 Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entry: +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend diff --git a/ld/testsuite/ld-riscv-elf/tls.s b/ld/testsuite/ld-riscv-elf/tls.s index 79e9bc20374..7cbf5ea6c72 100644 --- a/ld/testsuite/ld-riscv-elf/tls.s +++ b/ld/testsuite/ld-riscv-elf/tls.s @@ -17,6 +17,13 @@ _start: la.tls.ie a0,sg1 add a0,a0,tp + /* GD (TLSDESC), global var */ +.desc1: + auipc a0, %tlsdesc_hi(sg1) + lw t0, %tlsdesc_load_lo(.desc1)(a0) + addi a0, a0, %tlsdesc_add_lo(.desc1) + jalr t0, t0, %tlsdesc_call(.desc1) + /* GD, local var */ la.tls.gd a0,sl1 call __tls_get_addr @@ -25,4 +32,11 @@ _start: la.tls.ie a0,sl1 add a0,a0,tp + /* GD (TLSDESC), local var */ +.desc2: + auipc a0, %tlsdesc_hi(sl1) + lw t0, %tlsdesc_load_lo(.desc2)(a0) + addi a0, a0, %tlsdesc_add_lo(.desc2) + jalr t0, t0, %tlsdesc_call(.desc2) + ret diff --git a/ld/testsuite/ld-riscv-elf/tlsbin.d b/ld/testsuite/ld-riscv-elf/tlsbin.d index cdcd51a9199..79b7ade405e 100644 --- a/ld/testsuite/ld-riscv-elf/tlsbin.d +++ b/ld/testsuite/ld-riscv-elf/tlsbin.d @@ -2,6 +2,11 @@ #ld: -no-pie tmpdir/tlslib.so #readelf: -Wr +Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 2 entries: + +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend +[0-9a-f]+ +[0-9a-f]+ R_RISCV_TLSDESC +4 +[0-9a-f]+ +[0-9a-f]+ R_RISCV_TLSDESC +0 + Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entry: +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend [0-9a-f]+ +[0-9a-f]+ R_RISCV_JUMP_SLOT +[0-9a-f]+ __tls_get_addr \+ 0 From patchwork Tue Feb 20 17:55:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 203729 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp572319dyc; Tue, 20 Feb 2024 10:02:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWgMXAKXWGbMf3KJdiLOB8aC0Ir9Ak/ZTgwl/UbgYLHeuTRIoXkY2p1SozvlfQtQTPF8ktsaxJ9eQAc9Q5/qqU1Nfx1Aw== X-Google-Smtp-Source: AGHT+IE1YcVsJh1ccvc5vMqhUJuU1Mh7ncVXlmPKNv23kKcX3EZULq0u9xiwVykQXT7fNQIe2j/i X-Received: by 2002:a0c:c990:0:b0:68f:5c6a:172e with SMTP id b16-20020a0cc990000000b0068f5c6a172emr9289640qvk.48.1708452157560; Tue, 20 Feb 2024 10:02:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708452157; cv=pass; d=google.com; s=arc-20160816; b=TeiFDTZBaXrz0l2ut32R2DgwJfpPHgB+qMDP0VxLq04go2QJdQm0sXpQqb2EkRvKUW hbwN+VFD8lgH1Ml9YHlVZU1vvFf1kKvGts3SyRkWpLY/+Z8/3b4KyURbCThIso/AyRbX /HBRNiAvDFEXT2MaYms+yeaxUySYXPdx/YEM/StkHmhqmeJwXVRx3v6BlPVeA7e1n0hK 8UADzPdgX8RHRf/cOV4DALEpKMipd7yJNYM9ezR+1/Ou7Lqw2doxFeSCRaXvtwlYOLRE Udv6tAGjx8tl0XkUDzu6S5IUKP5y+KSkMjDVLmss7vj6zkd8aPd/ODetZYz0e7F9DVjs 1V/A== 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=Cw/79Jt/roBBag0K16B2pqrdwn5Hy1kgaa6MBKODbv4=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=ze9Dl+oQp9oxfK7cM1uXux7/+ivC/3TQdxGfcJF5V9h8LhlTDilgmp93/eNYW74OzR UPMVH4KFpRwqalc+qtCtYacvTmzjhQgAJsgUJwXwS/6DEak6aQD2Cosl+vCagexjbucb eWxNITx1kKqbjSfcwGp9hkJ9x2ugW6GaR7bGCVKZpDPw+TyrvdWqueFY9Ch0SFqxDFPK 4PbJB464NqvWxP9MtB2PezLyxRBE9IEAhx586T5F3hT4EUVguvdTVkwqjneBPsVKxb3y yuT/4rG1O/a8Jz5xiMChgr26GZNHuZEdpvAguA62ZgrVUeBr7Nn4phg9ngtKRj2D2Kuq KcVQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BS24hpSq; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 o3-20020a0562140e4300b0068d15511a8dsi9166685qvc.74.2024.02.20.10.02.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 10:02:37 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.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=BS24hpSq; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 AE4D53857B95 for ; Tue, 20 Feb 2024 18:01:28 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.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 49A213858C36 for ; Tue, 20 Feb 2024 17:56:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49A213858C36 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 49A213858C36 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=1708451800; cv=none; b=X3YuKbak/QDkdfRp9W/2Sj23r9fgCHDThW0di0TK9l/Ge9egKEheCziSzwEiIjUfoF76uZm6kQsqlXzEo0kxiptcwqsrZrPlzsyHIy2RqJZFLClg5LVYgzrwLlZVl9Tg4z2SiIzPkuJEcPzZFUAne0WSStwHowtP9MDeXJm8v98= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451800; c=relaxed/simple; bh=5lpM9+5EUkJbSyvLZXvpURKYqmO+gjMAPoiecjewCyM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=cahGXHkyDHUHU0EgKF+QYNQzX/nev0gAZER8VK2b6QEc9oO2eQjiONWwJg+W86dP3MJNPGcOTQdAS01Ka5AtxjuMe9MnTWELT+WK1Nr9aWTtW81omKPhL9qSPqjUHA1CyvdXKZ0kio9/mnGdO7vfICGSdxIIErrBQlr1SPD4w20= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-5cdbc42f5efso1496440a12.0 for ; Tue, 20 Feb 2024 09:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708451796; x=1709056596; 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=Cw/79Jt/roBBag0K16B2pqrdwn5Hy1kgaa6MBKODbv4=; b=BS24hpSq0AZwHTqkcDbF7j9DKkdG/8ooYHhRaoUf+fcLR8/YCKrT2Wn03rH/WohhJK 69o89NHBnzYLCy0Zv04CAxqeGSQdzMRvRoLnzsuTjBGG4ksVAw8QpnY3rfX68Z84sku/ JzxCBTXLluNW4Js4ZvoFoiE+31UAYo1VFhOkRBTnpJ2JVvjhl4GHZsoRRwzx/TmNYpL9 00ibU/MK/OU+xqDaNAyzXCCxgr0dG2FzwHOTj8ZurwoLTktVwKFCX7dZdgeuQU8Ht8gD P68B7/KLO81m7DTfDZlc7e/oi9iE+Ruu1mcIZ5hGZgX2DVJxL1BrGlX4ZPkW1f+qNP2b lXzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708451796; x=1709056596; 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=Cw/79Jt/roBBag0K16B2pqrdwn5Hy1kgaa6MBKODbv4=; b=OFuxgQoeqtmbS2xNmf9X56FQhDGs5hRewp8ioorMZTS1CN+6+Z/lhamGP36eQDyxDI 5/GF1eCQE+BbfOyM7vF0qT4haq3yjpxj97NO29necBKZNFIUBm7XMoD9cVmnVBnK1Ep3 x5YaWvKZWQsri2nEVIfaaDcARSCGSUnPq9ahtYShwkL9m3rsx2i1M+ySawx1FOmDksyh Ksiu3Sge1+O7TV5fzZlBnmKkaEG/M3rAuB2NTAlobFOs9UQZy3ojgImz2vrGqIckc6WP I/+ber5d9PGeqt0p8EZuzLWfaa/3SgvBniOOX6QFCCE7RziGifuJTPysqjsNrQdcan9g X2SQ== X-Gm-Message-State: AOJu0YzYnm9ZcXiYAxyOr1+ZbyMedc6Q1BM8sL0IwJRSGqoF8YqFW7Ww BKzocoKGwi/qlj73W8jdc5DQnbcckQ9BdaBVI7fYIGZ0kC+97DlBxgQUthxrjEGZaA== X-Received: by 2002:a17:902:ea0f:b0:1db:eb9e:170b with SMTP id s15-20020a170902ea0f00b001dbeb9e170bmr7133662plg.0.1708451796274; Tue, 20 Feb 2024 09:56:36 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id o6-20020a170902d4c600b001dbcf63e406sm5848903plg.47.2024.02.20.09.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:56:35 -0800 (PST) From: Tatsuyuki Ishi To: binutils@sourceware.org Cc: i@maskray.me, nelson@rivosinc.com, rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH v4 6/9] RISC-V: Move STATIC_TLS handling into record_tls_type. Date: Wed, 21 Feb 2024 02:55:53 +0900 Message-ID: <20240220175556.304692-7-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220175556.304692-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20240220175556.304692-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 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, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791441929473442848 X-GMAIL-MSGID: 1791441929473442848 bfd/Changelog: * elfnn-riscv.c (riscv_elf_record_tls_type): Add bfd_link_info parameter and move code from below. (riscv_elf_check_relocs): Move STATIC_TLS handling into riscv_elf_record_tls_type. Add missing early return in the R_RISCV_TPREL_HI20 case. --- bfd/elfnn-riscv.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 16394110c6a..1594856ccef 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -663,12 +663,14 @@ riscv_elf_copy_indirect_symbol (struct bfd_link_info *info, } static bool -riscv_elf_record_tls_type (bfd *abfd, struct elf_link_hash_entry *h, +riscv_elf_record_tls_type (bfd *abfd, struct bfd_link_info *info, + struct elf_link_hash_entry *h, unsigned long symndx, char tls_type) { char *new_tls_type = &_bfd_riscv_elf_tls_type (abfd, h, symndx); *new_tls_type |= tls_type; + if ((*new_tls_type & GOT_NORMAL) && (*new_tls_type & ~GOT_NORMAL)) { (*_bfd_error_handler) @@ -676,6 +678,10 @@ riscv_elf_record_tls_type (bfd *abfd, struct elf_link_hash_entry *h, abfd, h ? h->root.root.string : ""); return false; } + + if ((*new_tls_type & GOT_TLS_IE) && bfd_link_dll (info)) + info->flags |= DF_STATIC_TLS; + return true; } @@ -839,27 +845,29 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, { case R_RISCV_TLS_GD_HI20: if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx) - || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLS_GD)) + || !riscv_elf_record_tls_type (abfd, info, h, r_symndx, + GOT_TLS_GD)) return false; break; case R_RISCV_TLS_GOT_HI20: - if (bfd_link_dll (info)) - info->flags |= DF_STATIC_TLS; if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx) - || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLS_IE)) + || !riscv_elf_record_tls_type (abfd, info, h, r_symndx, + GOT_TLS_IE)) return false; break; case R_RISCV_GOT_HI20: if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx) - || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_NORMAL)) + || !riscv_elf_record_tls_type (abfd, info, h, r_symndx, + GOT_NORMAL)) return false; break; case R_RISCV_TLSDESC_HI20: if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx) - || !riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLSDESC)) + || !riscv_elf_record_tls_type (abfd, info, h, r_symndx, + GOT_TLSDESC)) return false; break; @@ -949,8 +957,9 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, /* This is not allowed in the pic, but okay in pie. */ if (!bfd_link_executable (info)) return bad_static_reloc (abfd, r_type, h); - if (h != NULL) - riscv_elf_record_tls_type (abfd, h, r_symndx, GOT_TLS_LE); + if (h != NULL + && !riscv_elf_record_tls_type (abfd, info, h, r_symndx, GOT_TLS_LE)) + return false; break; case R_RISCV_HI20: From patchwork Tue Feb 20 17:55:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 203722 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp568799dyc; Tue, 20 Feb 2024 09:59:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW1HXZgnBZZ09F89V5z1TUMgieBXVqla3j54Fh6yq0o1ao/onTnUw4q5cymBzUzur7wWZOsr22TFh1XF2wFEYZfyIgcSQ== X-Google-Smtp-Source: AGHT+IFV6FdnCCcEKc90j5pDwcO3/BYnxukh6qL89y+F+uLRS/uQdPGT3Tp0i6FgIYEalsRGvGfR X-Received: by 2002:a0d:e2d6:0:b0:607:8c84:d474 with SMTP id l205-20020a0de2d6000000b006078c84d474mr15775417ywe.31.1708451949595; Tue, 20 Feb 2024 09:59:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708451949; cv=pass; d=google.com; s=arc-20160816; b=xelbfFqbUGIVKhI+I2cDQ3hGpi7MILgBM+XHJqQgQVMC6IXL0o2HlbqpeH19/giy9/ OC1uhWd8MxcGWoJHGb9O1zgNh2PJMmm5CU8q2QM4AL3Xg5YqyLe4c21n9c75KQm6tLaW 3qY7ZHJ4LtqmE81lGKI+xE7jR6ofKL/eSK/0jKrZjTDpxiuawjNtO1cSA5Q5p8HXUGi3 pPhyLqhiCsXzgPuYP0fIPKwu/mLL77on32oio+9YSD3OcyM4v3EKHibZS6afwMS0u6u6 1s4f1FCp9zLKm59b4cfrsPEIt7a9+RsghyF08TnYeSbWR7JSyKJUUJaYxsYTNkL9uM5L IS5Q== 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=h/yOCjAubBXr4UQpG8YHynJ3eSjL8rvvoG3ahJeSLJI=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=A6OePJqL7E7J7V0nb5R4K+DEkIxPY2Fq5xRYmrJdvEpPz5XRyPMM+ZOnUlkuSIXuPo XsUH0iqYqVoX4ur0Wnmb7Q5V1LgfTTFkuhO0u76k7fk6XxNQX1yrbc1v/I8N4mK/z1Xl JHji7sALU7FfnH3nm2DnOsb6iKMqCm3opkNr8SBUVFdbLreY6Xc023DjhomdFHXbduHv vMK2WCrGo2YePdjqEmTUkeOgBSpimI4V+tiplanYclPJ1+PtJ9uguQViv7HekzBv1wuH S0VWsJto3RREGgYs+1l+ZjggaNxr2JRst3bwLaCz5QkwrSuCVuV3JTyzJ7XxakBWpuTd unVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SyyZP5d6; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i7-20020ac87647000000b0042e2867d1d0si1794338qtr.532.2024.02.20.09.59.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:59:09 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SyyZP5d6; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 ED9973858006 for ; Tue, 20 Feb 2024 17:59:06 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@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 C0F153858D33 for ; Tue, 20 Feb 2024 17:56:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0F153858D33 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 C0F153858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451804; cv=none; b=PXV4LOv7p6yunWkv2BEpUS21+/OlfiUvr5LlU4FDLX5vVopZHU8096Aunr44w+TTtkiuJCgD///OyuOQbDO6/+OwA5B/trd41HqJBul5d7vhMVL52hRQzAFg8op3Ym4BnEAz0xL+Kc036kF8tCujEkY8fYVfuZIQUycCyzvSciA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451804; c=relaxed/simple; bh=GMNky/qO4h4VcvnGoDdEsj6/ofnAA/Df7Y3QB4bv9ks=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Hh/ISyx18Wd932LpcYYp9xnyn/Zse8Y8jJQbZMdfshtfrZhJf2vjVqjOsrmh1pKAh8zHzL+SUscOHGAw8owQi2RcEsLIGik3jwWK4AX0zIhD9HpNSZzRbpFBYCI7BN7LJeuW75HATMM/0aMUYMZpI7f0WFRzZlv4zQUqEVHlTxs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dbdd58ca83so602775ad.1 for ; Tue, 20 Feb 2024 09:56:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708451799; x=1709056599; 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=h/yOCjAubBXr4UQpG8YHynJ3eSjL8rvvoG3ahJeSLJI=; b=SyyZP5d6RyaVeXzGFLoTjOpNZXs9yVrlNrc4LKgvpGumJB54eMt1xFTjhqD6rricpC e7kg7Nd/yraQuBI6E/g1MFcVJXMYwxHEDx7D0jFx0fElpXICOWHdiUCB8N4qVTqPpMAX eljzqu/QiRSok/cs4VWs92f3XfzlNW04673DUgZqPN0Cvyk0ceaqz2ZDUdFQ1yLwsNQ8 tdyJVXgQytHPm/yZvBOLmhKUVtAyokw3z/3OyK1OSy3YNDCtnQ6lD0i8xeNGznMjU0BH GvsnBersYqnMEWuMjS2wNk95lHeqqShFwSVj1BUBbHjy/l21OxPLieGFJGTdyP425g+O Kskw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708451799; x=1709056599; 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=h/yOCjAubBXr4UQpG8YHynJ3eSjL8rvvoG3ahJeSLJI=; b=VT7iOfg/RW+b9UVZihoGXoWEspmNz6lyK755Gt8R0Iw8q05Dvwdn92ZetTfzajxc9J ExnGu9J9hlmEWb39M1UfUKQbzPIeM2ERD7cJYugOJ4Zl0JMSNY1v4BOumShSiCpFWHDv XFncAcsI0g91xnEUXZQiWytHkHL9rhKkBaQTh6NeQtgObS+BNInI8pnBsIa4CnxJEn1u R/hX651xCzCWbKBN3c0Q+khBOS8/hp0GaV1sui4DK1hDFy0r3H4cuqwzoQvAJf+fR+nX /2ghlxWjUVTwoVKsg+G89zlXveg2vtS2HaCkxm/yQh7f18XmppPraJYQ0Uv8MpDY3loT wmXw== X-Gm-Message-State: AOJu0YytCfZdLjp+9P2p8FQIW18noBumgsDC80db6zDJP31nISqwIsBB OGbqYQobK3GORVHpNl7lQ9MURAAxFFxkODR/H8D+39sDyMApdLulcXxnTNidNGurGA== X-Received: by 2002:a17:902:b082:b0:1dc:3c:fb67 with SMTP id p2-20020a170902b08200b001dc003cfb67mr4843555plr.5.1708451798792; Tue, 20 Feb 2024 09:56:38 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id v6-20020a170903238600b001d97fe26d47sm6487737plh.34.2024.02.20.09.56.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:56:38 -0800 (PST) From: Tatsuyuki Ishi To: binutils@sourceware.org Cc: i@maskray.me, nelson@rivosinc.com, rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH v4 7/9] RISC-V: Unify TLS handling in check_relocs. Date: Wed, 21 Feb 2024 02:55:54 +0900 Message-ID: <20240220175556.304692-8-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220175556.304692-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20240220175556.304692-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 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, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791441711782417644 X-GMAIL-MSGID: 1791441711782417644 With the introduction of transition, multiple relocation types may map to GOT_TLS_IE or GOT_TLS_LE and it makes more sense to unify the code path to perform checks common to them. bfd/ * elfnn-riscv.c (riscv_elf_check_relocs): Merge switch cases for TLS relocs. --- bfd/elfnn-riscv.c | 64 +++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 1594856ccef..1fbb0698ce1 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -662,6 +662,24 @@ riscv_elf_copy_indirect_symbol (struct bfd_link_info *info, _bfd_elf_link_hash_copy_indirect (info, dir, ind); } +static char +riscv_elf_tls_type_from_hi_reloc (unsigned int r_type) +{ + switch (r_type) + { + case R_RISCV_TLS_GD_HI20: + return GOT_TLS_GD; + case R_RISCV_TLS_GOT_HI20: + return GOT_TLS_IE; + case R_RISCV_TLSDESC_HI20: + return GOT_TLSDESC; + case R_RISCV_TPREL_HI20: + return GOT_TLS_LE; + default: + abort (); + } +} + static bool riscv_elf_record_tls_type (bfd *abfd, struct bfd_link_info *info, struct elf_link_hash_entry *h, @@ -843,19 +861,26 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, switch (r_type) { - case R_RISCV_TLS_GD_HI20: - if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx) - || !riscv_elf_record_tls_type (abfd, info, h, r_symndx, - GOT_TLS_GD)) - return false; - break; + case R_RISCV_TLS_GD_HI20: + case R_RISCV_TLS_GOT_HI20: + case R_RISCV_TLSDESC_HI20: + case R_RISCV_TPREL_HI20: + { + char tls_type = riscv_elf_tls_type_from_hi_reloc (r_type); - case R_RISCV_TLS_GOT_HI20: - if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx) - || !riscv_elf_record_tls_type (abfd, info, h, r_symndx, - GOT_TLS_IE)) - return false; - break; + /* Local exec is only allowed for executables. */ + if (tls_type == GOT_TLS_LE && !bfd_link_executable (info)) + return bad_static_reloc (abfd, r_type, h); + + if (tls_type != GOT_TLS_LE + && !riscv_elf_record_got_reference (abfd, info, h, r_symndx)) + return false; + if ((tls_type != GOT_TLS_LE || h != NULL) + && !riscv_elf_record_tls_type (abfd, info, h, r_symndx, + tls_type)) + return false; + break; + } case R_RISCV_GOT_HI20: if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx) @@ -864,12 +889,6 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, return false; break; - case R_RISCV_TLSDESC_HI20: - if (!riscv_elf_record_got_reference (abfd, info, h, r_symndx) - || !riscv_elf_record_tls_type (abfd, info, h, r_symndx, - GOT_TLSDESC)) - return false; - break; case R_RISCV_CALL: case R_RISCV_CALL_PLT: @@ -953,15 +972,6 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, break; goto static_reloc; - case R_RISCV_TPREL_HI20: - /* This is not allowed in the pic, but okay in pie. */ - if (!bfd_link_executable (info)) - return bad_static_reloc (abfd, r_type, h); - if (h != NULL - && !riscv_elf_record_tls_type (abfd, info, h, r_symndx, GOT_TLS_LE)) - return false; - break; - case R_RISCV_HI20: if (bfd_link_pic (info)) return bad_static_reloc (abfd, r_type, h); From patchwork Tue Feb 20 17:55:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 203728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp571786dyc; Tue, 20 Feb 2024 10:02:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUJAVaOWj2hb8CHYIS223nmZ6v0Iuvfc9kA5S8poC0TpNAue9z7+QjIdWcOsQFPtJZIPrDI82rsaNTXR7fKndbzenlAVw== X-Google-Smtp-Source: AGHT+IEka7K+iWo2ovyfNjcd1WxXKywH16LBy1FtdU0yxG9YGzdZPNqqEROGlhv0Ed6+afestG/C X-Received: by 2002:a0c:da8d:0:b0:68f:721e:9ad1 with SMTP id z13-20020a0cda8d000000b0068f721e9ad1mr5811539qvj.65.1708452131791; Tue, 20 Feb 2024 10:02:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708452131; cv=pass; d=google.com; s=arc-20160816; b=k5bqgYaNi7gVKUg8oTfJOx2pz6eAzNn5uzimFZA0hvOicHKoHqbjCRdmVcaGlR1Q0q U7uvlranzPeypRkGOIfXmMb7+gsUEl2L0CKFndMXxmJzwwDOelB+jj49n3XG48Fe/YOq gycYn4xXGnmHELzhXUgyMhnQM89L2jGjj/yDqkfFTrl5h/9FgtRhJBjLlRATTAuSmNKX muaOn8s4rauZiE/g5aq/rb5YtP6KGdno+pMos6e21SWduv4lgNed0cW8P9k6OHTxfgOU 0G/wJUYBN+aWXQEpFa60XWwUUddaY8XHeyx1R3UqO3WYKLYoJEAxfVAy9evL2xwyDA0e 884w== 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=DNrOBFf8/pwu+DtubgIpDhc+heOFu5Yj769tqGEEopQ=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=nLx6NAah9PwTCipCOdUNa4RxCbs85ui62F5v+IVSPRQLlESUUbzJtjbBPNKr0wQw0l 61iBQO5oBMa/ky+qqyV8rX6qJs/CaCZKrKm3q0qz/apct+NZ6DHm6X6YyFoPH3IWQosB uG8GWzwqpR+ZznnPEOpM1kfZTtWNu8daZ0XAFkLTjBSd71F8+KxZOrjKk1RSdGjAV8vU xR7iRfU7BZzetDy7nXBmKxgVGA/9+B4ElIo734nxG3+kBV/9zV8dRFxh3Vr80MGne94g 7EyPLYDwVkE2IHoB2AQbdCD8gwF5VX/I39N8nNTz3YNsO/N3L7JPZ9MJM5IpTHmkrC3v blCg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="JBWo/BeZ"; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gw13-20020a0562140f0d00b0068f3fdcaf25si9372313qvb.243.2024.02.20.10.02.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 10:02:11 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="JBWo/BeZ"; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 D81F23861839 for ; Tue, 20 Feb 2024 18:01:01 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-oo1-xc34.google.com (mail-oo1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) by sourceware.org (Postfix) with ESMTPS id 8B43D3858D28 for ; Tue, 20 Feb 2024 17:56:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8B43D3858D28 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 8B43D3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451806; cv=none; b=qzOor3OfCkjyKaQfGbMjT1UdNEEJIo6O1Wg0Ziej8iVBNIt/a9P/NeNpyPznzYmV+inv9M/q+2NBH7sRoG2oWL/DCV66FBCYjb4zQj9aa0aywE/EkK6acagx10lRkVaZAV5OjjbLdBAZDnOJNmG3rz6SH6zjyyaSaOMmnLuQpqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451806; c=relaxed/simple; bh=6pm6TK+hpvuC3A/32SZ46Lb1R6SO1q0+TTH9x7f8bfw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wPreFkg0AKvY9foqjMX7gUZshDODdY9FfnGlbEpqPfWHGOrl0sYzUib8kPFaQ17HO4f86k+pKQ/DsaPcsqQpIe6yMQtNfJCbjQqyyrNo4gMtZHfNJZIfJgyUiyIWBxExyiiWgTbHhNGs1o1VFdAJNHwd1YWjcnvu0yQNbIeUp08= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-59fcf83f92fso189659eaf.1 for ; Tue, 20 Feb 2024 09:56:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708451802; x=1709056602; 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=DNrOBFf8/pwu+DtubgIpDhc+heOFu5Yj769tqGEEopQ=; b=JBWo/BeZsCfasl65RRSAG8OdttbSceZJWjNIBpULCxKWcwbKj3GQaVZO/v3yOBqot6 znMigi9ebmdFZgjzZ3BWkCDIHPWhBLyx6zuJv1nQiMs2Ej31u9ds2McGZHilBjPHnMdF 94DuJKPt/dkD4q1vuTo4S0bLTFOj64t0tBHrPWECPOgZ8HRGT3Ny+Jzg94bE+2/kWhkO 5hQwigQNUqHrpT9c/Ha7klzG1yIkVUhKg4lWqVZAMj1OL/i24UdJmk7Zf5SVYVU8SVy9 nn1xvaMX+6LgFRxHDDK701XLC23KbMa18IbDrrKhB2rwrk5qVjz0NEYH8SOwgb2pzUVc p02g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708451802; x=1709056602; 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=DNrOBFf8/pwu+DtubgIpDhc+heOFu5Yj769tqGEEopQ=; b=XD4cQ4NgUM5hBT31IJGCEvZZ44CQVJ7FjyfeQrDbJHtlyjRmJusXy2erU1atugD1pm 6XUmZQhlACz78PonB3+PJPQP72JtOgHjwUoaEZQHDb/afPG1zkEgP8xefOoReNAhmkud BCZ/smqmN/GDgheMRFtaBAtGZwTzsrUHmeg3yDdIbs2GZBgcmhhNkwDHkhdMA//2IgaH 2KAg9u2TqAIY0yP1tHBiVGx7o8p13xKsTfJx3qPE0eDQXMvIHgU0f1a0HPSH1Q7YIns/ pcDfs+418E++qfZ83BEKfq133ywIIxo3y5gu2SsvKmVUPZMQgasusNBd0WvabR3q+aHs pKmA== X-Gm-Message-State: AOJu0YzOqvM+U7sdeQfgA5XdNxEXNWrIMww0fgqmLmwMOcPUMxUNpHPc ezYHFKbNjHrchBLCb1TRTFe7e+n6Hy2BfePL8+eIdbCAXcJoN2u8H3tY7bXOFcEgdg== X-Received: by 2002:a05:6358:e49a:b0:178:9f1d:65e3 with SMTP id by26-20020a056358e49a00b001789f1d65e3mr14584137rwb.0.1708451801820; Tue, 20 Feb 2024 09:56:41 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id b186-20020a6334c3000000b005dc120fa3b2sm6768549pga.18.2024.02.20.09.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:56:41 -0800 (PST) From: Tatsuyuki Ishi To: binutils@sourceware.org Cc: i@maskray.me, nelson@rivosinc.com, rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH v4 8/9] RISC-V: Add elf_link_hash_entry to relax_func args. Date: Wed, 21 Feb 2024 02:55:55 +0900 Message-ID: <20240220175556.304692-9-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220175556.304692-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20240220175556.304692-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 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, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791441902528586743 X-GMAIL-MSGID: 1791441902528586743 bfd/ * elfnn-riscv.c (riscv_pcgp_hi_reloc): Add a field for hash_entry. (riscv_record_pcgp_hi_reloc): Add argument and record the hash_entry. (_bfd_riscv_relax_*): Add unused hash_entry argument. (_bfd_riscv_relax_pc): Also record the hash_entry, for consistency (but it is not used by the LO reloc handling). (_bfd_riscv_relax_section): Move h to outer scope and pass into relax helpers. --- bfd/elfnn-riscv.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 1fbb0698ce1..acc45ebb549 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -4235,6 +4235,7 @@ struct riscv_pcgp_hi_reloc bfd_vma hi_addr; unsigned hi_sym; asection *sym_sec; + struct elf_link_hash_entry *h; bool undefined_weak; riscv_pcgp_hi_reloc *next; }; @@ -4295,6 +4296,7 @@ static bool riscv_record_pcgp_hi_reloc (riscv_pcgp_relocs *p, bfd_vma hi_sec_off, bfd_vma hi_addend, bfd_vma hi_addr, unsigned hi_sym, asection *sym_sec, + struct elf_link_hash_entry *h, bool undefined_weak) { riscv_pcgp_hi_reloc *new = bfd_malloc (sizeof (*new)); @@ -4305,6 +4307,7 @@ riscv_record_pcgp_hi_reloc (riscv_pcgp_relocs *p, bfd_vma hi_sec_off, new->hi_addr = hi_addr; new->hi_sym = hi_sym; new->sym_sec = sym_sec; + new->h = h; new->undefined_weak = undefined_weak; new->next = p->hi; p->hi = new; @@ -4607,6 +4610,7 @@ riscv_relax_resolve_delete_relocs (bfd *abfd, typedef bool (*relax_func_t) (bfd *, asection *, asection *, struct bfd_link_info *, + struct elf_link_hash_entry *, Elf_Internal_Rela *, bfd_vma, bfd_vma, bfd_vma, bool *, riscv_pcgp_relocs *, @@ -4617,6 +4621,7 @@ typedef bool (*relax_func_t) (bfd *, asection *, asection *, static bool _bfd_riscv_relax_call (bfd *abfd, asection *sec, asection *sym_sec, struct bfd_link_info *link_info, + struct elf_link_hash_entry *_h ATTRIBUTE_UNUSED, Elf_Internal_Rela *rel, bfd_vma symval, bfd_vma max_alignment, @@ -4723,6 +4728,7 @@ _bfd_riscv_relax_lui (bfd *abfd, asection *sec, asection *sym_sec, struct bfd_link_info *link_info, + struct elf_link_hash_entry *_h ATTRIBUTE_UNUSED, Elf_Internal_Rela *rel, bfd_vma symval, bfd_vma max_alignment, @@ -4836,6 +4842,7 @@ _bfd_riscv_relax_tls_le (bfd *abfd, asection *sec, asection *sym_sec ATTRIBUTE_UNUSED, struct bfd_link_info *link_info, + struct elf_link_hash_entry *_h ATTRIBUTE_UNUSED, Elf_Internal_Rela *rel, bfd_vma symval, bfd_vma max_alignment ATTRIBUTE_UNUSED, @@ -4878,6 +4885,7 @@ static bool _bfd_riscv_relax_align (bfd *abfd, asection *sec, asection *sym_sec, struct bfd_link_info *link_info, + struct elf_link_hash_entry *_h ATTRIBUTE_UNUSED, Elf_Internal_Rela *rel, bfd_vma symval, bfd_vma max_alignment ATTRIBUTE_UNUSED, @@ -4938,6 +4946,7 @@ _bfd_riscv_relax_pc (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, asection *sym_sec, struct bfd_link_info *link_info, + struct elf_link_hash_entry *_h, Elf_Internal_Rela *rel, bfd_vma symval, bfd_vma max_alignment, @@ -5058,6 +5067,7 @@ _bfd_riscv_relax_pc (bfd *abfd ATTRIBUTE_UNUSED, symval, ELFNN_R_SYM(rel->r_info), sym_sec, + _h, undefined_weak); /* Delete unnecessary AUIPC and reuse the reloc. */ *again = true; @@ -5147,6 +5157,7 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec, /* Examine and consider relaxing each reloc. */ for (i = 0; i < sec->reloc_count; i++) { + struct elf_link_hash_entry *h = NULL; asection *sym_sec; Elf_Internal_Rela *rel = relocs + i; relax_func_t relax_func; @@ -5249,7 +5260,6 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec, else { unsigned long indx; - struct elf_link_hash_entry *h; indx = ELFNN_R_SYM (rel->r_info) - symtab_hdr->sh_info; h = elf_sym_hashes (abfd)[indx]; @@ -5351,7 +5361,7 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec, symval += sec_addr (sym_sec); - if (!relax_func (abfd, sec, sym_sec, info, rel, symval, + if (!relax_func (abfd, sec, sym_sec, info, h, rel, symval, max_alignment, reserve_size, again, &pcgp_relocs, undefined_weak)) goto fail; From patchwork Tue Feb 20 17:55:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 203725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp569737dyc; Tue, 20 Feb 2024 10:00:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW65CibnBbSP+BjGdQhG3fYV9VjLQxfeMZnBTn6O1Yi6hppuU+j64vBjTbgvy4VrqElh/a1xyH3fuJHB09XBZp0DyhVpw== X-Google-Smtp-Source: AGHT+IHqEyUAkltceRboilAGVxkkI8knrtYLFD/vg1FRD+PVJf0K+VX/34m73oR/YF9eHNeNuBDE X-Received: by 2002:a05:622a:1b91:b0:42c:74f8:1221 with SMTP id bp17-20020a05622a1b9100b0042c74f81221mr22576491qtb.33.1708452031762; Tue, 20 Feb 2024 10:00:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708452031; cv=pass; d=google.com; s=arc-20160816; b=ZVGLtxjuoq9iKcSKneG6767rFAgAPFLsVQIKB5dbFqx85n9zTT+mNKv6MsL+wi11Mc zmMCz11N4+NU+esLa3fzU1kpy5oC8oIaOAzytwbC3jFIE9VvlIMcnk8o4LO1q6kz7Vq7 ylfa+mvqHUtDNGbZV2/r79Iqyn5sxEyeuvFFTRqPhyCEM5AWMZvWlm/8ABJuHWUi9Mu1 gSO5XeZpPbi/fOtgtu0DM7TGnOscng/bMOORGM+AFYB6LXTlLEv/fzYzje1s1WHxn8Fz GDYFG5RzetgT5B9dW2nmHktwnO1clv5pg6BtibV/89j6Q3LDgDmRvvNi3yfaFkPXHpU4 LOUA== 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=+Ln9UYSSJWhdsfTwpxR6EQ7IGvtB7+h0kd4YhBcUoZM=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=dNQFkg/3ajwMo6GM9DsPWejTcVvDE17Kz+qTksRO9tv4bbblVpDaS5QTQHf/m/sTz5 G/kszrms9xS2jqdnPoVB2mVgiQpBjcjDY9qjdMCMxyOdwB1WrsaDph1QEsbwlJVZBuh8 LpmMT20EbmM/s1h9HAtp3XkCGg9mPoZGjbBGCJlqveckz0uhhwvKNPhaXu0WDFeWSjha 7Ioc0bSi6TshLSQmlLSjRx7ZBMVcFYlXfs8B1aVGJ+ZmqpyMob11tiqmNqiu0qSmDZaJ UuzZCYWznkXXEyejuMJ2jtKrGwahpFNa2nEGRaCpcSIKKWXwb3BOHs41hBYkO04pt4tN 0qnw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=coBoFvc0; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y10-20020a05622a004a00b0042da7adb8aasi9916314qtw.267.2024.02.20.10.00.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 10:00:31 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=coBoFvc0; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.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 BE9A93857BBC for ; Tue, 20 Feb 2024 18:00:04 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id DD6E2385840D for ; Tue, 20 Feb 2024 17:56:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DD6E2385840D 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 DD6E2385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::532 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451809; cv=none; b=uQfZEQPg5p9slOTKAJd4674lQdJ5NF54R4zM4zu0WtYcjFhcvxEtrmTzSbJ+q8ZXUOm8uRYvAIhQB1up0DvbtYrTb1yrKA4LJNPDfs7V9WUGe93YrQrMbWUDVZY3mU+UsJXBVVSbiPMmPSC3ImG9z7m/CA4N2jEls1u6UHK0ya4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451809; c=relaxed/simple; bh=VCwv3Ja9QBAkvrxo5Uw92mo0i5HSgnHaOwttCVpc+Bg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=f3dXNdlUJ6c2SdD6eM7RPiIn4yhYpFX7MIuMNayiiihW2IWYWfXjY60hluy5O4DQfzUBr634hCFGmNzm0A+9XrXqvnrXVKWPIKirpraXrGwN2b+w+zLKmzDEDlTHojeK0pSK0jHAyDWQZUtq2Jtbw2h5nh2IPdqEaJTV4igJmSQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-55b5a37acb6so1702827a12.0 for ; Tue, 20 Feb 2024 09:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708451805; x=1709056605; 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=+Ln9UYSSJWhdsfTwpxR6EQ7IGvtB7+h0kd4YhBcUoZM=; b=coBoFvc0yW30MsaKqSbOVoEyPaBKhsXGmPOSZMkLgYM17ctcDRTn0fpP7xiA59Wwxr vic2e+lUqbHAROJHVfrzeBBAPLcck6vIpY5ghV8v1T56g2kynavg0pkVLgM6tU3BcBy6 lGQUD1ktGAXxC59P71DUFKeluRVp1QYJFkLjHD96tlp5m6zfXu9u5edA6dQAbvk/o0Jr ozf1Jvytgv34svafUZLjoYlWf/g9lVJ6jaQtueMZqni89ZFCzulQ7zaxKZXZUaPxhBRp EjoHCz1RuicKTrPYhc9gQUf4DRoTczdJOOt4qXLwP9nHIeVf/KFFFEa063A6bB2FsE5j CqiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708451805; x=1709056605; 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=+Ln9UYSSJWhdsfTwpxR6EQ7IGvtB7+h0kd4YhBcUoZM=; b=ddn7abooiQ85tjsrUAWu+CT/buHGbxsx5uQR4iSX6MgmBQFt81OWULFAl7wCmpb6Or G3q5+tdYx+VUNBiu+2w0n/ALT4stnmnWNOHhRzI1GFlNwKmTOI54qQmLqYVyM6/IfFxo 2DZviZ+i5NNIuMx7S7rvCKWzrzDMe4QLUdk6p7TLRqei6ysxQFt2pnIryh+UJ75aTbl3 3KZ+YBhtD+Dn0S9Ro5e5fp54MFsfgtTKCMLr71TW5k5/SPk4OoK5hDtslclrX+3fpi2y FMNgmyzYaCzokKifqvetqvD6/NIkTjfRn6bpB/MsQwXAjewNBwpsYiTOoVU5eFrc1fpI o1Bw== X-Gm-Message-State: AOJu0YxUE0+cCxp5M6clhGwCkhVekh7hTbERBLngVyWgCzbglW0o5n/g GojNUXsFHY7oaWzQWUImqDea47H/rgwMctT6SXOFWUPihZofi5iS3dVqi01J6zc4vw== X-Received: by 2002:a05:6a21:999c:b0:1a0:9abd:2801 with SMTP id ve28-20020a056a21999c00b001a09abd2801mr10187689pzb.3.1708451805166; Tue, 20 Feb 2024 09:56:45 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id fa7-20020a056a002d0700b006e489e6019esm137371pfb.39.2024.02.20.09.56.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:56:44 -0800 (PST) From: Tatsuyuki Ishi To: binutils@sourceware.org Cc: i@maskray.me, nelson@rivosinc.com, rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH v4 9/9] RISC-V: Introduce TLSDESC relaxation. Date: Wed, 21 Feb 2024 02:55:56 +0900 Message-ID: <20240220175556.304692-10-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220175556.304692-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20240220175556.304692-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791441797534853304 X-GMAIL-MSGID: 1791441797534853304 For now, only the 2 instruction (long) forms. This allows static binaries to correctly execute when TLSDESC is used. bfd/ * elfnn-riscv.c (riscv_elf_tls_type_from_hi_reloc): Decide TLS type based on relaxation eligibility as well. (riscv_elf_check_relocs): Pass the required eligibility information to riscv_elf_tls_type_from_hi_reloc. (perform_relocation): Handle encoding for TLSDESC relaxation relocations. (riscv_elf_relocate_section): Emit relaxation instruction sequence. (_bfd_riscv_relax_tlsdesc): Added for handling of relaxable TLSDESC relocs. (_bfd_riscv_relax_section): Call _bfd_riscv_relax_tlsdesc when eligible. * elfxx-riscv.c (howto_table_internal): Add internal relocations for TLSDESC -> LE / IE relaxation. include/ elf/riscv.h: Add internal relocations, same as above. opcode/riscv.h: Add X_A0 for use in TLSDESC relaxation sequence. ld/ * testsuite/ld-riscv-elf/tlsbin.d: Remove TLSDESC relocs from expectation to now that we have relaxation. --- v4: Remove addend from lo-hi calculation since it's required to be 0. bfd/elfnn-riscv.c | 144 ++++++++++++++++++++++++++++- bfd/elfxx-riscv.c | 55 +++++++++++ include/elf/riscv.h | 16 ++-- include/opcode/riscv.h | 1 + ld/testsuite/ld-riscv-elf/tlsbin.d | 5 - 5 files changed, 207 insertions(+), 14 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index acc45ebb549..43db8f1b5c0 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -663,8 +663,12 @@ riscv_elf_copy_indirect_symbol (struct bfd_link_info *info, } static char -riscv_elf_tls_type_from_hi_reloc (unsigned int r_type) +riscv_elf_tls_type_from_hi_reloc (struct bfd_link_info *info, + unsigned int r_type, + struct elf_link_hash_entry *h, + bool can_relax) { + bool local_exec = SYMBOL_REFERENCES_LOCAL (info, h); switch (r_type) { case R_RISCV_TLS_GD_HI20: @@ -672,7 +676,10 @@ riscv_elf_tls_type_from_hi_reloc (unsigned int r_type) case R_RISCV_TLS_GOT_HI20: return GOT_TLS_IE; case R_RISCV_TLSDESC_HI20: - return GOT_TLSDESC; + if (!can_relax || !bfd_link_executable (info)) + return GOT_TLSDESC; + else + return local_exec ? GOT_TLS_LE : GOT_TLS_IE; case R_RISCV_TPREL_HI20: return GOT_TLS_LE; default: @@ -866,7 +873,10 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, case R_RISCV_TLSDESC_HI20: case R_RISCV_TPREL_HI20: { - char tls_type = riscv_elf_tls_type_from_hi_reloc (r_type); + bool can_relax = rel != relocs + sec->reloc_count - 1 + && ELFNN_R_TYPE ((rel + 1)->r_info) == R_RISCV_RELAX + && rel->r_offset == (rel + 1)->r_offset; + char tls_type = riscv_elf_tls_type_from_hi_reloc (info, r_type, h, can_relax); /* Local exec is only allowed for executables. */ if (tls_type == GOT_TLS_LE && !bfd_link_executable (info)) @@ -1816,6 +1826,8 @@ perform_relocation (const reloc_howto_type *howto, case R_RISCV_TLS_GOT_HI20: case R_RISCV_TLS_GD_HI20: case R_RISCV_TLSDESC_HI20: + case R_RISCV_TLSDESC_LE_HI: + case R_RISCV_TLSDESC_IE_HI: if (ARCH_SIZE > 32 && !VALID_UTYPE_IMM (RISCV_CONST_HIGH_PART (value))) return bfd_reloc_overflow; value = ENCODE_UTYPE_IMM (RISCV_CONST_HIGH_PART (value)); @@ -1828,6 +1840,8 @@ perform_relocation (const reloc_howto_type *howto, case R_RISCV_PCREL_LO12_I: case R_RISCV_TLSDESC_LOAD_LO12: case R_RISCV_TLSDESC_ADD_LO12: + case R_RISCV_TLSDESC_LE_LO: + case R_RISCV_TLSDESC_IE_LO: value = ENCODE_ITYPE_IMM (value); break; @@ -2834,6 +2848,35 @@ riscv_elf_relocate_section (bfd *output_bfd, r = bfd_reloc_overflow; break; + case R_RISCV_TLSDESC_IE_HI: + { + bfd_vma insn = MATCH_AUIPC | (X_A0 << OP_SH_RD); + relocation = dtpoff (info, relocation); + bfd_putl32 (insn, contents + rel->r_offset); + break; + } + case R_RISCV_TLSDESC_IE_LO: + { + bfd_vma insn = MATCH_LREG | (X_A0 << OP_SH_RD) | (X_A0 << OP_SH_RS1); + relocation = dtpoff (info, relocation); + bfd_putl32 (insn, contents + rel->r_offset); + break; + } + case R_RISCV_TLSDESC_LE_HI: + { + bfd_vma insn = MATCH_LUI | (X_A0 << OP_SH_RD); + relocation = tpoff (info, relocation); + bfd_putl32 (insn, contents + rel->r_offset); + break; + } + case R_RISCV_TLSDESC_LE_LO: + { + bfd_vma insn = MATCH_ADDI | (X_A0 << OP_SH_RD) | (X_A0 << OP_SH_RS1); + relocation = tpoff (info, relocation); + bfd_putl32 (insn, contents + rel->r_offset); + break; + } + case R_RISCV_GPREL_I: case R_RISCV_GPREL_S: { @@ -4878,6 +4921,95 @@ _bfd_riscv_relax_tls_le (bfd *abfd, } } +/* Relax TLSDESC (global-dynamic) references to TLS IE or LE references. */ + +static bool +_bfd_riscv_relax_tlsdesc (bfd *abfd, + asection *sec, + asection *sym_sec, + struct bfd_link_info *link_info, + struct elf_link_hash_entry *h, + Elf_Internal_Rela *rel, + bfd_vma symval, + bfd_vma max_alignment ATTRIBUTE_UNUSED, + bfd_vma reserve_size ATTRIBUTE_UNUSED, + bool *again, + riscv_pcgp_relocs *pcgp_relocs, + bool undefined_weak) +{ + BFD_ASSERT (rel->r_offset + 4 <= sec->size); + BFD_ASSERT (bfd_link_executable (link_info)); + riscv_pcgp_hi_reloc *hi = NULL; + bool local_exec; + unsigned sym; + + /* Chain the _LO relocs to their corresponding _HI reloc to compute the + actual target address. */ + switch (ELFNN_R_TYPE (rel->r_info)) { + case R_RISCV_TLSDESC_HI20: { + /* If the corresponding lo relocation has already been seen then it's not + safe to relax this relocation. */ + if (riscv_find_pcgp_lo_reloc (pcgp_relocs, rel->r_offset)) + return true; + riscv_record_pcgp_hi_reloc (pcgp_relocs, + rel->r_offset, + rel->r_addend, + symval, + ELFNN_R_SYM (rel->r_info), + sym_sec, + h, + undefined_weak); + sym = ELFNN_R_SYM (rel->r_info); + break; + } + + case R_RISCV_TLSDESC_LOAD_LO12: + case R_RISCV_TLSDESC_ADD_LO12: + case R_RISCV_TLSDESC_CALL: { + bfd_vma hi_sec_off = symval - sec_addr (sym_sec); + hi = riscv_find_pcgp_hi_reloc (pcgp_relocs, hi_sec_off); + if (hi == NULL) { + riscv_record_pcgp_lo_reloc (pcgp_relocs, hi_sec_off); + return true; + } + sym = hi->hi_sym; + symval = hi->hi_addr; + sym_sec = hi->sym_sec; + h = hi->h; + break; + } + default: + abort (); + } + + local_exec = SYMBOL_REFERENCES_LOCAL (link_info, h); + + switch (ELFNN_R_TYPE (rel->r_info)) { + case R_RISCV_TLSDESC_HI20: + *again = true; + riscv_relax_delete_bytes (abfd, sec, rel->r_offset, 4, link_info, + pcgp_relocs, rel); + break; + case R_RISCV_TLSDESC_LOAD_LO12: + riscv_relax_delete_bytes (abfd, sec, rel->r_offset, 4, link_info, + pcgp_relocs, rel); + break; + case R_RISCV_TLSDESC_ADD_LO12: + rel->r_info = ELFNN_R_INFO (sym, local_exec ? R_RISCV_TLSDESC_LE_HI : R_RISCV_TLSDESC_IE_HI); + rel->r_addend += hi->hi_addend; + break; + case R_RISCV_TLSDESC_CALL: + rel->r_info = ELFNN_R_INFO (sym, local_exec ? R_RISCV_TLSDESC_LE_LO : R_RISCV_TLSDESC_IE_LO); + rel->r_addend += hi->hi_addend; + break; + default: + abort (); + } + + return true; +} + + /* Implement R_RISCV_ALIGN by deleting excess alignment NOPs. Once we've handled an R_RISCV_ALIGN, we can't relax anything else. */ @@ -5182,6 +5314,12 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec, || type == R_RISCV_TPREL_LO12_I || type == R_RISCV_TPREL_LO12_S) relax_func = _bfd_riscv_relax_tls_le; + else if (bfd_link_executable (info) + && (type == R_RISCV_TLSDESC_HI20 + || type == R_RISCV_TLSDESC_LOAD_LO12 + || type == R_RISCV_TLSDESC_ADD_LO12 + || type == R_RISCV_TLSDESC_CALL)) + relax_func = _bfd_riscv_relax_tlsdesc; else if (!bfd_link_pic (info) && (type == R_RISCV_PCREL_HI20 || type == R_RISCV_PCREL_LO12_I diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index a4aa71fd809..86f1538f69a 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -958,6 +958,61 @@ static reloc_howto_type howto_table_internal[] = 0, /* src_mask */ ENCODE_STYPE_IMM (-1U), /* dst_mask */ false), /* pcrel_offset */ + + /* TLSDESC relaxed to Initial Exec. */ + HOWTO (R_RISCV_TLSDESC_IE_HI, /* type */ + 0, /* rightshift */ + 4, /* size */ + 32, /* bitsize */ + true, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_signed, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_TLSDESC_IE_HI", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_UTYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ + HOWTO (R_RISCV_TLSDESC_IE_LO, /* type */ + 0, /* rightshift */ + 4, /* size */ + 32, /* bitsize */ + true, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_signed, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_TLSDESC_IE_LO", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_ITYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ + /* TLSDESC relaxed to Local Exec. */ + HOWTO (R_RISCV_TLSDESC_LE_HI, /* type */ + 0, /* rightshift */ + 4, /* size */ + 32, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_signed, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_TLSDESC_LE_HI", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_UTYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ + HOWTO (R_RISCV_TLSDESC_LE_LO, /* type */ + 0, /* rightshift */ + 4, /* size */ + 32, /* bitsize */ + false, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_signed, /* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_RISCV_TLSDESC_LE_LO", /* name */ + false, /* partial_inplace */ + 0, /* src_mask */ + ENCODE_ITYPE_IMM (-1U), /* dst_mask */ + false), /* pcrel_offset */ }; /* A mapping from BFD reloc types to RISC-V ELF reloc types. */ diff --git a/include/elf/riscv.h b/include/elf/riscv.h index c1e73f7f5c0..a99038d42d5 100644 --- a/include/elf/riscv.h +++ b/include/elf/riscv.h @@ -98,12 +98,16 @@ START_RELOC_NUMBERS (elf_riscv_reloc_type) END_RELOC_NUMBERS (R_RISCV_max) /* Internal relocations used exclusively by the relaxation pass. */ -#define R_RISCV_DELETE (R_RISCV_max) -#define R_RISCV_RVC_LUI (R_RISCV_max + 1) -#define R_RISCV_GPREL_I (R_RISCV_max + 2) -#define R_RISCV_GPREL_S (R_RISCV_max + 3) -#define R_RISCV_TPREL_I (R_RISCV_max + 4) -#define R_RISCV_TPREL_S (R_RISCV_max + 5) +#define R_RISCV_DELETE (R_RISCV_max) +#define R_RISCV_RVC_LUI (R_RISCV_max + 1) +#define R_RISCV_GPREL_I (R_RISCV_max + 2) +#define R_RISCV_GPREL_S (R_RISCV_max + 3) +#define R_RISCV_TPREL_I (R_RISCV_max + 4) +#define R_RISCV_TPREL_S (R_RISCV_max + 5) +#define R_RISCV_TLSDESC_IE_HI (R_RISCV_max + 6) +#define R_RISCV_TLSDESC_IE_LO (R_RISCV_max + 7) +#define R_RISCV_TLSDESC_LE_HI (R_RISCV_max + 8) +#define R_RISCV_TLSDESC_LE_LO (R_RISCV_max + 9) /* Processor specific flags for the ELF header e_flags field. */ diff --git a/include/opcode/riscv.h b/include/opcode/riscv.h index adea7dbc794..6e359d11388 100644 --- a/include/opcode/riscv.h +++ b/include/opcode/riscv.h @@ -355,6 +355,7 @@ static inline unsigned int riscv_insn_length (insn_t insn) #define X_T0 5 #define X_T1 6 #define X_T2 7 +#define X_A0 10 #define X_T3 28 #define NGPR 32 diff --git a/ld/testsuite/ld-riscv-elf/tlsbin.d b/ld/testsuite/ld-riscv-elf/tlsbin.d index 79b7ade405e..cdcd51a9199 100644 --- a/ld/testsuite/ld-riscv-elf/tlsbin.d +++ b/ld/testsuite/ld-riscv-elf/tlsbin.d @@ -2,11 +2,6 @@ #ld: -no-pie tmpdir/tlslib.so #readelf: -Wr -Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 2 entries: - +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend -[0-9a-f]+ +[0-9a-f]+ R_RISCV_TLSDESC +4 -[0-9a-f]+ +[0-9a-f]+ R_RISCV_TLSDESC +0 - Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entry: +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend [0-9a-f]+ +[0-9a-f]+ R_RISCV_JUMP_SLOT +[0-9a-f]+ __tls_get_addr \+ 0