PR27228, .reloc wrong symbol emitted for undefined local symbol

H.J. Lu hjl.tools@gmail.com
Sun Jan 24 12:17:57 GMT 2021


On Sat, Jan 23, 2021 at 9:51 PM Alan Modra via Binutils
<binutils@sourceware.org> wrote:
>
> Local symbols are of course supposed to be defined by their object
> file, but in other cases a local symbol is promoted to global by gas
> if undefined and referenced.  This patch stops gas wrongly replacing a
> local undefined symbol with the undefined section symbol, resulting in
> a .reloc undefined local symbol being emitted as global.
>
> Committed mainline and 2.36 branch.
>
>         PR 27228
>         * write.c (resolve_reloc_expr_symbols): Don't assume local symbol
>         is defined.
>
> diff --git a/gas/write.c b/gas/write.c
> index 75ba971eb4b..95922bb25a0 100644
> --- a/gas/write.c
> +++ b/gas/write.c
> @@ -737,7 +737,9 @@ resolve_reloc_expr_symbols (void)
>                  prevent the offset from overflowing the relocated field,
>                  unless it has enough bits to cover the whole address
>                  space.  */
> -             if (S_IS_LOCAL (sym) && !symbol_section_p (sym)
> +             if (S_IS_LOCAL (sym)
> +                 && S_IS_DEFINED (sym)
> +                 && !symbol_section_p (sym)
>                   && (sec->use_rela_p
>                       || (howto->partial_inplace
>                           && (!howto->pc_relative
>
> --
> Alan Modra
> Australia Development Lab, IBM

I am checking this testcase to master and 2.36 branch.

-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-gas-Add-a-testcase-for-PR-gas-27228.patch
Type: text/x-patch
Size: 2082 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20210124/6d77d447/attachment.bin>


More information about the Binutils mailing list