* [PATCH v1] LoongArch: Do not relax against __[start|stop]_SECNAME symbol
@ 2025-01-22 9:00 Lulu Cai
2025-01-28 9:05 ` Lulu Cai
0 siblings, 1 reply; 5+ messages in thread
From: Lulu Cai @ 2025-01-22 9:00 UTC (permalink / raw)
To: nickc, binutils
Cc: xuchenghua, chenglulu, mengqinggang, xry111, i.swmail, luweining,
hejinyang, Lulu Cai
The value of the __[start|stop]_SECNAME symbol will be set after
loongarch_elf_relax_section. If relaxation is done against the
__[start|stop]_SECNAME symbol, the correct symbol value cannot
be obtained.
---
bfd/elfnn-loongarch.c | 5 ++++-
ld/testsuite/ld-loongarch-elf/relax.exp | 2 ++
ld/testsuite/ld-loongarch-elf/start_stop.d | 13 +++++++++++++
ld/testsuite/ld-loongarch-elf/start_stop.s | 10 ++++++++++
4 files changed, 29 insertions(+), 1 deletion(-)
create mode 100644 ld/testsuite/ld-loongarch-elf/start_stop.d
create mode 100644 ld/testsuite/ld-loongarch-elf/start_stop.s
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index efa57184e44..dfb760dbf22 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -5636,10 +5636,13 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
}
else
{
+ /* Do not relax __[start|stop]_SECNAME, since the symbol value
+ is not set yet. */
if (h != NULL
&& ((h->type == STT_GNU_IFUNC
&& r_type != R_LARCH_CALL36)
- || bfd_is_abs_section (h->root.u.def.section)))
+ || bfd_is_abs_section (h->root.u.def.section)
+ || h->start_stop))
continue;
/* The GOT entry of tls symbols must in current execute file or
diff --git a/ld/testsuite/ld-loongarch-elf/relax.exp b/ld/testsuite/ld-loongarch-elf/relax.exp
index 81924cd35cb..5c17a2ef403 100644
--- a/ld/testsuite/ld-loongarch-elf/relax.exp
+++ b/ld/testsuite/ld-loongarch-elf/relax.exp
@@ -484,4 +484,6 @@ if [istarget loongarch64-*-*] {
"uleb128" \
] \
]
+
+ run_dump_test "start_stop"
}
diff --git a/ld/testsuite/ld-loongarch-elf/start_stop.d b/ld/testsuite/ld-loongarch-elf/start_stop.d
new file mode 100644
index 00000000000..b887dcc2eb7
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/start_stop.d
@@ -0,0 +1,13 @@
+#ld: -z norelro -pie -e0
+#objdump: -d
+
+.*: file format .*
+
+
+Disassembly of section sec1:
+
+[0-9a-f]+ <_start>:
+ [0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .*
+ [0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .*
+ [0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .*
+ [0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .*
diff --git a/ld/testsuite/ld-loongarch-elf/start_stop.s b/ld/testsuite/ld-loongarch-elf/start_stop.s
new file mode 100644
index 00000000000..f50bc603abb
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/start_stop.s
@@ -0,0 +1,10 @@
+ .section sec1,"ax",@progbits
+ .globl _start
+ .type _start, @function
+_start:
+ la.got $a0,__start_sec1
+ la.got $a0,__stop_sec1
+ .size _start, .-_start
+
+ .hidden __start_sec1
+ .hidden __stop_sec1
--
2.45.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] LoongArch: Do not relax against __[start|stop]_SECNAME symbol
2025-01-22 9:00 [PATCH v1] LoongArch: Do not relax against __[start|stop]_SECNAME symbol Lulu Cai
@ 2025-01-28 9:05 ` Lulu Cai
2025-01-28 13:45 ` Nick Clifton
0 siblings, 1 reply; 5+ messages in thread
From: Lulu Cai @ 2025-01-28 9:05 UTC (permalink / raw)
To: nickc, binutils; +Cc: mengqinggang
Hi Nick,
This patch fixes a relaxation bug for LoongArch and needs to be
applied to 2.44 branch and the mainline source.
link: https://sourceware.org/pipermail/binutils/2025-January/138943.html
Thanks.
On 1/22/2025 5:00 PM, Lulu Cai wrote:
> The value of the __[start|stop]_SECNAME symbol will be set after
> loongarch_elf_relax_section. If relaxation is done against the
> __[start|stop]_SECNAME symbol, the correct symbol value cannot
> be obtained.
> ---
> bfd/elfnn-loongarch.c | 5 ++++-
> ld/testsuite/ld-loongarch-elf/relax.exp | 2 ++
> ld/testsuite/ld-loongarch-elf/start_stop.d | 13 +++++++++++++
> ld/testsuite/ld-loongarch-elf/start_stop.s | 10 ++++++++++
> 4 files changed, 29 insertions(+), 1 deletion(-)
> create mode 100644 ld/testsuite/ld-loongarch-elf/start_stop.d
> create mode 100644 ld/testsuite/ld-loongarch-elf/start_stop.s
>
> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> index efa57184e44..dfb760dbf22 100644
> --- a/bfd/elfnn-loongarch.c
> +++ b/bfd/elfnn-loongarch.c
> @@ -5636,10 +5636,13 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
> }
> else
> {
> + /* Do not relax __[start|stop]_SECNAME, since the symbol value
> + is not set yet. */
> if (h != NULL
> && ((h->type == STT_GNU_IFUNC
> && r_type != R_LARCH_CALL36)
> - || bfd_is_abs_section (h->root.u.def.section)))
> + || bfd_is_abs_section (h->root.u.def.section)
> + || h->start_stop))
> continue;
>
> /* The GOT entry of tls symbols must in current execute file or
> diff --git a/ld/testsuite/ld-loongarch-elf/relax.exp b/ld/testsuite/ld-loongarch-elf/relax.exp
> index 81924cd35cb..5c17a2ef403 100644
> --- a/ld/testsuite/ld-loongarch-elf/relax.exp
> +++ b/ld/testsuite/ld-loongarch-elf/relax.exp
> @@ -484,4 +484,6 @@ if [istarget loongarch64-*-*] {
> "uleb128" \
> ] \
> ]
> +
> + run_dump_test "start_stop"
> }
> diff --git a/ld/testsuite/ld-loongarch-elf/start_stop.d b/ld/testsuite/ld-loongarch-elf/start_stop.d
> new file mode 100644
> index 00000000000..b887dcc2eb7
> --- /dev/null
> +++ b/ld/testsuite/ld-loongarch-elf/start_stop.d
> @@ -0,0 +1,13 @@
> +#ld: -z norelro -pie -e0
> +#objdump: -d
> +
> +.*: file format .*
> +
> +
> +Disassembly of section sec1:
> +
> +[0-9a-f]+ <_start>:
> + [0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .*
> + [0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .*
> + [0-9a-f]+: [0-9a-f]+ pcalau12i \$a0, .*
> + [0-9a-f]+: [0-9a-f]+ ld.d \$a0, \$a0, .*
> diff --git a/ld/testsuite/ld-loongarch-elf/start_stop.s b/ld/testsuite/ld-loongarch-elf/start_stop.s
> new file mode 100644
> index 00000000000..f50bc603abb
> --- /dev/null
> +++ b/ld/testsuite/ld-loongarch-elf/start_stop.s
> @@ -0,0 +1,10 @@
> + .section sec1,"ax",@progbits
> + .globl _start
> + .type _start, @function
> +_start:
> + la.got $a0,__start_sec1
> + la.got $a0,__stop_sec1
> + .size _start, .-_start
> +
> + .hidden __start_sec1
> + .hidden __stop_sec1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] LoongArch: Do not relax against __[start|stop]_SECNAME symbol
2025-01-28 9:05 ` Lulu Cai
@ 2025-01-28 13:45 ` Nick Clifton
2025-01-30 16:04 ` Lulu Cai
0 siblings, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2025-01-28 13:45 UTC (permalink / raw)
To: Lulu Cai, binutils; +Cc: mengqinggang
Hi Lulu,
> This patch fixes a relaxation bug for LoongArch and needs to be applied to 2.44 branch and the mainline source.
>
> link: https://sourceware.org/pipermail/binutils/2025-January/138943.html
When I test this patch on my local machine (an x86_64 box) I get a
new linker testsuite failure:
FAIL: ld-loongarch-elf/start_stop
The reason, according to ld.log is:
Executing on host: sh -c {./ld-new -L/work/sources/binutils/upstream/2.44/ld/testsuite/ld-loongarch-elf -z norelro -pie -e0 -o tmpdir/dump tmpdir/start_stop.o 2>&1}
/dev/null dump.tmp (timeout = 300)
spawn [open ...]
./ld-new: -pie not supported
failed with: <./ld-new: -pie not supported>, no expected output
I think that this must be a problem with my local setup, so please
go ahead and apply the fix to both the mainline and the 2.44 branch.
But if you can, please do run a quick check to make sure that the
linker test does actually pass for you...
Cheers
Nick
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] LoongArch: Do not relax against __[start|stop]_SECNAME symbol
2025-01-28 13:45 ` Nick Clifton
@ 2025-01-30 16:04 ` Lulu Cai
2025-01-31 10:39 ` Nick Clifton
0 siblings, 1 reply; 5+ messages in thread
From: Lulu Cai @ 2025-01-30 16:04 UTC (permalink / raw)
To: Nick Clifton, binutils; +Cc: mengqinggang
On 1/28/2025 9:45 PM, Nick Clifton wrote:
> Hi Lulu,
>
>> This patch fixes a relaxation bug for LoongArch and needs to be
>> applied to 2.44 branch and the mainline source.
>>
>> link:
>> https://sourceware.org/pipermail/binutils/2025-January/138943.html
>
> When I test this patch on my local machine (an x86_64 box) I get a
> new linker testsuite failure:
>
> FAIL: ld-loongarch-elf/start_stop
>
> The reason, according to ld.log is:
>
> Executing on host: sh -c {./ld-new
> -L/work/sources/binutils/upstream/2.44/ld/testsuite/ld-loongarch-elf
> -z norelro -pie -e0 -o tmpdir/dump tmpdir/start_stop.o 2>&1} /dev/null
> dump.tmp (timeout = 300)
> spawn [open ...]
> ./ld-new: -pie not supported
> failed with: <./ld-new: -pie not supported>, no expected output
>
> I think that this must be a problem with my local setup, so please
> go ahead and apply the fix to both the mainline and the 2.44 branch.
Hi Nick,
Thanks for the problem report otherwise I would have missed it.
I have sent patch V2 to fix it by checking for loongarch64 target and
pie support. Please apply this patch to mainline and 2.44 branch.
Link: https://sourceware.org/pipermail/binutils/2025-January/139161.html
Thanks
Lulu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] LoongArch: Do not relax against __[start|stop]_SECNAME symbol
2025-01-30 16:04 ` Lulu Cai
@ 2025-01-31 10:39 ` Nick Clifton
0 siblings, 0 replies; 5+ messages in thread
From: Nick Clifton @ 2025-01-31 10:39 UTC (permalink / raw)
To: Lulu Cai, binutils; +Cc: mengqinggang
Hi Lulu,
> Thanks for the problem report otherwise I would have missed it.
>
> I have sent patch V2 to fix it by checking for loongarch64 target and pie support. Please apply this patch to mainline and 2.44 branch.
>
> Link: https://sourceware.org/pipermail/binutils/2025-January/139161.html
Thanks - I have applied this patch to the mainline and the 2.44 branch.
Cheers
Nick
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-01-31 10:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-22 9:00 [PATCH v1] LoongArch: Do not relax against __[start|stop]_SECNAME symbol Lulu Cai
2025-01-28 9:05 ` Lulu Cai
2025-01-28 13:45 ` Nick Clifton
2025-01-30 16:04 ` Lulu Cai
2025-01-31 10:39 ` Nick Clifton
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).