[PATCH] Skip convert lui to GPREL_L for .LANCHOR

Nelson Chu nelson.chu@sifive.com
Fri Mar 12 02:38:59 GMT 2021


Hi Lifang,

Could you add the ld testcase for this?  It's better to report the
details somewhere, like sourceware bugzilla or riscv github.  I find a
similar fix in PR25258,
https://sourceware.org/bugzilla/show_bug.cgi?id=25258.  The patch
works only for c.lui relaxation, so I think we might need a similar
fix for the regular lui to gp relaxation, rather than just disable the
relaxation.  Anyway, we need a testcase or at least a reduced case can
be reproduced.

Thanks
Nelson

On Thu, Mar 11, 2021 at 9:05 PM Lifang Xia via Binutils
<binutils@sourceware.org> wrote:
>
> If the .LANCHOR defined in .rodata, the gp may not reach the symbol
> after lang_size_relro_segment while linking with "-z relro".
>
> bfd/
>         * elfnn-riscv.c (_bfd_riscv_relax_lui): Skip that the symbol
>           is defined in rodata and linking with "-z relro".
> ---
>  bfd/elfnn-riscv.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
> index 364d67b..74dce3c 100644
> --- a/bfd/elfnn-riscv.c
> +++ b/bfd/elfnn-riscv.c
> @@ -4251,10 +4251,14 @@ _bfd_riscv_relax_lui (bfd *abfd,
>       Valid gp range conservatively because of alignment issue.  */
>    if (undefined_weak
>        || (VALID_ITYPE_IMM (symval)
> -         || (symval >= gp
> -             && VALID_ITYPE_IMM (symval - gp + max_alignment + reserve_size))
> -         || (symval < gp
> -             && VALID_ITYPE_IMM (symval - gp - max_alignment - reserve_size))))
> +         /* Skip that the symbol defined in rodata by .set, such as .LANCHOR,
> +            and link with -z relro. The symbol may not be accessed with gp.  */
> +         || (!(sym_sec->flags & SEC_READONLY
> +               && link_info->relro)
> +             && ((symval >= gp
> +                  && VALID_ITYPE_IMM (symval - gp + max_alignment + reserve_size))
> +                 || (symval < gp
> +                     && VALID_ITYPE_IMM (symval - gp - max_alignment - reserve_size))))))
>      {
>        unsigned sym = ELFNN_R_SYM (rel->r_info);
>        switch (ELFNN_R_TYPE (rel->r_info))
> --
> 2.6.0-rc0
>


More information about the Binutils mailing list