From patchwork Fri Apr 21 08:28:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nelson Chu X-Patchwork-Id: 86171 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp909041vqo; Fri, 21 Apr 2023 01:28:58 -0700 (PDT) X-Google-Smtp-Source: AKy350bdsouUgTYdjjTnMzue0v3/stAIX+1+ZIeHbgOuqPkhpQnfBBI0z2sP+s82dlPwcgQHLM4u X-Received: by 2002:a17:906:b044:b0:94e:547b:6322 with SMTP id bj4-20020a170906b04400b0094e547b6322mr1798546ejb.25.1682065738827; Fri, 21 Apr 2023 01:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682065738; cv=none; d=google.com; s=arc-20160816; b=cvkFvoPcw6h5Ul9sgxm/sSDrYa8XssabQVeAFLnk/JhiQWLh99F4HSHTVLKPnQfqBT yIQYJEPqP3RFsElzEQREeNxtGLlT7EzwDMRieDYb1Rbsbh2SMqueV1q3esmntTmjc25V VjUEQ+VtgVkQh7eUiTEo5AVII6UNhR/5724bkP3ZBgCoeCMy074q5lnslGm356rp6Ryj xx2TeU2/fiYULuiFF68AuGUoUs2HBnh61ngLdOGYhCJAPK2tpOCUdMZpcsml11KIyrDQ FkqdEy3HjXUjpmZXs73ZdhC4nWj9n2ilF8OMeCti6Dt09S2J62Q6VVT6Zemz148ISmpc rIIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dmarc-filter :delivered-to; bh=/5WTw0eF9DXkF0zpEyzNwZdC0fjEY3YBEU7imbJgqvI=; b=nYIlvkatCVWwQNDYXAL3DN1NHNcD2WacPnawNaoKLiujLfdsZe2DgR24HEtD0b7IPg 61x5TTep9+MnEQiLCwUCmYBOxEgUUpQ7u6+c1RVSGENNPaFCmpoV8Aa4lYnvONGznUSK uOH1oAZ1HjdnAXYyzJ88YSyQaUNeUOsRH967paXFJtPKuPjdNdR7tfv5c7UQILPb07tX pLaWaFd8v6NlmytkwtavyHof3uMwdFpA4mc1A02jyV4qx0Yji553aRazHnpkLkTzxXYn 6smgCJlKoUebQZ6YYgwosn/lrWo36qvO4glb5Sut9H6o54M/oKRbqdttyxdUX7jAZrpY xdng== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v24-20020a17090606d800b0094f256d8decsi3059906ejb.532.2023.04.21.01.28.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Apr 2023 01:28:58 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C0773857351 for ; Fri, 21 Apr 2023 08:28:57 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from NelsondeMBP.localdomain (114-25-92-140.dynamic-ip.hinet.net [114.25.92.140]) by sourceware.org (Postfix) with ESMTP id 9A4523858C83 for ; Fri, 21 Apr 2023 08:28:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A4523858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=NelsondeMBP.localdomain Received: by NelsondeMBP.localdomain (Postfix, from userid 501) id 603DCBDB05C; Fri, 21 Apr 2023 16:28:41 +0800 (CST) From: Nelson Chu To: binutils@sourceware.org, jim.wilson.gcc@gmail.com, palmer@dabbelt.com, kito.cheng@sifive.com Cc: nelson@rivosinc.com Subject: [PATCH 1/2] RISC-V: Relax R_RISCV_[PCREL_]LO12_I/S to R_RISCV_GPREL_I/S for undefined weak. Date: Fri, 21 Apr 2023 16:28:38 +0800 Message-Id: <20230421082839.41542-1-nelson@rivosinc.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KHOP_HELO_FCRDNS, NO_DNS_FOR_FROM, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_PBL, RCVD_IN_SORBS_DUL, RDNS_DYNAMIC, SPF_HELO_NONE, SPF_NONE, 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.29 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 Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763773764112246466?= X-GMAIL-MSGID: =?utf-8?q?1763773764112246466?= bfd/ *elfnn-riscv.c (_bfd_riscv_relax_lui): For undefined weak symbol, just relax the R_RISCV_LO12_I/S to R_RISCV_GPREL_I/S, and then don't update the rs1 to zero until relocate_section. (_bfd_riscv_relax_pc): Likewise, but for R_RISCV_PCREL_LO12_I/S. --- bfd/elfnn-riscv.c | 55 ++++++----------------------------------------- 1 file changed, 6 insertions(+), 49 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index e90e36b58bb..499f51ee857 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -4552,27 +4552,11 @@ _bfd_riscv_relax_lui (bfd *abfd, switch (ELFNN_R_TYPE (rel->r_info)) { case R_RISCV_LO12_I: - if (undefined_weak) - { - /* Change the RS1 to zero. */ - bfd_vma insn = bfd_getl32 (contents + rel->r_offset); - insn &= ~(OP_MASK_RS1 << OP_SH_RS1); - bfd_putl32 (insn, contents + rel->r_offset); - } - else - rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_I); + rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_I); return true; case R_RISCV_LO12_S: - if (undefined_weak) - { - /* Change the RS1 to zero. */ - bfd_vma insn = bfd_getl32 (contents + rel->r_offset); - insn &= ~(OP_MASK_RS1 << OP_SH_RS1); - bfd_putl32 (insn, contents + rel->r_offset); - } - else - rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_S); + rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_S); return true; case R_RISCV_HI20: @@ -4737,7 +4721,6 @@ _bfd_riscv_relax_pc (bfd *abfd ATTRIBUTE_UNUSED, bool undefined_weak) { struct riscv_elf_link_hash_table *htab = riscv_elf_hash_table (link_info); - bfd_byte *contents = elf_section_data (sec)->this_hdr.contents; bfd_vma gp = riscv_global_pointer_value (link_info); BFD_ASSERT (rel->r_offset + 4 <= sec->size); @@ -4830,39 +4813,13 @@ _bfd_riscv_relax_pc (bfd *abfd ATTRIBUTE_UNUSED, switch (ELFNN_R_TYPE (rel->r_info)) { case R_RISCV_PCREL_LO12_I: - if (undefined_weak) - { - /* Change the RS1 to zero, and then modify the relocation - type to R_RISCV_LO12_I. */ - bfd_vma insn = bfd_getl32 (contents + rel->r_offset); - insn &= ~(OP_MASK_RS1 << OP_SH_RS1); - bfd_putl32 (insn, contents + rel->r_offset); - rel->r_info = ELFNN_R_INFO (sym, R_RISCV_LO12_I); - rel->r_addend = hi_reloc.hi_addend; - } - else - { - rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_I); - rel->r_addend += hi_reloc.hi_addend; - } + rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_I); + rel->r_addend += hi_reloc.hi_addend; return true; case R_RISCV_PCREL_LO12_S: - if (undefined_weak) - { - /* Change the RS1 to zero, and then modify the relocation - type to R_RISCV_LO12_S. */ - bfd_vma insn = bfd_getl32 (contents + rel->r_offset); - insn &= ~(OP_MASK_RS1 << OP_SH_RS1); - bfd_putl32 (insn, contents + rel->r_offset); - rel->r_info = ELFNN_R_INFO (sym, R_RISCV_LO12_S); - rel->r_addend = hi_reloc.hi_addend; - } - else - { - rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_S); - rel->r_addend += hi_reloc.hi_addend; - } + rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_S); + rel->r_addend += hi_reloc.hi_addend; return true; case R_RISCV_PCREL_HI20: