public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Hau Hsu <hau.hsu@sifive.com>
To: Hau Hsu <hau.hsu@sifive.com>,
	binutils@sourceware.org, kito.cheng@gmail.com
Subject: Re: [PATCH] RISC-V: Use the right PLT address when making a new entry
Date: Mon, 4 Sep 2023 15:02:47 +0800	[thread overview]
Message-ID: <7F4FEA75-B86F-47C3-8E1C-DFB7B03F3A5A@sifive.com> (raw)
In-Reply-To: <20230904061257.17425-1-hau.hsu@sifive.com>

Sorry I accidentally sent a patch for fixing an internal bug. Please ignore this mail ... 

> Hau Hsu <hau.hsu@sifive.com> 於 2023年9月4日 下午2:12 寫道:
> 
> 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;
> -- 
> 2.40.1
> 


      reply	other threads:[~2023-09-04  7:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04  6:12 Hau Hsu
2023-09-04  7:02 ` Hau Hsu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7F4FEA75-B86F-47C3-8E1C-DFB7B03F3A5A@sifive.com \
    --to=hau.hsu@sifive.com \
    --cc=binutils@sourceware.org \
    --cc=kito.cheng@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).