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: 137441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp915898vqo; Sun, 3 Sep 2023 23:13:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFVZxf9FhdUoggh9n04h0jQh8vsURnTBLj87myLdo1KTzJDzJ2uInGy8Sl4nRoVohbfIID X-Received: by 2002:a05:6402:1518:b0:51e:309:2e11 with SMTP id f24-20020a056402151800b0051e03092e11mr7792857edw.36.1693807994910; Sun, 03 Sep 2023 23:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693807994; cv=none; d=google.com; s=arc-20160816; b=B8h5mrcimHCzP0IDx6MQTS/IWf2OIoy282/+7Xy8rUmLGjdvuwH0KErp5xa4jAzeal ausKnRj+UegqZqsfm7fYUauYC+5pm3wwKIvzXg3JNEX6Xu+3C2ZIXEJ7s+M1YRvAC5Az Zju787uOA7Q/5CTiD6oAanE8HfWxHV8Rwoz7KllR7AybRVdgOgLhZrdbw/PwQAG4tSKH LVGbrjSsYwuZ3JSrxfWc+76fMejQ+VsRIoWg5ZPMZtTLOjc5gRQF33RLHiOTVMoP4gUN I3+/Xkxh54RiNs2wgGMmWP513cNgaUrPUD0iV/pe6j9ft33Uur9kfZHBUbX5WPW4dBCI sCzg== 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:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=qIQCjK6Q00GnuiDIbsV6cLMKGK3vfR72Qsqcthbhkwc=; fh=YsH7QSfdsXKbT0RUvNemARzjrFgh1/I7U6dG01CJ3FU=; b=pl5xsYn1dJlHYKK65OxebXcM+mQmqLytsjVepaXqQugkzrniiyF7p7utnKaMP7GR06 8fDWJJCLkZjLt/sX4xDZ+7fj/tJK8foTOavt4wJLulklzzfXgoNBp+pR+Y4quxzZUwNl yw0aEiVkJY+bDrEggQv5ydAO5meRsUJHeNW5KtCL5Vw6gsxgwqq+u7jBIqCgN1Dphajj zGmRJscxVYxlKTrtc60+Jhi7UCCtGTg4G8kL3CdK1AE1WTsPMqmiNe/fBW4PejJKeR3y 1fg08swXMRZwsH9+u8oTVOw0vvWEzx7CEdtR5i+CyrK5Upg7yihL9QX31JysKauU4mSE kQxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="Z4B/8jBA"; 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 t16-20020aa7d710000000b0052a1aa609a5si5917653edq.357.2023.09.03.23.13.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Sep 2023 23:13:14 -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="Z4B/8jBA"; 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 89B003858296 for ; Mon, 4 Sep 2023 06:13:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89B003858296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693807993; bh=qIQCjK6Q00GnuiDIbsV6cLMKGK3vfR72Qsqcthbhkwc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Z4B/8jBAftkgaKMdJEAzQlYVa1ux/5K2VY933BWa0iy8KTdL29ppVc2EF0pSWh46z RhaD6NRIAEZpNtEQ/Oq1QuebCNiTrpn0hLhew77MRuQ9KsDz3zcEWZ2EpvZOzg6es5 I2aUKWWiHsiiGBzBU4NkcZFiQl5vCoUHnRhuuNsU= 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-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+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776086412216269368 X-GMAIL-MSGID: 1776086412216269368 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;