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: 74282 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 60448385C6E6 for ; Thu, 17 Aug 2023 18:06:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60448385C6E6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1692295583; 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=pr6HO/sKxwqEiC/Hsk2urE9O51sD5XY/Ps2UcR7soOlujM3vGKSNvE1WW0/6Esm4M UJgwwV6Mlm33M0z7rJLxsdk8rtTZp9MaMl5VxeEoXHd1/A4wI4arlDM7sKO76js+RE IN6OnehkMVj3Owj7ftJKGg/Yh1AgitSA0WsmOAJ4= 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-Google-Smtp-Source: AGHT+IGcHyl5sJ+Vf2pNq+bVzqDcQ1RjaALV15Y8c5q/GWAka7piikx9o8UnfzBVZTMNifnm/F1n7w== 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+patchwork=sourceware.org@sourceware.org Sender: "Binutils" 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;