From patchwork Thu Aug 17 18:05: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: 135929 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp881860vqi; Thu, 17 Aug 2023 11:06:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZ0tuRbnkRt0eGEJQqGcLPq7ihOCzFF/om2dTnu1dannZyntGQzGyoqCUUpGVQnNAOFclx X-Received: by 2002:a05:6512:3c96:b0:4fd:fecf:5d57 with SMTP id h22-20020a0565123c9600b004fdfecf5d57mr64407lfv.39.1692295565808; Thu, 17 Aug 2023 11:06:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692295565; cv=none; d=google.com; s=arc-20160816; b=FVXEYwrlsci/B92tWCkN5OvwtvRukKPwhbxUk0um9EeBMScCRJS5rQVSBr25V6jmBa RBNHeJ7nUrFQFXerMTUIATSnzqgar/qlVxNnhafnf1CoZRaYie9ZIZdJGpOWihu2KkSO RxEekdtDU3FtpnUF5bNVsl7w2Bb3V4bXuGh29K0d+MIaCPxWApe6vdXOH4QSc0o+L3Yg xCKKO3IBeQZhLT2bc0tHkPkmVDTgXnx8ivf0/j+OAcXj1Z6P2QhRGWTmnEkvnuITHCoZ tAIfDp/g0SE0FK/3ryMwMDvMPISu0p6QYT0pumbpy4VE6UOZljTcLvp+f/ADUtHa04Nl XtKA== 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:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=xbbhymrI8m1DyvdFa5ytLRnT9vsbOsj0dVBReNG/7wc=; fh=RnOK2kMt7+DQSwabMVlm0F5hv9+FMo5J9F5oi1ILKLA=; b=frTIJB/BiQJK16OQ8FkJENm04aqmqu3xVLfWOMQbdWPkaL9ouTRNwllw4gc9xIzbrH pccUh0mBv1ASr5Ei6O4zDNQ8HFDlhJnXzFXhmg9u0nxi2I/v3azD8XIDeZ+5QP5C1vOa 78kPrnfaaLDAqNlIxV8jbhoaJozTXdMco56LiYrcCqCLpZydv4ceXxWuD1eFjsFpvj5I 68Usn83XahnakCpb4fsf9QY3AiUsPYnOjO0/MvPERS1U6zrgCEAhkwLFYm23tIuWDxNS SfDGnF7f0FFFyHa1aX6zU+c8p5IoEzw2XE0ola+wFoG3NezyCZkymQgiEPEVwJ5cBN6z Op6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=dooMGlxi; 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 t26-20020aa7d4da000000b00523366b6448si57218edr.9.2023.08.17.11.06.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:06:05 -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=dooMGlxi; 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 E6EDD385DC15 for ; Thu, 17 Aug 2023 18:06:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E6EDD385DC15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1692295563; bh=xbbhymrI8m1DyvdFa5ytLRnT9vsbOsj0dVBReNG/7wc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=dooMGlxiPnDI7whHguZWv0LIGaAPR4XXadv51hQzsTOWp6c3U7v2EtOrYcbCgZ/or Ok0HoK+vhmL+hXM6ub9ix2jYa5RFrP/8tfydWxuXgAFDDGoF/u8Izw6W5sL56IDJqB 5T3Kkc1H6HR7AfLWSGGQit2MaKzibLXKsrXVTTy4= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 6BEC1385624C for ; Thu, 17 Aug 2023 18:05:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6BEC1385624C Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bf1876ef69so109235ad.1 for ; Thu, 17 Aug 2023 11:05:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692295553; x=1692900353; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xbbhymrI8m1DyvdFa5ytLRnT9vsbOsj0dVBReNG/7wc=; b=kQon3CJt5E069rZRcVu5mcW29AGJ5tGHv/RakdvvR59VTiWRedZw0ck3OjtqIevhUQ Xyo3gMiP9BZjFuyA6uN4aBXXINKc46DW6XT1TM8rtcbk9vgsWkj1vkIog4QjRw9+Bx8z dA6zFf+sEMfPHE1GpX3t67iJhk87Y+h7VAofZsTUKHQH8ErlO5VAmReDqsHcGNnPhPfT Nqpe6b+g5Ke03CJgGOq7G2KYrMFRzbJ74guxNBrFIK4lVoE6CHhKlnEeau8n1bswRNU4 nKg58VrYO1Y5MdNKIfxS9aaxhuiAomV6iNNV5BYjYQe1sjNxGcq+V777kQ9OOcKknwWv DO9w== X-Gm-Message-State: AOJu0Ywkh4BCVNq786hy7v0GlfW9mesjI+7hWuLDtIVsx3oRLnlrb5M9 ohsuVXmAhnSfoLt0Ws+DEjMyGDWdlH2zDBo+ X-Received: by 2002:a17:903:11c4:b0:1bf:1a9e:85f7 with SMTP id q4-20020a17090311c400b001bf1a9e85f7mr161882plh.1.1692295552789; Thu, 17 Aug 2023 11:05:52 -0700 (PDT) Received: from localhost (zz20184013906F627101.userreverse.dion.ne.jp. [111.98.113.1]) by smtp.gmail.com with ESMTPSA id 13-20020a170902ee4d00b001b7fd27144dsm72700plo.40.2023.08.17.11.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Aug 2023 11:05:52 -0700 (PDT) To: binutils@sourceware.org Cc: rui314@gmail.com, ruiu@bluewhale.systems, Tatsuyuki Ishi Subject: [PATCH] RISC-V: Fix local GOT and reloc size calculation for TLS. Date: Fri, 18 Aug 2023 03:05:04 +0900 Message-ID: <20230817180508.120318-2-ishitatsuyuki@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 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: 1774500515073621461 X-GMAIL-MSGID: 1774500515073621461 The previous code did not account correctly for two cases: * A TLS symbol can be referenced with multiple TLS types, in which case it only allocated the maximum slot size among the types, instead of the sum. * TLS relocations are only needed for DLLs, unlike normal symbols which requires relocations for all PIE code. Similar to the size calculation for global symbols, break up the calculation into TLS and non-TLS symbols, and handle the two cases above correctly. --- No regression in binutils and gcc tests for rv64gc. This contribution is made on behalf of Blue Whale Systems, which has copyright assignment on file with the FSF. bfd/elfnn-riscv.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 09aa7be225e..02b46835cc7 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -1562,12 +1562,27 @@ riscv_elf_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) if (*local_got > 0) { *local_got = s->size; - s->size += RISCV_ELF_WORD_BYTES; - if (*local_tls_type & GOT_TLS_GD) - s->size += RISCV_ELF_WORD_BYTES; - if (bfd_link_pic (info) - || (*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE))) - srel->size += sizeof (ElfNN_External_Rela); + if (*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE)) + { + if (*local_tls_type & GOT_TLS_GD) + { + s->size += 2 * RISCV_ELF_WORD_BYTES; + if (bfd_link_dll (info)) + srel->size += sizeof (ElfNN_External_Rela); + } + if (*local_tls_type & GOT_TLS_IE) + { + s->size += RISCV_ELF_WORD_BYTES; + if (bfd_link_dll (info)) + srel->size += sizeof (ElfNN_External_Rela); + } + } + else + { + s->size += RISCV_ELF_WORD_BYTES; + if (bfd_link_pic (info)) + srel->size += sizeof (ElfNN_External_Rela); + } } else *local_got = (bfd_vma) -1;