From patchwork Tue Nov 28 08:51:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 170636 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3771836vqx; Tue, 28 Nov 2023 00:52:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGk/wPkqkzT3OFQxOwnlLneOohgWF3J1On2s1qexog2Lpi9FxZJx2pxYyok9oXatulJ1Wnn X-Received: by 2002:a05:622a:14ca:b0:412:1c5f:478b with SMTP id u10-20020a05622a14ca00b004121c5f478bmr22017938qtx.15.1701161572399; Tue, 28 Nov 2023 00:52:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701161572; cv=pass; d=google.com; s=arc-20160816; b=EsX1YxRXYYhUAaPZJ7UD9SU/Nv7qbG8YgtWv+5GNobFL5Vz4d4up/8QmQcMkayppLN 3EBFpyriSCOqztK4xJC3UXnhLToW9xhmoH/pcP7Etfg1XZ6d2Ngd6X9urNUaoiVeHtkM dF8mQjlL25zGiWQG6IJyOwrUe+Nf53AwFNbbuhUEmsQF+TsDjqv2aaTnmBVmVpPIIZ5f n+C33lOPGIPyx9boI1oZwUrk6uqAyaGMVj/4m4QYTH5sDO/HSRICEoOq4J3uCAJj7auQ rZmPye2xito4bYFuyksJfDWzZFU/1u9H65/HIqaqXLFeDX5gpSPjIfYlEmbqOJLBkzHV F8yw== 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=KkD3751mJXlW1P/MsC8/06Y7JPoPopoajZ+eHXihXX0=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=gEMQVbLTn8D+79hs88SvBZtuXuWX/VyfyGB+gqIluXOtP1kATuW4nT1PzglwppSw01 OnrtxLd7IBYBXphDKBLXVnekVVjWY1Kb5qRmTdtuLPTMRIhA7U38bVyFpa7NMRNov3+R utDlSgyHS9W8ITxXVZ+4g5dKjlJTK6fH7YAfybN70Em2la80NOzo8sXPWL6gG0cTJY72 GeNjuHGIdNYU/O5x5iH5x5S4dQLmThmRU47Durf89HhGCEcnMyVY7WFr7Oh5oefCVLFk KPfc1wZ5B2FMXGdaDU/nQ1g2empSc5nJWiPA456HSxXs9gHmFD7leDy5Q31N8tkXUW+I Kd3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Dt/DNw2/"; 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 x7-20020ac85387000000b00423a0dfaae7si7080283qtp.707.2023.11.28.00.52.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 00:52:52 -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="Dt/DNw2/"; 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 32371384CB8F for ; Tue, 28 Nov 2023 08:52:22 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id B95C0384DEFD for ; Tue, 28 Nov 2023 08:51:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B95C0384DEFD 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 B95C0384DEFD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701161495; cv=none; b=ZcQhN31ppihHcwKaKuS0IPeLErMayxRps7TaIsaj/KuZ1zDddM4WmdATDRIMCpfXdwV4oJglDAq5cFYU+Oq0sL1DhzDLrMa4ynnNmBx9QNqeYaVOlRuv+0X2BAx843zBchGHZ/ZZjhfZj7Sf+M60SvygzvaiY5N4SYBVe4U5PN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701161495; c=relaxed/simple; bh=I+fg8xSJxP6KrLs6etrETS6RxH7UaHXBNZ5i9DUJYOA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=RIkdvxbvPscWXUfDz4/ol4ljEAPdEadCbuzfC6WPljU47VfQ7/oTu5qrS0gL3ZJfNX447mXYl5xtJ10vDqZRiZai7R5gYOmWQw5SrlEKHVkapJCsaTre/OWBYeP1R5qlCX1qFgzWXADMmIZxgN5bMEhgge1FRoWqFLsJhOYhnrc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1cc13149621so12365185ad.1 for ; Tue, 28 Nov 2023 00:51:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701161491; x=1701766291; 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=KkD3751mJXlW1P/MsC8/06Y7JPoPopoajZ+eHXihXX0=; b=Dt/DNw2/7KHCGtyTy2+/Xk+eku+EIW9U5O8zMnQojkT0rk/0CapQCgYCQPJL1YkF6T G7AFKL7MWoRBFxGSlB6Dj6ivtHT7dW+mY2iG8YNekExCEWAEQegjFo9EXVrzbPSxB5BS Y9oA6T4eMQw86xo/sLJ0+X1zDkQncrvoYY5ezdg0eTf4HmhgC/nohLMjrZ8EdBaRBcu1 31kw8fSwJSV9SsxdmmgNambh1qBmvGnQtmHJmr+bR8hkSkk7MRhrIBDolc+nVZtwgv3U YB89UnbtEakrA6+DCFgSCq1KYEkob0M0vlIQgXJ3eSMHMkIp3Cjhlf5CjARVUdPOVBd+ kOKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701161491; x=1701766291; 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=KkD3751mJXlW1P/MsC8/06Y7JPoPopoajZ+eHXihXX0=; b=vBwSVb+Dx+kQ7gOP4hdv4uFtuxYjsd9+iJgglvV3zGT6OR0Ilmj7cjnfAYJ/8X27CJ lDhf9oYbJvbHD8GmNDJ15srXWI6ckQHsizliLEPx38c8y6fcQz7UzQp63oTBfRJWiQAv xF85GnR7YjrXbjJDqnf1CgjTnhWHZvXEfE8Ub96dD9/suYNRVs1wBReEO0GpBh834Gn/ 3dFaLMXkd39w+olXhvq4+1ffCwiNF2VgmNSH8uAR79X6nQBe5GbDhOSc9g9CSshs4h9u jrT70rkf4cK32lnFLpri1M+dCNcRaiJ5odirg7sbOpDIHjad+uKmz0Fp1b/7U2W9q043 U7eQ== X-Gm-Message-State: AOJu0YxE8HgT/XGyU9/GrNpGcUJo1bOxS9IuMtrcKl9tYtPyPoAwg5zJ sKB8nW73V3AYnK4mkC7pSPvBEbAQTpWrN32Z X-Received: by 2002:a17:903:183:b0:1ce:5b6e:bae1 with SMTP id z3-20020a170903018300b001ce5b6ebae1mr17757831plg.3.1701161491099; Tue, 28 Nov 2023 00:51:31 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id s17-20020a170902989100b001cfd0ddc5d3sm3117904plp.277.2023.11.28.00.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 00:51: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 v3 2/9] RISC-V: Add TLSDESC reloc definitions. Date: Tue, 28 Nov 2023 17:51:02 +0900 Message-ID: <20231128085109.28422-3-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231128085109.28422-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20231128085109.28422-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, 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: 1783797197372533750 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. --- 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 040d5560cdf..9bc6b9885ff 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -5407,6 +5407,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 567631e7d96..65d676b06b1 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_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 */ }; 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 cc432677a81..919b63d51a1 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -2400,6 +2400,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 93ebad879e0..345f444d17a 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -4984,6 +4984,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 56d419c665b..7f5c0407ac8 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 Nov 28 08:51:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 170634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3771547vqx; Tue, 28 Nov 2023 00:51:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLED2c8OhG0qtFJ2GiHFeq7hQsaqBTwsqKKt/lZOUVEMWNz/aut5XT1SBseVFMDHrsVxMu X-Received: by 2002:a05:6102:3712:b0:462:9350:685f with SMTP id s18-20020a056102371200b004629350685fmr18910094vst.21.1701161516690; Tue, 28 Nov 2023 00:51:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701161516; cv=pass; d=google.com; s=arc-20160816; b=jH045el0L0BdlTK5YQjKYq76k3Rj7NrlgoRBBpfD9H/8O9H9zIEBYYtSlA8/dlGi9p 8uAdr7Ngb0UX4wqwVnoKrcr0ZhdkZqb8W+3SAE0qWFlwdjgtQJnbtoroCjdzXUmpJjju PwInupH7nmW6e4BHm//D2cigVkXzkCRZFIR8Q6HXy2QgvEwpVQMDPzjuyZVUh1FE0idH Cmltrzi+5+rW5iUt8ZYoc99fAu9quUn3Il5Y9gs1L18xwPuw/fqDWxVD3MhuCPyazb6y ZbWlNY2y9MOMO7BvQ5uQ9xv7F3tgAPp+C+LfA02CrwWFbTsSBNYo0QUuMMWe66/I+cc7 MVBA== 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=FUXOuEwEjhApc9RBXqLnwljTR4Su9ibK06wJ6jXmu5M=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=ZTy7e5tMMw8n8dGPb6r4X4st4eVbptXsPMeonMI7i345FG5z7YbpKXVLbNj0466DnP AfmNHZpNXIu/f0Z7L6TZROCdozp4YIogASkERW3/x573DkrBjKlA/CC3iyP0eEBpalyD Mw4InqAe23bzdICDvQwXciH22QmXTgssWjrVy24Lq+b+gQX0bkXCdxKdUWwJltQL51F3 HNl6mPeHwU0knmOLD+lo3OOzsUrFf68ZqHB9FbqLUlyfb2UaPgXq5OApaI4oVdLE5qb8 kIKC8+H8ahtYp22Ekq89J6pp9zwntRcEYCaCd1P4dnp/RfoaV+x91aSLdm7zP9+1PfdH uWOA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JqDHu5UT; 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 bx12-20020a05622a090c00b00423a7d51adesi6328124qtb.767.2023.11.28.00.51.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 00:51:56 -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=JqDHu5UT; 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 A3021384CBAD for ; Tue, 28 Nov 2023 08:51:44 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by sourceware.org (Postfix) with ESMTPS id 0FA31386583C for ; Tue, 28 Nov 2023 08:51:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0FA31386583C 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 0FA31386583C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701161497; cv=none; b=i6b4js+LUJ/R49odMAKsFgPCXmLxqKw3dsGnKbviJNXcS/By5C297ZkFTgDXMXKX1dnY1vLGvpXX4JVjeDv/OybvehHDktUHqWpdZJGSyULdbNaqD30UqHnK4Y/ZfKra+nPgpcKRhhdtH5+Hm1CtYLLYCKkMZTIwo2LwqnP9EEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701161497; c=relaxed/simple; bh=joqgW4A9qJku2ArCpoA+mDdtdG+4ZC6TsbZx5TcaRDE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=he1G08WBMYezX8G0tu9IlWNwIpfoFy06OgmrL2k8V7onL3F6luuvwl3MrPxJ3BCXJfiYVjC9LzACxQORGQf3cxhQeJxG9+piyR4kWE2vdW0RFuN0HOwZfwL0gsBQBxTuk9n77SJDkiKDm3LnhqTPmfCRZWQnSndEJS/NQM5XB/I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-5841a3ffd50so470234eaf.1 for ; Tue, 28 Nov 2023 00:51:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701161494; x=1701766294; 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=FUXOuEwEjhApc9RBXqLnwljTR4Su9ibK06wJ6jXmu5M=; b=JqDHu5UTGLRNhDMZNmMOeCGd1dMbVLKqFbTQp+QF9Bb5XElIUJmpxiTOS+rBzUl/rm p4C9ewjj8oWTf4K63Sq0BwT8fWc5Fs4J9HdHUYzeP7sKpi9zc7kJ3EltG/Og2OhrH3Ex RsNcQjCpjRpbcTftfYQmbaAK9Zdx39zY82fF39gVQoZ5R/b1idPhlAF2rTk4fPNpfXcQ cHuaConRwQ/RlFF5r4flQpOBgtsiSF8yZ4bSwJC2deqDEdSi1pLbjv4BIa7v9BHCtP+E VuEYK7DA0thx8FzHly5iTSYjSqfb/HTXn3Dj6AuPu+vT7q/0U58zW8pQJREWZakbxoMS uRuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701161494; x=1701766294; 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=FUXOuEwEjhApc9RBXqLnwljTR4Su9ibK06wJ6jXmu5M=; b=LU/SsyuPh1WFr0FZyYKVWdL0o6DMyGQSKEiblTT3L3rRs+zWtDJEQIA9SX6rookTUG 3Fjd7BkpU176L45TNjolE7g0dAjEa4CQor1QQgqslIVfioJWdthCZnxKZ224y07Dfq8J SDvmxBb0H2fNEHA+f/M1YaDFhGTEy6nbrFm3n/P36QX+joi+JT1Olny8vzfWEhdvUt4h 76zIxbxAo1T2PJDMhHdirNHdXLyoBEfjtyqsOhoRJyLkDew3vWNMwLx5a2pnxZpevrlv Mw775a4COBsT5qKN8nkm1eE1YBQVdZaEYzB6ShFxbSej4c41pd+lHHAO/R822/Es3zgk 6wKg== X-Gm-Message-State: AOJu0YxK0ulPPmKm9N+FgnmmHovEaGVjLRqEivDx371qRulHcYEGmCC0 iA5kw7HRGDh4CiXt0JQd/qulIVNG9VgmqAxi X-Received: by 2002:a05:6808:f86:b0:3b6:d0f3:29d0 with SMTP id o6-20020a0568080f8600b003b6d0f329d0mr16611849oiw.2.1701161494230; Tue, 28 Nov 2023 00:51:34 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id d25-20020aa78159000000b006cbae51f335sm8769535pfn.144.2023.11.28.00.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 00:51: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 v3 3/9] RISC-V: Add assembly support for TLSDESC. Date: Tue, 28 Nov 2023 17:51:03 +0900 Message-ID: <20231128085109.28422-4-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231128085109.28422-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20231128085109.28422-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, 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: 1783797138408371266 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. --- gas/config/tc-riscv.c | 18 +++++++++++++----- gas/testsuite/gas/riscv/tlsdesc.d | 22 ++++++++++++++++++++++ gas/testsuite/gas/riscv/tlsdesc.s | 24 ++++++++++++++++++++++++ opcodes/riscv-opc.c | 1 + 4 files changed, 60 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 04738d5e00c..376d2a34530 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -2113,6 +2113,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}, @@ -2124,6 +2125,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} }; @@ -2135,8 +2138,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} }; @@ -3244,10 +3248,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: @@ -4036,6 +4040,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. */ @@ -4209,6 +4214,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..11872953d23 --- /dev/null +++ b/gas/testsuite/gas/riscv/tlsdesc.d @@ -0,0 +1,22 @@ +#as: -march=rv32ia +#source: tlsdesc.s +#readelf: -Wr + +Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 16 entries: + +Offset +Info +Type +Sym. Value +Symbol's Name \+ Addend +0+ +0+a3e +R_RISCV_TLSDESC_HI20 +0+ +sg1 \+ 0 +0+ +0+33 +R_RISCV_RELAX + 0 +0+4 +0+63f +R_RISCV_TLSDESC_LOAD_LO12 0+ +\.desc1 \+ 0 +0+4 +0+33 +R_RISCV_RELAX + 0 +0+8 +0+640 +R_RISCV_TLSDESC_ADD_LO12 0+ +\.desc1 \+ 0 +0+8 +0+33 +R_RISCV_RELAX + 0 +0+c +0+641 +R_RISCV_TLSDESC_CALL +0+ +\.desc1 \+ 0 +0+c +0+33 +R_RISCV_RELAX + 0 +0+10 +0+53e +R_RISCV_TLSDESC_HI20 +0+4 +sl1 \+ 0 +0+10 +0+33 +R_RISCV_RELAX + 0 +0+14 +0+83f +R_RISCV_TLSDESC_LOAD_LO12 0+10 +\.desc2 \+ 0 +0+14 +0+33 +R_RISCV_RELAX + 0 +0+18 +0+840 +R_RISCV_TLSDESC_ADD_LO12 0+10 +\.desc2 \+ 0 +0+18 +0+33 +R_RISCV_RELAX +0 +0+1c +0+841 +R_RISCV_TLSDESC_CALL +0+10 +\.desc2 \+ 0 +0+1c +0+33 +R_RISCV_RELAX +0 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 bf19978e025..edaf4b0c8b5 100644 --- a/opcodes/riscv-opc.c +++ b/opcodes/riscv-opc.c @@ -372,6 +372,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 Nov 28 08:51:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 170736 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3854290vqx; Tue, 28 Nov 2023 03:50:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6zT8iOP4Gc2E9mMvHaKK3sDNKu9VGffbSe8bxLTPiml5IpwMEUZeeV2Y4EO5PcCXVsKk4 X-Received: by 2002:a05:6214:1d2f:b0:67a:5be3:f0f8 with SMTP id f15-20020a0562141d2f00b0067a5be3f0f8mr1738125qvd.19.1701172227778; Tue, 28 Nov 2023 03:50:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701172227; cv=pass; d=google.com; s=arc-20160816; b=E2wajOYL6vtSC2UcohchHKz+NwuMKkG8G1NCevqjmgie5kuTTVzc4JqAJUFZditB13 r6tMRAnyHm3Gk0u79NKloKeHHhTldU38pkvEybjfYkZ1IJIhxsSrfWwUu9PC3FahdA23 i0MpcOIpE3EVJDUl7HgovrfVO2LJFoEO7PmkEZvZOhzjP1yYeSTiUmf91K9oqbHNwSnm p+Wv9zTFWQfESLK+vkTr7ZHODl7Tif9kb+tE7zy//hbpPV/5w9g7gJTBJTXRLSrowyGR lp1kI3S8JrlNW0quJn1g4eh/O2t/cBn4GtgEG+r/JBfj0BGgcHNGjepbhvJI0b+lVGpM GyUQ== 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=XN4ETMvl/+1tnmCJy3fTvUlZOS78GsFb+tjvEbW/js0=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=P8jvk13F+ASLsH7BU59uirmVjPix0eezbLzOLB/y1V+kviRpQsj9998zoUl9gWxbk5 VIKMVB0S5Kx3PHBNqnJezZg1N2l656XawkryYoOa72FTGGEbnAUGuIxNeGNkZAvfdlje 7otnABWBJl3n1qHXjvugQ+6l9anFbCYFykLTfOe9FDVri2/i498Cj5QZo7pcTGlmU9+l XQDnfmWaYamYJMuS36R88JpN2zBNo2UNpQHOUO8KY0F262MljWeAbPZUcV62+Cyxnd7X BSxa0IUIisPC41ASkHyxs8MqZPlRMtxmGMF2Vb49pUo0AirXBRkgat8AkHt3+TYCVsmI fvjQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=AJSORxOM; 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 i9-20020ad44109000000b0067a2c0848casi6506346qvp.116.2023.11.28.03.50.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 03:50:27 -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=AJSORxOM; 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 907523881D3C for ; Tue, 28 Nov 2023 08:52:30 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id 7967D38654AD for ; Tue, 28 Nov 2023 08:51:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7967D38654AD 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 7967D38654AD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1031 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701161500; cv=none; b=BuflHajjMzjYWJpP7QcuQ17SRc6MpdtEZAPd+x4ZRm+2hCEJx1KMGlqLIJR9+ET2uGObu+0qmQ7EJ0rQgNn2BvWEycGTBcYOOt08o/NodC0zQ1Q1Wt5qygmMPJujvXISY0UmQRdyfTnPbCe5D+bcpuxazLGFLnkH2LzgJQp74ro= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701161500; c=relaxed/simple; bh=5gYhP505IbbZG0ikt9j6GcwMPq7VPfYOu5qj9luUR7U=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=C/mryVGMIcEwi0YbQeC92dr4CKFIlJeqt4KD5F8AZ1Bxn5rTgLO0EI0fX88ypKc9wzPzBZIzfM2PKKGoy4h0WTGKuex59px5PJNNEX4nRsq+TNuU/jBHQOgnYjwoh11J9/vsl490jGPViSVgzxOelPLdgrCswShypV53LMMxiOY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-27fe16e8e02so988558a91.0 for ; Tue, 28 Nov 2023 00:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701161497; x=1701766297; 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=XN4ETMvl/+1tnmCJy3fTvUlZOS78GsFb+tjvEbW/js0=; b=AJSORxOMr/C23KXtRJU0iYHM4p8NkWITL4eGP21FkK2uP6GLyNaPL7xbl4wUGM20Or VD7pHErtgr8476To0MYcvE2ljcTrmzZ93PGVIei46d+YITdfo+Ui91h8JgWmuZ+Rr3Lj r/XzmfoPoLmlayYOyzfBsiTzs/LMiZSLWD8Fx+u6p7ORw4Tk4DD/T/l3OZMjtB1vArWT JfAAtPqZaHa1WL2Y1Dzlf7x5D+p7kGi3K7kLIVnZXnaXVVZ7Lc2NMGIt6BWgNEgY/2hg R5zifCvzmsFMI4Ktob54Lw1FEfp3uVoNVConIe1zYJoYIbKHZqlCAIcVCYeKIkBhuCxf YvxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701161497; x=1701766297; 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=XN4ETMvl/+1tnmCJy3fTvUlZOS78GsFb+tjvEbW/js0=; b=mIv1jsdQGkw3b63O6n5naeoda3uidn2T7IBalr6ofDAdcOQh6fdczwvN1RC806+/fo RelqXCSwooGL0nCaSGIlxU2/Gz/4nyapUUQolkNA5sTvpbP+qWWtrijtPw6njt8Tk/Gj 42x5VoKvseiZkAUUDzMg/+solnKgs3MTcgidg91Z4PG9FrwGiHkeh6DAT5Ze0LHXQ6hc +VGN/qlDVnwwyFY+Me522UH/Hh9PjKweDMBpdg4ukKh+tF/uXYh51GTmAtDZMd3nFd92 Uk4DgO0Isg+PVDpU/0AsCXm/qhTvIeLmrPppnPtfTjGXDl7JkZXHxrQRRhdM9GaMRN0D tY8Q== X-Gm-Message-State: AOJu0YxW8mrjqCZCGf0NJ+eOUhceNY9ClzqEh1Fq2A8/P7kepu/jFIQi GmU/j7eNhPLTdSXkhQHlJuU/B50kb3Sk//HG X-Received: by 2002:a17:90b:2315:b0:283:9d45:a815 with SMTP id mt21-20020a17090b231500b002839d45a815mr14758634pjb.3.1701161497411; Tue, 28 Nov 2023 00:51:37 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id mn24-20020a17090b189800b0026f4bb8b2casm9009552pjb.6.2023.11.28.00.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 00:51:36 -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 v3 4/9] RISC-V: Define and use GOT entry size constants for TLS. Date: Tue, 28 Nov 2023 17:51:04 +0900 Message-ID: <20231128085109.28422-5-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231128085109.28422-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20231128085109.28422-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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: 1783808369955876210 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 c0207765906..d5190538503 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); } @@ -2912,7 +2914,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 Nov 28 08:51:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 170776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3902409vqx; Tue, 28 Nov 2023 05:06:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9rkh6ZzxZXTIPUdWpJAh6NWPGEBeCqTJxHJF9w1yERIQod+5sIIWKaiUgE2BJ9ExXd3xf X-Received: by 2002:a05:620a:268a:b0:77d:84d1:a594 with SMTP id c10-20020a05620a268a00b0077d84d1a594mr20181146qkp.10.1701176787183; Tue, 28 Nov 2023 05:06:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701176787; cv=pass; d=google.com; s=arc-20160816; b=VU5Hyh0vomxiFlmc5KrMwPAxq+ftd1Ced5Jj2hMVVCvhW+rZ4bLanEsPw9upoPa5qW dwTI3bWDI2yWogLYVXr4Hq7Tk4YzBFjvjw/b2DccR5/vIAa14TDhy7jxy/K/xELAUS3L LHREAjDlgLSRbLkLZD2BTbhyAUv9Ha9EDPMu+BGGNP2LNHpM3xOS1T/Q3D8g1rgX5kb7 w8EQfL4bPw1Tp0Cm6Zv1jxGGM4avy9f8Bdul2fpq19jc+nKhobNUD5AvxK8YrY3PwJkv QL+z1UHue/Uv0rRYhNHZHzDwfMBtSie0qW7tF3TdSg9fP9rUAyPJD7aX5hggTzyfD6hy ShJA== 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=8506Kma4qk4mh6i8TY9tHbJ7ej0t0/2tauvigcP3l+Q=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=th/aY3BKxEK3alEyD1NFJ+3ogpQMKrhx7XDS+vEdYJloZe1lcsc+l9b8WJw9nJCY+Y cFR38Okww0tf3KyNZi1Jt2dxvpQSIsaelNsukAofvlRF5lVUqHQw5/VGdqtp3Ffv+Ouy gAvAYxAiWER/CqPQ2gFnDG5byZMlT8B1cEJBJJkgIxxHuW+ti3qHsydrYULbOfuZ3Xxj TOKoqjKxc/VTGGIrtTo/fure6EK+mxkG5Y/AmkSeTgWByygGbYWoyiTrDmj9wi7gZgin SxU3kYpMqSo+d/IuscN6IUBsn8mv4IZCMLWZUluazB0RGubnxtR+TJO6bRft6c+mJjFF knYw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=AauVSUNS; 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 qr7-20020a05620a390700b0077da9bb9890si4454066qkn.6.2023.11.28.05.06.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 05:06:27 -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=AauVSUNS; 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 C3BFB3876880 for ; Tue, 28 Nov 2023 08:52:54 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 6CFDA3845BD2 for ; Tue, 28 Nov 2023 08:51:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6CFDA3845BD2 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 6CFDA3845BD2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701161504; cv=none; b=rHS5PxzlXdw3L00bw/pC6UYVoRH3fNJT34NtnOxKgfs8VgeBtSN3tNW1Ss9keQGMtFbIbraZvzUXV4QpG9i289WW/FVDWJidLST+a1NhA+qBGGjBsaGn/FzcSglkOkhVPq1866yunx7oGeASCRt5r7o41nUzX0ka80GnNYsQ7QU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701161504; c=relaxed/simple; bh=bjaSUEw69IKL1aMRQp1K3smbyjGns80D1uuNrEHk2d0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nhv9/1pwFYAgvDQ+yghzoZWVZNVyDgGt5on8ZH/7IDKNBqJDkgImkUAkopSP1cv/bhOEkeDSvYWb+ucxAmEbL/GsFowqgwCLEFkykrPvfLmMmKit/F5SeXL5T4RN0zXA4Olgw8GbUy5oTVRpVHQkTa0eA6GTWA4L6DGNTmB+oCg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1cf974e87d9so7564815ad.1 for ; Tue, 28 Nov 2023 00:51:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701161500; x=1701766300; 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=8506Kma4qk4mh6i8TY9tHbJ7ej0t0/2tauvigcP3l+Q=; b=AauVSUNSfEQZuokQGSj9dNZYBIHEzTG7g6rtEseWJNFzGDgsgd/q7Cf+19yldEK3RW CWnmX3ZnCRApBhX5ISP5TQXK9mAQCRoTypLqpoRCC1TKki5Wp8lhFixJatuVFgO2HF1t vPjclOxB7WFVCCSl26Hg4/+FQAZAFRmfObq1OnS51gS4sLkImMnJwnNEXGHYNa0N8FCY 5G5Km1EN60ctB9hL7QF1SkvvM1KC/K5CpxE+t3uqCZjRjaXlGk+QygLXae8TA8yplR4g VNIGWuSoWfJR69smbsmUqroCfizp9mleTk36BVZpvDwPsroFTVchVF0bpQCkgPDU0xh9 +tDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701161500; x=1701766300; 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=8506Kma4qk4mh6i8TY9tHbJ7ej0t0/2tauvigcP3l+Q=; b=H93BLkv9MP2It1k3GyasqnYGAh49qEWeV1SIOjIR+8pBdXFwUGfoyED+EiKskGAF70 AahKmNmL+G31iUDzqcgRhAFCe/AD8oy2Pc/Ubxuh4Cnu/JeXiskDKrKijzWxRzRezTAH 0TNGHrP2Wj9/qUukuSaMyGcNVq+tnRW2+jhXn+i1euBBGk5TUydcFSeWe0MTO+9jwQjR CAJHnaUX5p4xeZMKf+Gywr4TpTd74gctPOHt1UQCRUdj6iQtQgikubng0HkkhdQ86Koi FA1A40ShTfStKXyyIwKAWLaXJHrFa0cr+LSvv4bWgUDEeZamhfpqdOePSdKCuw8NNMnc IbRA== X-Gm-Message-State: AOJu0YzIY+JVyVs4JT7ln2qOBhlj81k5ld5/KG5PCBlONJzOczeXaRnp UiPNjo/xx4e1WxMiP0LXkKKRvoRabl2vxpVj X-Received: by 2002:a17:902:e80b:b0:1cf:a718:384 with SMTP id u11-20020a170902e80b00b001cfa7180384mr14681000plg.6.1701161500258; Tue, 28 Nov 2023 00:51:40 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id 20-20020a170902ee5400b001cf64c60d20sm9698062plo.37.2023.11.28.00.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 00:51:39 -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 v3 5/9] RISC-V: Initial ld.bfd support for TLSDESC. Date: Tue, 28 Nov 2023 17:51:05 +0900 Message-ID: <20231128085109.28422-6-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231128085109.28422-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20231128085109.28422-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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: 1783813150686279089 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. --- bfd/elfnn-riscv.c | 91 +++++++++++++++++++++++++++--- 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, 104 insertions(+), 10 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index d5190538503..8f63998aa5a 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 @@ -1774,6 +1806,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)); @@ -1784,6 +1817,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; @@ -2202,8 +2237,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); @@ -2506,6 +2541,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: @@ -2827,6 +2863,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) @@ -2892,11 +2937,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; @@ -2909,12 +2959,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; @@ -2996,10 +3050,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)) @@ -3219,7 +3292,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