[PATCH] RISC-V: Optimize lui and auipc relaxations for undefweak symbols

Nelson Chu nelson.chu@sifive.com
Mon Sep 23 01:21:00 GMT 2019


Dear Jim,

> When doing some last minute testing, I got some LTO errors that were
> difficult to reproduce.  The problem turns out to be the part of the
> patch that does
> -         else if (h->root.u.def.section->output_section == NULL
> -                  || (h->root.type != bfd_link_hash_defined
> -                      && h->root.type != bfd_link_hash_defweak))
> +         else if (!undefined_weak
> +                  && (h->root.u.def.section->output_section == NULL
> +                      || (h->root.type != bfd_link_hash_defined
> +                          && h->root.type != bfd_link_hash_defweak)))
> This causes us to fall through to code that does
>     sym_sec = h->root.u.def.section
> but this isn't valid for an undefined variable.  def.section happens
> to overlap undef.abfd, and we end up with a abfd pointer instead of a
> section pointer, which can cause a crash we end up with the wrong
> garbage values there.  Usually it works, sometimes it crashes.  I
> changed the code to add an explicit else if for undefined_weak to set
> symval and sym_sec to reasonable values.
>
> I committed the patch with my change, which is attached below.

Thanks so much!  This modified patch is more reasonable.
I am grateful for your help :)

> I also rewrote the ChangeLog entries.  They are supposed to describe
> the textual changes you are making.  I'm old school; I prefer
> ChangeLog entries written like the ones I checked in.

OK I will pay special attention to this in the future :)



More information about the Binutils mailing list