From patchwork Mon Sep 4 06:12:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hau Hsu X-Patchwork-Id: 75207 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 4F4C63858C52 for ; Mon, 4 Sep 2023 06:13:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F4C63858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693808013; bh=qIQCjK6Q00GnuiDIbsV6cLMKGK3vfR72Qsqcthbhkwc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qAn9UqWa7kIo5ZU6sTM/hpMIz0VQevjoft/X/ppUbdKeR+71JZ6R8At4nni83NDxz j6JeY2dj99tYFhTkk3T/wltvvABy4HF6Lt+CHI89OZzRxpJJSeakHZOLyRgmTP8GYO q9gFQDDcEWI+QYwsWKP/+VKGfsiNjL3YkaYcgwSw= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 1200B3858D33 for ; Mon, 4 Sep 2023 06:13:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1200B3858D33 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-68bec3a9bdbso392863b3a.3 for ; Sun, 03 Sep 2023 23:13:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693807983; x=1694412783; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qIQCjK6Q00GnuiDIbsV6cLMKGK3vfR72Qsqcthbhkwc=; b=lo7qX61snHIk6t9zV/X8AL+4HXQF8XbTHkOH/59G1oF01yhh+7A2yFZjY6pPmIh3eH 69NYote5U0ndUXgwpF4Fr9Y1hpAcaoc9Dk3nUlLjCPGebLnStNf1d+5Zhydh7yN5RkKL H4SJSvB3D0/stZtuqt4znl5veqN99+dy7cA8VjBUP4n8k2Ozl0Wh7yaQ9cvBM28mkOYo xBJsQ42qtBpTvJarPWYpia854Evqbf1Pld5ObyX41POKcWUzE/LyjAtzdZX0wc/HEKOs RtzqV8K5glbqMuRhPNpvZcDHI2oZPHPOQclhPzQNoMNZaQmnGw4z+zfj+zBO38awMr5v lUIQ== X-Gm-Message-State: AOJu0YxS/8eg6N74wM382sYsg1kPoQeMUcZg206hZXRG0VnGZuLdu3rQ JBh3N847LFsMz4N6wtacYtMt7w== X-Google-Smtp-Source: AGHT+IGi15XjEXQFkNUV6DA/NiUrKZodirDqpOCIFzhUvM7mnjhfuwqTmCmikaMYfXgqWtT5HsYnwQ== X-Received: by 2002:a05:6a00:b87:b0:68b:4e07:1358 with SMTP id g7-20020a056a000b8700b0068b4e071358mr8716442pfj.11.1693807983015; Sun, 03 Sep 2023 23:13:03 -0700 (PDT) Received: from hsinchu15.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id e22-20020aa78256000000b0068c676f1df7sm6582276pfn.57.2023.09.03.23.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 23:13:02 -0700 (PDT) To: hau.hsu@sifive.com, binutils@sourceware.org, kito.cheng@gmail.com Subject: [PATCH] RISC-V: Use the right PLT address when making a new entry Date: Mon, 4 Sep 2023 14:12:57 +0800 Message-Id: <20230904061257.17425-1-hau.hsu@sifive.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Hau Hsu via Binutils From: Hau Hsu Reply-To: Hau Hsu Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org Sender: "Binutils" When building static executable for IFUNC we should fill .igot.plt instead of .got.plt. .got.plt might be NULL and fail following tests with segmentation fault: FAIL: ifunc-reloc-call-01 (rv32-exe) FAIL: ifunc-reloc-call-02 (rv32-exe) FAIL: ifunc-reloc-pcrel (rv32-exe) FAIL: ifunc-reloc-pcrel (rv64-exe) Since we already choose which plt setion to be used earlier: if (htab->elf.splt != NULL) { plt = htab->elf.splt; gotplt = htab->elf.sgotplt; relplt = htab->elf.srelplt; } else { plt = htab->elf.iplt; gotplt = htab->elf.igotplt; relplt = htab->elf.irelplt; } use the variable `gotplt` to fill the plt entry. More detail: riscv_make_plt_entry() has a parameter `got` that is used for compact plt, but not used in normal mode. With older GCC, the address is random, but since `got` is not used, the random address doesn't matter. Starting from GCC 12, GCC will initialize stack variables to 0, which triggers segmentation fault when calling riscv_make_plt_entry() immediately. --- bfd/elfnn-riscv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 3d228e95375..d90e598ec83 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -3549,7 +3549,7 @@ riscv_elf_finish_dynamic_symbol (bfd *output_bfd, /* Fill in the PLT entry itself. */ if (! riscv_make_plt_entry (output_bfd, - sec_addr (htab->elf.sgotplt), got_address, + sec_addr (gotplt), got_address, header_address, h->plt.offset, plt_entry)) return false;