From patchwork Tue Feb 20 17:55:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tatsuyuki Ishi X-Patchwork-Id: 203721 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp568755dyc; Tue, 20 Feb 2024 09:59:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWNfbGKeyhhTC1cUh9AFV7j7b7Der7192HUq5m3WpEXpcsELYRAS44pXu5IyuNVtmu4zuaba41BzFdDoNgYZ0zHeKc3Kg== X-Google-Smtp-Source: AGHT+IEc4CWquZyGUeMD44I508oypcAuwhhoAmmC57ruFLHokoJLZPW38STK/9bhXFh7SlNigTKW X-Received: by 2002:a05:6214:626:b0:68f:301b:5481 with SMTP id a6-20020a056214062600b0068f301b5481mr5484167qvx.13.1708451945311; Tue, 20 Feb 2024 09:59:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708451945; cv=pass; d=google.com; s=arc-20160816; b=SUmg3GTGrx1/x22htYVywFMabRqr+PdvYlGTiJZ5vGvJRVwDybBJqxdsY0JLSUL7go QxCROyKWG1Vh8S5aBnZN/5nVKjKfgSa6LWPLLgIObztbHR3xjHzBWICpLIe9GNOyjEDj IgL6smDU20ECiScaYxv5WW36EBsapQeYUijkB9SdIVnEfRc4aK83GixcfltFgGL1+i1Y ON3DrTMiI09tz6eIZpnSjXInfqdOUe4JXLh8n190x0kIFYEtxorc6JaaiAKuiwbtjkQ6 umH0CG1enVZkzGY3JTTbdH7qNM8nu1XoX15P9Ykz+XtWo7SWkIpE5YVnqcpjDFY97YaO LXCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=ytrMX7M8wCHAzq3bbA4ODKo8vb46faf/l8fO4vYcxuM=; fh=YSa8tbAsFM03BU4mjhbbHsdQe1vIF6KegOb6Q0/FrUw=; b=JcM2Z5E66TDuueWT5+2sDui1g8DfMQazhJ71ax31bIeYrJPagEq02RZehHkEk9SE+g Q9OEX+1aUlcVg8tVwnXv8APldpYMvvXv7glEZKJefKboFFzD3ewCbMAxDYAYKGcYFYLE zoCIpAiaKMDNiPegOu72R1IdSqLQJTCcdHZTkFxE5n2e4gdNFtQxlnjihDGuNhk6C1Yy C8dHpEmnYRBMfaFI/1kFOxoyqqc1Tzn4EvqrPV69spzPvOB6HhfB931koWoYPp1RcmWP tMlG6mIaFk+4kvTiJX/xzevx2CDHErKoAFzw/OPcI44+PM22IeWbglfSbCTE0C8m205H 8uPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iQBZl2M+; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z10-20020a056214040a00b0068f07ff2506si9203099qvx.223.2024.02.20.09.59.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:59:05 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iQBZl2M+; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2474838582A0 for ; Tue, 20 Feb 2024 17:59:03 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 2C2AB3858D39 for ; Tue, 20 Feb 2024 17:56:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C2AB3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2C2AB3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451796; cv=none; b=rpa5giyIk3xPilfILGr/z4L5zjw8fl4kQXPltn4uIq6XSXtD8VcbAjtgMUaFQG+6BrIMbDqqbjCKrKHbMOVt7tvy9wnrjm55AFHb/P1FmHsF664ja4HjP/pG2ZeK5z93Bouf6ah5piLGuPgNIDLrz0MWY1vgVZ3vpV3th9wf3Dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708451796; c=relaxed/simple; bh=z9ppKNL9EowFqG6WpswAh0qndDlORpnZVU99eS9Yr6w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=l7/LxU6EPn9wr+iAsOW4fyx9XnnaJ65d9rv/9KYtQOPOcYps3Cgq6cRc9vMahXOCVZMgbvn5L0xXNgpXajLd8ErHP0uoESYPS2QAHgZZQVu42rULi52dsIcCUdD06b2S3LMfbFjFwLRT7WHPfq+33sE9lmHFO8GZ2g9PBBEnRdM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6e45c698090so476893b3a.0 for ; Tue, 20 Feb 2024 09:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708451791; x=1709056591; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ytrMX7M8wCHAzq3bbA4ODKo8vb46faf/l8fO4vYcxuM=; b=iQBZl2M+ZsgTV4S7sbMuDMZBCgUDEexYSVxHXBQvMjb0jTfhLon4u03JMslKvONExw 4kL/2qg9nhneaNz3vd60yQ7zJjel1ZitydAHdYKc0+u3+EgT6YAxbJhZYI8M+pL1DHbg /0gF1cjlztNKj17W7VXmkidVPK0mFenBjlaNRmM3I9w1tk9RP7J9NkWqG057daJ5zsCt 2QznIE8dlVqb7mBO7G/IWY0iX7tNbc4cQd8qyAI5sanE3Cus1MoA8q4JPgVBvYEQGlb9 aySSPdmrXK33yxSWXIP0uvd5bFSe6itSG71ERXzyfzJIJ0suZcMR4Rinb6MQ3FqQygC1 pDoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708451791; x=1709056591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ytrMX7M8wCHAzq3bbA4ODKo8vb46faf/l8fO4vYcxuM=; b=DitDgRUzQShnhsFmeQR9sJz3JG8rPHr87gnFC+w8DBITRHDO1QNTxG5HHCzww7qi+L XOK/bHrCi0FuBKAqKEbBUSDQbQFrFmEEAyw93kfprXO3p16IfOVWUPAGzfw1gtC+k0mF fYsWkkePz4MaUmtp/0FunxnxRNKH00h2xTsfiZoyU3Xbcw3BdpZfqJQg+v6JO2uHg/+t Qo59L0pLPTa9aHYvwfP54TM5yjmVX0Z3fubMLhjmH0827NmdrBVTbWDzAlD0gI3JeTmu JgPNHiyRRaQGBx34v5mLpx4ui2onR+Z/P4ZF4WxT6ktv7Az5dEXy4BGE/LInFGTlo0iY 0QCw== X-Gm-Message-State: AOJu0YyXzt2eO2G9s29tSrEKD/RBIIZzY+yRtOut5RuucGxGG7vGr7Tz JC5hNmAbshCVvS3PjDMypyooK1Nq+Sg8rdE1696ZHDe83rQwsROpdwAIxOgKB52S/g== X-Received: by 2002:a05:6a21:328a:b0:1a0:b20e:531b with SMTP id yt10-20020a056a21328a00b001a0b20e531bmr3893482pzb.4.1708451791196; Tue, 20 Feb 2024 09:56:31 -0800 (PST) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id lb26-20020a056a004f1a00b006dde1781800sm7358072pfb.94.2024.02.20.09.56.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 09:56:30 -0800 (PST) From: Tatsuyuki Ishi To: binutils@sourceware.org Cc: i@maskray.me, nelson@rivosinc.com, rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH v4 4/9] RISC-V: Define and use GOT entry size constants for TLS. Date: Wed, 21 Feb 2024 02:55:51 +0900 Message-ID: <20240220175556.304692-5-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220175556.304692-1-ishitatsuyuki@gmail.com> References: <20230817180852.121628-2-ishitatsuyuki@gmail.com> <20240220175556.304692-1-ishitatsuyuki@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774500850174321211 X-GMAIL-MSGID: 1791441706791281817 As the size calculation is split by global and local symbols, using a shared constant definition for its size improves clarity. bfd/ * elfnn-riscv.c: Add macros for sizes of a normal GOT entry, TLS GD and TLS IE entry. (allocate_dynrelocs): Replace GOT size expressions with the new constants. (riscv_elf_size_dynamic_sections): Likewise. (riscv_elf_relocate_section): Likewise. --- bfd/elfnn-riscv.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index e5cecd79cf3..17d44979d7e 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -298,6 +298,8 @@ riscv_is_insn_reloc (const reloc_howto_type *howto) #define PLT_HEADER_SIZE (PLT_HEADER_INSNS * 4) #define PLT_ENTRY_SIZE (PLT_ENTRY_INSNS * 4) #define GOT_ENTRY_SIZE RISCV_ELF_WORD_BYTES +#define TLS_GD_GOT_ENTRY_SIZE (RISCV_ELF_WORD_BYTES * 2) +#define TLS_IE_GOT_ENTRY_SIZE RISCV_ELF_WORD_BYTES /* Reserve two entries of GOTPLT for ld.so, one is used for PLT resolver, the other is used for link map. Other targets also reserve one more entry used for runtime profile? */ @@ -1320,7 +1322,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) /* TLS_GD needs two dynamic relocs and two GOT slots. */ if (tls_type & GOT_TLS_GD) { - s->size += 2 * RISCV_ELF_WORD_BYTES; + s->size += TLS_GD_GOT_ENTRY_SIZE; if (need_reloc) htab->elf.srelgot->size += 2 * sizeof (ElfNN_External_Rela); } @@ -1328,14 +1330,14 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) /* TLS_IE needs one dynamic reloc and one GOT slot. */ if (tls_type & GOT_TLS_IE) { - s->size += RISCV_ELF_WORD_BYTES; + s->size += TLS_IE_GOT_ENTRY_SIZE; if (need_reloc) htab->elf.srelgot->size += sizeof (ElfNN_External_Rela); } } else { - s->size += RISCV_ELF_WORD_BYTES; + s->size += GOT_ENTRY_SIZE; if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h) && ! UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) htab->elf.srelgot->size += sizeof (ElfNN_External_Rela); @@ -1563,20 +1565,20 @@ riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) { if (*local_tls_type & GOT_TLS_GD) { - s->size += 2 * RISCV_ELF_WORD_BYTES; + s->size += TLS_GD_GOT_ENTRY_SIZE; if (bfd_link_dll (info)) srel->size += sizeof (ElfNN_External_Rela); } if (*local_tls_type & GOT_TLS_IE) { - s->size += RISCV_ELF_WORD_BYTES; + s->size += TLS_IE_GOT_ENTRY_SIZE; if (bfd_link_dll (info)) srel->size += sizeof (ElfNN_External_Rela); } } else { - s->size += RISCV_ELF_WORD_BYTES; + s->size += GOT_ENTRY_SIZE; if (bfd_link_pic (info)) srel->size += sizeof (ElfNN_External_Rela); } @@ -2928,7 +2930,7 @@ riscv_elf_relocate_section (bfd *output_bfd, reference's GOT slot follows the GD reference's slots. */ ie_off = 0; if ((tls_type & GOT_TLS_GD) && (tls_type & GOT_TLS_IE)) - ie_off = 2 * GOT_ENTRY_SIZE; + ie_off = TLS_GD_GOT_ENTRY_SIZE; if ((off & 1) != 0) off &= ~1;