[PATCH 2/2] RISC-V: Don't generate R_RISCV_RELATIVE if symbol referenced section is SH_ABS
Nelson Chu
nelson@rivosinc.com
Fri Aug 22 02:36:40 GMT 2025
On Thu, Aug 21, 2025 at 1:42 PM Fangrui Song <maskray@sourceware.org> wrote:
> On Wed, Aug 20, 2025 at 9:33 PM Nelson Chu <nelson@rivosinc.com> wrote:
> >
> > It's werid if it's absolute symbol but have a relative reloc for got
> entry
> > under pie. So don't generate relative reloc if symbol referenced
> section is
> > SH_ABS. However, x86 allows the absolute symbol defined in linker
> script has
> > a relative reloc, not sure if risc-v needs this or not.
> >
> > diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
> > index 6ff64325f85..aac061fb43d 100644
> > --- a/bfd/elfnn-riscv.c
> > +++ b/bfd/elfnn-riscv.c
> > @@ -2880,7 +2880,8 @@ riscv_elf_relocate_section (bfd *output_bfd,
> > if (h->dynindx == -1
> > && !h->forced_local
> > && h->root.type != bfd_link_hash_undefweak
> > - && bfd_link_pic (info))
> > + && bfd_link_pic (info)
> > + && !bfd_is_abs_section(h->root.u.def.section))
> > relative_got = true;
> >
> > bfd_put_NN (output_bfd, relocation,
>
> Reviewed-by: Fangrui Song <maskray@sourceware.org>
>
> I haven't checked, but I suspect that the condition `h->root.type !=
> bfd_link_hash_undefweak` should be generalized to undefined.
> In a -pie -z undefs or -pie --noinhibit-exec link, an undefined
> non-weak symbol should be treated as an absolute value as well.
> -z undefs suppresses the "undefined symbol" error.
>
Thanks for the information, I will check this later ;)
Nelson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20250822/6848c29a/attachment.htm>
More information about the Binutils
mailing list