public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Lulu Cai <cailulu@loongson.cn>
To: Xi Ruoyao <xry111@xry111.site>, binutils@sourceware.org
Cc: mengqinggang@loongson.cn, Chenghua Xu <xuchenghua@loongson.cn>,
	Huacai Chen <chenhuacai@kernel.org>,
	WANG Xuerui <kernel@xen0n.name>
Subject: Re: [PATCH 3/3] LoongArch: Reword message for unresolvable PC-relative relocs
Date: Wed, 18 Dec 2024 16:12:59 +0800	[thread overview]
Message-ID: <683a72ff-956d-3bb0-0d5b-325cce663f30@loongson.cn> (raw)
In-Reply-To: <20241213055427.579306-4-xry111@xry111.site>

[-- Attachment #1: Type: text/plain, Size: 2838 bytes --]

On 12/13/24 1:53 PM, Xi Ruoyao wrote:
> If we hit such a bad reloc, it means the programmer has somehow wrongly
> instructed the compiler to generate PC-relative relocs against external
> symbols.  "Recompiling with -fPIC" (or -fPIE) is just misleading.
>
> Signed-off-by: Xi Ruoyao <xry111@xry111.site>
> ---
>   bfd/elfnn-loongarch.c                                     | 4 ++++
>   ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d     | 2 +-
>   ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global_pie.d | 2 +-
>   ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d       | 2 +-
>   ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak_pie.d   | 2 +-
>   ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d     | 2 +-
>   ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d       | 2 +-
>   7 files changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> index 5d252bcccb9..93368275b46 100644
> --- a/bfd/elfnn-loongarch.c
> +++ b/bfd/elfnn-loongarch.c
> @@ -894,6 +894,10 @@ bad_static_reloc (struct bfd_link_info *info,
>         pic = _("; recompile with -fPIE");
>       }
>   
> +  if (r_type == R_LARCH_PCREL20_S2 || r_type == R_LARCH_PCALA_HI20)
> +    pic = _("; recompile with -mno-direct-extern-access and check the "
> +	    "symbol visibility");
> +
>     (*_bfd_error_handler)
>      (_("%pB:(%pA+%#lx): relocation %s against `%s` can not be used when making "
>         "%s%s"),

Perhaps the prompt here is not always appropriate. such as:
$ cat test.c

int a =1;
int main (void)
{
printf("%d\n",a);
}

$ gcc -fno-pic -c test.o
$ gcc -shared -o test test.o

Will get error message:
ld: test.o:(.text+0x10): relocation R_LARCH_PCALA_HI20 against `a` can 
not be used when making a shared object; recompile
with -mno-direct-extern-access and check the symbol visibility

If the user follows the prompts and uses "gcc -mno-direct-extern-access 
-c test.o" to compile and then link, an error will still be reported.
However, the problem is solved after recompiling and linking using "gcc 
-fpic -c test.o".

> diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d
> index 6ecefd1d48a..fac02d036ba 100644
> --- a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d
> +++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d
> @@ -2,4 +2,4 @@
>   #source: bad_pcala_hi20_global.s
>   #target: [check_shared_lib_support]
>   #ld: -shared --defsym global_a=0x10 --defsym global_b=0x20
> -#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -fPIC
> +#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -mno-direct-extern-access and check the symbol visibility



  reply	other threads:[~2024-12-18  8:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-13  5:53 [PATCH 0/3] LoongArch: Allow and correctly resolve PC-relative relocs against local undefined weak symbols Xi Ruoyao
2024-12-13  5:53 ` [PATCH 1/3] LoongArch: Fix resolution of undefined weak hidden/protected symbols Xi Ruoyao
2024-12-13  5:53 ` [PATCH 2/3] LoongArch: Allow R_LARCH_PCALA_HI20 or R_LARCH_PCREL20_S2 against undefined weak symbols for static PIE Xi Ruoyao
2024-12-18  8:02   ` Lulu Cai
2024-12-13  5:53 ` [PATCH 3/3] LoongArch: Reword message for unresolvable PC-relative relocs Xi Ruoyao
2024-12-18  8:12   ` Lulu Cai [this message]
2024-12-18  9:00     ` Xi Ruoyao
2024-12-18  9:22       ` Lulu Cai
2024-12-25  2:04       ` Lulu Cai
2024-12-25  3:29         ` Xi Ruoyao

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=683a72ff-956d-3bb0-0d5b-325cce663f30@loongson.cn \
    --to=cailulu@loongson.cn \
    --cc=binutils@sourceware.org \
    --cc=chenhuacai@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=mengqinggang@loongson.cn \
    --cc=xry111@xry111.site \
    --cc=xuchenghua@loongson.cn \
    /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).