From patchwork Thu Aug 17 18:08:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 135930 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp884055vqi; Thu, 17 Aug 2023 11:09:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHivbJV+KQAWV3SGN1K2C8NKN2ugTLDLFPwhVgHFj30XHWuBefjl8JundXZR6Nl5vsgOuCh X-Received: by 2002:a17:907:77c4:b0:99d:f876:8752 with SMTP id kz4-20020a17090777c400b0099df8768752mr152760ejc.75.1692295775620; Thu, 17 Aug 2023 11:09:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692295775; cv=none; d=google.com; s=arc-20160816; b=HxHNQDHZhSg65GnPTv+c0vplU3QK8v7+aVJlXId1ua/k/fVUxrYt5voXbXaz6y8GWw iPmoXtFLEvUOLFeN3dCZAfQjlbL0ECy49sShPGauSaAqP6NVMGSIIIbSKDt237h9/J82 O2Vti8XNMQXEjkEUHDeJBUbSEvjziyn9spJSPDP40haGtkncW5yZajbB88QN76ndsvvf AcNkQTxOS08HlqZDNj+lk1zG8ZPQQXafHQzTJS02FejwP5K2j18Bd61UQ6yu3G4Icx1v /86CqmpaheWORPYUjogUs7Yjm1UedYRwHZGTlEa1tS9DSx/YFYKFMapP6niaBxmib2b/ Oo/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from: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:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=RsnLvEoHJCxoBGphiamsbmEIOe0zTdOO5Dni80yDIHU=; fh=RnOK2kMt7+DQSwabMVlm0F5hv9+FMo5J9F5oi1ILKLA=; b=IxhQtQmXzTXMWmpMXPsJwSjszqDdGZOsvLX1950+23emZmDXpXGjNPqq9oKWIwXZAe mXP2DeorOupanvvegHtVaiAZkZdsC3ZwPncoWxnU9Hpxz4ddeBUPlnLy/Q6Ej7m4OQZS 2rweYfle3atwF0WgS8iPy7kVKZN7SJpLCrgI9K2j+MWlrKrS9FUSqY43DbFMyZhycdgQ P6a0mQ6EVIbv70CHTGEv9z8VMqkkkXvygcWvazhTxnXh1pEjgb+2L9AVTJPcQe34SMrX T8nN2V7kZurosZ3+aAxA1zPyIzUMhdw9+VsjB/2y5GUPaDnjnyblHYRvRhYmBgTZ2taR JitQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=oodQqJ7I; 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=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w14-20020a170906480e00b0099207b3bc46si39572ejq.322.2023.08.17.11.09.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:09:35 -0700 (PDT) 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=@sourceware.org header.s=default header.b=oodQqJ7I; 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=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 19D72385DC18 for ; Thu, 17 Aug 2023 18:09:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 19D72385DC18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1692295771; bh=RsnLvEoHJCxoBGphiamsbmEIOe0zTdOO5Dni80yDIHU=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=oodQqJ7IQtu4alnJuC9cSsdi1uZWeIhENH2Vme+uY9TSeOoWKcB/2+HsQtXC+he+D BXBSdVmUG999ygVmZTMKMMqH4bvpageSzEo3pVnVZFE+MI2V0vbbmRgOWChAg4bKHy cfXuZmf4vgpjC6drawNy61qt+BXZWm7zfZg4n8TY= 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 D4A4E385624C for ; Thu, 17 Aug 2023 18:09:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D4A4E385624C Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bf095e1becso115245ad.1 for ; Thu, 17 Aug 2023 11:09:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692295759; x=1692900559; 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=RsnLvEoHJCxoBGphiamsbmEIOe0zTdOO5Dni80yDIHU=; b=d87QJbejcaU+UYAeQXiqliCf54jOZBxzb2Vt2Ig5E0x3ffgIwhsyuQWK5sopY5SirA 6/yk7STzqnBLx5HUg6n9OlUD5p1qhQUh7fI7+aVd6cmIaYJiWwkoMKXoWnhHU8N+rLNp H0VBirLwH2Ch9hvAJwR9PpWHhZPU3IrG+XZ8T3dBHMZzHdi1wQoAu1nfiBaNjcZ7oeM/ grSzqx4cXlqujdCNpfayq3eLJ9ewknafTcYZicUKqrAjzTg6VQerEzpQr6KDJGh/u9S1 wyw7HQGP/gJ0e0h1yCKvBuV6cgOkSBnLj0sVkt+hUVBnvGA4Stw+FD0J/Jf3yaQNwUc6 gr2w== X-Gm-Message-State: AOJu0YxKojAlsjGxXOj7OsqgSj6nRpsPLQyp0Rsfv2iy8t8vL2TnHbIG h0j2qipQaRM/M2yuWF93+nuou6z4/E4hVo4X X-Received: by 2002:a17:902:da90:b0:1bb:b832:4be9 with SMTP id j16-20020a170902da9000b001bbb8324be9mr189294plx.1.1692295758782; Thu, 17 Aug 2023 11:09:18 -0700 (PDT) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id iy20-20020a170903131400b001bc18e579aesm66560plb.101.2023.08.17.11.09.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:09:18 -0700 (PDT) To: binutils@sourceware.org Cc: rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH 1/4] RISC-V: Add TLSDESC reloc definitions. Date: Fri, 18 Aug 2023 03:08:34 +0900 Message-ID: <20230817180852.121628-3-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230817180852.121628-2-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.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 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.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tatsuyuki Ishi via Binutils From: Tatsuyuki Ishi Reply-To: Tatsuyuki Ishi Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774500735283371203 X-GMAIL-MSGID: 1774500735283371203 --- 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 e2deb107494..110207789c3 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -5404,6 +5404,10 @@ number for the SBIC, SBIS, SBI and CBI instructions */ BFD_RELOC_RISCV_GOT_HI20, BFD_RELOC_RISCV_TLS_GOT_HI20, BFD_RELOC_RISCV_TLS_GD_HI20, + 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_JMP, BFD_RELOC_RISCV_TLS_DTPMOD32, BFD_RELOC_RISCV_TLS_DTPREL32, diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index e9852ef8fa1..43931a2be5d 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -218,8 +218,21 @@ static reloc_howto_type howto_table[] = MINUS_ONE, /* dst_mask */ false), /* pcrel_offset */ + 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 */ + /* Reserved for future relocs that the dynamic linker must understand. */ - EMPTY_HOWTO (12), EMPTY_HOWTO (13), EMPTY_HOWTO (14), EMPTY_HOWTO (15), @@ -879,6 +892,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_signed, /* 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_signed, /* 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_signed, /* 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 */ }; /* A mapping from BFD reloc types to RISC-V ELF reloc types. */ @@ -925,6 +994,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 a84febd8257..e04ab7d8d36 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -2401,6 +2401,10 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", "BFD_RELOC_RISCV_GOT_HI20", "BFD_RELOC_RISCV_TLS_GOT_HI20", "BFD_RELOC_RISCV_TLS_GD_HI20", + "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_JMP", "BFD_RELOC_RISCV_TLS_DTPMOD32", "BFD_RELOC_RISCV_TLS_DTPREL32", diff --git a/bfd/reloc.c b/bfd/reloc.c index 07d35e45c8b..38e1bdfc754 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -5016,6 +5016,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 0aa8b3359c4..f32215f5d95 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) /* Processor specific flags for the ELF header e_flags field. */ From patchwork Thu Aug 17 18:08:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 135931 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp884096vqi; Thu, 17 Aug 2023 11:09:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFI0lUOzEVNXGXpl5l/iT+bADqT/j77ZMGIRRyFFwg6YAtmXkJZv7FD4Nu4uFi6AtPqKgt X-Received: by 2002:a05:6402:343:b0:523:2e30:aaee with SMTP id r3-20020a056402034300b005232e30aaeemr370958edw.32.1692295779882; Thu, 17 Aug 2023 11:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692295779; cv=none; d=google.com; s=arc-20160816; b=nYUxxPsm6jbg4q+4E5fLS13Dn5quT715vOLoK6tmaFnC0+vxGIQwhDOP/CObQvp/Sy BOqGd3jpWajdpXipBz0DVC8hktVPDbFSPcfIMskTWSV1yBv1OL7KkX/Qan5ApH0z3V11 pIe7ea2+gHh4AJSpe2tNUNiLb2bKMiritVJb6ITYlMguOotb4qhaQNIBv2fLo5l6n/em WWrcZyTXVqXXBHMmUqLhYSI7XjyeP+GPcgIDENbIHClfSly+01ZjFvGREKDNFNJDmH0V BGrIf+dm/GFpAxgtwYldnJovFEdAxU9aMr1bHWSueQTLsvJYsbX0vS1INk1Nh0+EUatp UDJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from: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:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=NdQ0hoXRGw8WKBEObjxsi9TcN/pwcwTfN8Nco08hiM4=; fh=RnOK2kMt7+DQSwabMVlm0F5hv9+FMo5J9F5oi1ILKLA=; b=SxFtm/y4OAUWF4Cf8Fnml/8WGuTkg5zkfRyie5BhueBEI7GqDpBaYFXm4obCcPHm8B jrlD5qSqlzYn3L4DIFp+Pq7rrlweLeeMzNRwqiko6jPd0qZD9+Dq2qgkdT87nl7bfbcp xxjHme67RmgXpTo4rbrPZBFoodEkkw/CgNdHwzbMlZGbtNt9hWdLlXGXWVGbO2bv3fJw CaBHdXMK+btGG0la6EJdb/RdHJI70/g8sbFmA+1Sf1lADLA5T7YDp4n8OEhSr9/7zdLs gsQEbzChY1Qel282ECdICZCvrWnbTyYNb+NvbGNM6eXBtq31hghk2evkqdaEW2me9nev nAPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Lgn8h6lX; 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=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u9-20020aa7d0c9000000b00522561facd7si67129edo.143.2023.08.17.11.09.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:09:39 -0700 (PDT) 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=@sourceware.org header.s=default header.b=Lgn8h6lX; 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=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 36000385DC07 for ; Thu, 17 Aug 2023 18:09:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36000385DC07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1692295773; bh=NdQ0hoXRGw8WKBEObjxsi9TcN/pwcwTfN8Nco08hiM4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Lgn8h6lXcQbdr3GiEvXfOhRqsOf0tgl6J8iaSq89rWrPJZjZuSVWjXjHODu78bo0z 33tPE+OQoKVHDmzmD36oIO3l+n3h3L52KaAASZd5C085dLho2oBUSjBpX4Ii6qo0qS e7TKwprARa/WGsXf1sBV9gJSGo789Cwv1aD2K9m4= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 6DD1E3854826 for ; Thu, 17 Aug 2023 18:09:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6DD1E3854826 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bb91c20602so161895ad.0 for ; Thu, 17 Aug 2023 11:09:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692295762; x=1692900562; 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=NdQ0hoXRGw8WKBEObjxsi9TcN/pwcwTfN8Nco08hiM4=; b=gF2nf3ggv2JTupfcdKUUS4Gj7hmTlL+dcfSKie2GDJC7+Y60jf8rwJdqL1RW/EmREQ +Slx9Mv0uoOP7rlnUZrFxCSU09Ol4Y33nYZOyZGAFVYnTXr3N7UFwh4ADkzMpotiVIzx r36tTfBXCiWQRGyzE2/2k5Ezl3r/D2odIblvV0HERA4V8ASFGdr3uEGofFo6tZWb83G0 OtEfU0xs/Ly797tk0Pw1fRDXnx2uwRlkHDDVBf3uW2o1rGOppN/9/bOV7PiBvK+VcgXm 7APzeQXj3rhasW0dt4oOF7nwzPBEr0mlnDp/8IZ/gOc+LsvLRefpK7lr48PqI+bz0Ncp mmuA== X-Gm-Message-State: AOJu0YzZE/iTdk870vI3bqEAckgMSDhP3cem3EUW5J4ChhIKkDWmAM5M Vr9GOJW9S7wPFQDKs02XdQQHKEAoVuwApzMo X-Received: by 2002:a17:903:32c3:b0:1b8:9fc4:2733 with SMTP id i3-20020a17090332c300b001b89fc42733mr148869plr.3.1692295761849; Thu, 17 Aug 2023 11:09:21 -0700 (PDT) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id b4-20020a170902d30400b001bdd700dc11sm50870plc.292.2023.08.17.11.09.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:09:20 -0700 (PDT) To: binutils@sourceware.org Cc: rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH 2/4] RISC-V: Add assembly support for TLSDESC. Date: Fri, 18 Aug 2023 03:08:35 +0900 Message-ID: <20230817180852.121628-4-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230817180852.121628-2-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tatsuyuki Ishi via Binutils From: Tatsuyuki Ishi Reply-To: Tatsuyuki Ishi Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774500739865715451 X-GMAIL-MSGID: 1774500739865715451 --- gas/config/tc-riscv.c | 18 +++++++++++++----- opcodes/riscv-opc.c | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 959cbbc32a5..0a1fac9de9d 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -2195,6 +2195,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}, @@ -2206,6 +2207,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} }; @@ -2217,8 +2220,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} }; @@ -3326,10 +3330,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: @@ -4082,6 +4086,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. */ @@ -4255,6 +4260,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/opcodes/riscv-opc.c b/opcodes/riscv-opc.c index 067e9fdb611..467666b9805 100644 --- a/opcodes/riscv-opc.c +++ b/opcodes/riscv-opc.c @@ -370,6 +370,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 Thu Aug 17 18:08:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 135932 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp885226vqi; Thu, 17 Aug 2023 11:11:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwczoieRaYy6WqIa4cvUdRTlH8LDJwLHca3umVk95A/X2QgsA0Z6cH/iVKevLbbGRJD7Pz X-Received: by 2002:ac2:5f6a:0:b0:4fe:8ba8:16a9 with SMTP id c10-20020ac25f6a000000b004fe8ba816a9mr43146lfc.55.1692295885085; Thu, 17 Aug 2023 11:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692295885; cv=none; d=google.com; s=arc-20160816; b=ikOy6qFSRDn6t1wKJnjDCAM1+kB3TT5Egbtbi8tmlo+1PhzpPDqe9j72Sv6o2ZhQh1 7C8Ar4hlm7PlBinvEkNXP6WCSdmf5MNlQQRe6s7pz9efyOErz1gmlwQrMfRYSgmpv0sk 9w0thXqnYiqGEA80cBeHiKon+cTM9KV1sVste6XabC4c51q/tH7hWaIQ7QoEfVjw6w95 80/nuxjL3/lASF0QyMCmlzw0ne7injsZE1WaD/MHjEvvJxad2RXd/SFCtqkXrExp3q5e 8rsFua5SNnGnTjwHn/p7fpgL3V+m7HbWjeq7qqBpm81ZrcM60st3/b4NMBaVO7v7hFIJ ApKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from: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:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=/wIKW/ubIEfaUsGWQZdx94TLSSG26xKVZ4fCtDwJboQ=; fh=RnOK2kMt7+DQSwabMVlm0F5hv9+FMo5J9F5oi1ILKLA=; b=KZNu4nhLS2ntDLDpv1+puq/gq4ltWulrDuxbGSq2+z2QCin58f0QTTAFy9I+EdLIzb Q4MHu01RL1/9r4I35wQKpGTqCF2cYAKxifjMHwl2N7m8CABGpCqZ1BVfF1vkhuVmbd/L SXMmKm/yCnJGQLCm92RqJ+8pIQaJ2owerodpw1gI76p5xpGKN7jUPkwsxZ2gpaODJH5x bCg82KjQj2E/SEaC7WEJQfRduNRcbURai1/aXrtQp5Zw6klgxqbDmZDTZcM2VVFSUxub sXvs6QwaQOKOYfL6AKbOPQTdoNX4Pe0nih5RKt88NiarVyGOVyAHYbH846QYGL1f3ias PULQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=WqrGaQ12; 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=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i13-20020a170906264d00b00992e9af8186si51860ejc.13.2023.08.17.11.11.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:11:25 -0700 (PDT) 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=@sourceware.org header.s=default header.b=WqrGaQ12; 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=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 740E03830B65 for ; Thu, 17 Aug 2023 18:10:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 740E03830B65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1692295827; bh=/wIKW/ubIEfaUsGWQZdx94TLSSG26xKVZ4fCtDwJboQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=WqrGaQ12YOO286WJ3nuWWzOxx3jkplwwBiHCGHiCcnD0UsRItmWcS1W4hLWc6lvc5 ZBAUKroBTI32a7qLMlN+Y+qdlQ1G+VG1iiUDgRHG2uhemOP0JQmJSLt3KkteT0Kv8l L5Sj7uhMffmIuYRyZm+/JBwSeKYit7EMH2smRbP8= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 049FA385DC02 for ; Thu, 17 Aug 2023 18:09:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 049FA385DC02 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1bdf1abee23so137615ad.0 for ; Thu, 17 Aug 2023 11:09:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692295764; x=1692900564; 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=/wIKW/ubIEfaUsGWQZdx94TLSSG26xKVZ4fCtDwJboQ=; b=kLgTF29eFLgudOuNKvY5or/UBNZA+eistmiFh/oauLwWyWM7UrsDpuWJk1vNgQXuuh LtIVyTZ8NqBLyTRm/mgFUKoVN6lx8vK5O+MIo//W0zCmW4jcCkxPYHFO05K8g2wZWTBD fLYfRemNM73wi7jSyrmS4Lg9NNlkWHfWeEJD69ON1dORNwsBWOu0z/pLZtC/Jp6nPc2v Quq1LkeczvoN8rFpIzX03Nq12h117nkEtL1lCuDFGe7RIOr5BRXDdoIBiFx2qKZA9nTN Qg2l5jRTJ4tzw7gy38iOxWt/0CQwZCPUTMNOXn2//FEejs7DIJJOXJfiZ4JF6E7HIR8F QiPg== X-Gm-Message-State: AOJu0Yw7JQOUEF5zKncf9akeK62ff/0bsbpKwD7XEupdNEOBdeVjXKXh IeL+9wXtK0K4U+sNu81SacS1GfqgoeRJ+GZz X-Received: by 2002:a17:902:da88:b0:1bc:496c:8eda with SMTP id j8-20020a170902da8800b001bc496c8edamr132014plx.4.1692295764414; Thu, 17 Aug 2023 11:09:24 -0700 (PDT) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id q18-20020a170902dad200b001b892aac5c9sm50318plx.298.2023.08.17.11.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:09:23 -0700 (PDT) To: binutils@sourceware.org Cc: rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH 3/4] RISC-V: Define and use GOT entry size constants for TLS. Date: Fri, 18 Aug 2023 03:08:36 +0900 Message-ID: <20230817180852.121628-5-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230817180852.121628-2-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tatsuyuki Ishi via Binutils From: Tatsuyuki Ishi Reply-To: Tatsuyuki Ishi Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774500850174321211 X-GMAIL-MSGID: 1774500850174321211 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 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 02b46835cc7..38883134828 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -301,6 +301,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? */ @@ -1323,7 +1325,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); } @@ -1331,14 +1333,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); @@ -1566,20 +1568,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); } @@ -2905,7 +2907,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 Thu Aug 17 18:08:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 135933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp886061vqi; Thu, 17 Aug 2023 11:12:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjeulPMya9Xc0AaiU7XuFmrdjjTm2lb6n06m0HR5MK087N0MuRBgJx9a5EBPpWNQjRsi5m X-Received: by 2002:aa7:d90c:0:b0:525:6666:3551 with SMTP id a12-20020aa7d90c000000b0052566663551mr347669edr.27.1692295973388; Thu, 17 Aug 2023 11:12:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692295973; cv=none; d=google.com; s=arc-20160816; b=T7qn7Eol/tkqSyBviaIcwZEsuY7b44ff2aYisnGHH4p40D8fpxFg8LsGrlhNeqa6ub Ce6bxp3yBW2T5ezB/ERhKOF3rBrqULK2S73/E0+KQtPoYaGmeLq5y/Q/VtOlbeRBmVvY 3OGteXxi2eY89LmpsF9RNCnP6/tD1BxpSiqYeHiZdmGIY1Q9kBgHc8tV84iS/NnTvJUp o+vQclOxx2+ShlTlR9GzQUajmF8Evt0nLN9cC8s/0+046GOz/CybTNy81knajLXX7Cze YtmlC2hu2F2+DKWqin4PUONPkAkcKaPKNAbFNyB70p9n1sw4Q1/IBYRW4qiMTgA2P3ot 3rHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from: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:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=YnSfuEQf3iraU1vFMZmFC9fB8/TpBVL86BKQLGby0TY=; fh=RnOK2kMt7+DQSwabMVlm0F5hv9+FMo5J9F5oi1ILKLA=; b=TtIruVl1DP7Teq6WxrUEGcsMATW61iiOUSESqzHkrqk8Umum1uXzGHhppSxoFA4T0w iRvnkY5gUBMb7pj5rqPcuMxmNJrok9g61svcQ418qyP+G3VOtdIQ0meGVdhmVKP0fcF5 1kiMgEVNoGnvO/pxDjZ0xkWnhh9Cu/I9zHOcf3L17K4w0dwdc7kUoJgfZoGe9NVZR4VQ /EpImIVDSNPspsbeg2zSfuZeN4KLKuNTQjMhxk9KmPTm+1BeraIuivwmv+BLrrDKtOiF Ow5Rz7reaKapwKPmBR0jDGqkewXiO9Wu4+lcCv9x7K+PyBQK93MI6SE5BqXewi1wowy1 H0Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=kNfqTC5k; 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=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u1-20020aa7d981000000b0052257d9655bsi61736eds.304.2023.08.17.11.12.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:12:53 -0700 (PDT) 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=@sourceware.org header.s=default header.b=kNfqTC5k; 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=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED484385E019 for ; Thu, 17 Aug 2023 18:11:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED484385E019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1692295887; bh=YnSfuEQf3iraU1vFMZmFC9fB8/TpBVL86BKQLGby0TY=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=kNfqTC5kWJdGFMw0W5/o7M7v7rFyI7yvFS9Gjuc+6zMCFPb7eYHWbXba/hkk3/KSl pEPXUMu1fl3X3bHOMf51O1hluOjnHQlA6bhY/ZgrBftszapzRe3GorWyCaxrakEh4L Y95m+Ho6qmXFUEe/iHPlNHJQzarYGWqDRyqz9og4= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 02A6B385DC10 for ; Thu, 17 Aug 2023 18:09:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02A6B385DC10 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6879986a436so16778b3a.0 for ; Thu, 17 Aug 2023 11:09:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692295768; x=1692900568; 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=YnSfuEQf3iraU1vFMZmFC9fB8/TpBVL86BKQLGby0TY=; b=kmn41EusfULMhMq/zWHXPRUsRZ90VLH4J7T6pUp2AgaOsMBxx6LvFk1B9/IEbKDUQ+ Vl3IOw31caGxSCmkIYANb6ClQJW4Oqz/Up/aUJAFL1lQgGJOaKEWOgenAuTmeObB6DpE 3NzFHGSKeDe6adC752E2j/5vBDtEj5qFlewOpDTMrJcu4MhnBs3nvcwxwT1W7ludC+kU 6yr5al1+U6ijt0RhvrvA1HnXh/RccVGk5f5C1rMNAfPW15XRhop/K/yBlgP/eCD2QR4X RO5DjdhQj3xbyn9rVbAHZoy0cZgZMPmoP0xYHBXuNz06vIwQqjXFcWdRM2bWTfXTGm3E 9Xkw== X-Gm-Message-State: AOJu0Yx1GikfVilTM8imVxAuQ9UGPrkYKaSjbuhPoydo/JFBNgh0JmUw UCTA50hM7ETyy9Mxtd9yeF3t5uIPIe0+jIDH X-Received: by 2002:a05:6a20:441a:b0:13e:1d49:7249 with SMTP id ce26-20020a056a20441a00b0013e1d497249mr618267pzb.2.1692295768353; Thu, 17 Aug 2023 11:09:28 -0700 (PDT) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id ey17-20020a056a0038d100b00686f048bb9dsm64094pfb.74.2023.08.17.11.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:09:27 -0700 (PDT) To: binutils@sourceware.org Cc: rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH 4/4] RISC-V: Initial ld.bfd support for TLSDESC. Date: Fri, 18 Aug 2023 03:08:37 +0900 Message-ID: <20230817180852.121628-6-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230817180852.121628-2-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-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, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tatsuyuki Ishi via Binutils From: Tatsuyuki Ishi Reply-To: Tatsuyuki Ishi Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774500943007427688 X-GMAIL-MSGID: 1774500943007427688 Only relocation handling for now; relaxation is not implemented yet. --- bfd/elfnn-riscv.c | 91 +++++++++++++++++++--- ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp | 2 + 2 files changed, 84 insertions(+), 9 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 38883134828..a55bee7af52 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -166,6 +166,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; }; @@ -303,6 +304,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? */ @@ -858,6 +860,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. @@ -1316,7 +1324,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; @@ -1337,6 +1345,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 four 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 { @@ -1564,7 +1580,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) { @@ -1578,6 +1594,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 { @@ -1728,6 +1749,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; @@ -2195,8 +2230,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); @@ -2499,6 +2534,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: @@ -2820,6 +2856,15 @@ 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 (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) @@ -2885,11 +2930,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; @@ -2902,12 +2952,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)); + BFD_ASSERT (tls_type & (GOT_TLS_IE | GOT_TLS_GD | GOT_TLSDESC)); /* If this symbol is referenced by both GD and IE TLS, the IE 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 = TLS_GD_GOT_ENTRY_SIZE; + 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; @@ -2989,10 +3043,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)) @@ -3212,7 +3285,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/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp index 947a266ba72..e09c25486a5 100644 --- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp +++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp @@ -317,4 +317,6 @@ 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_dump_test "tlsdesc" }