public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] LoongArch: Do not relax against __[start|stop]_SECNAME symbol
@ 2025-01-30 15:43 Lulu Cai
  0 siblings, 0 replies; only message in thread
From: Lulu Cai @ 2025-01-30 15:43 UTC (permalink / raw)
  To: binutils; +Cc: 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.

---
Changes from v1:
  - Modify the test case to loongarch64 and check pie support.
---
 bfd/elfnn-loongarch.c                      |  5 ++++-
 ld/testsuite/ld-loongarch-elf/relax.exp    |  3 +++
 ld/testsuite/ld-loongarch-elf/start_stop.d | 13 +++++++++++++
 ld/testsuite/ld-loongarch-elf/start_stop.s | 10 ++++++++++
 4 files changed, 30 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 c24b2600a9a..0e3bfac67f6 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -5637,10 +5637,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..9d952d9727f 100644
--- a/ld/testsuite/ld-loongarch-elf/relax.exp
+++ b/ld/testsuite/ld-loongarch-elf/relax.exp
@@ -412,6 +412,8 @@ if [istarget loongarch64-*-*] {
 		  "relax-segment-max" \
 	      ] \
 	  ]
+
+     run_dump_test "start_stop"
     }
 
     run_ld_link_tests \
@@ -484,4 +486,5 @@ if [istarget loongarch64-*-*] {
 	      "uleb128" \
 	  ] \
       ]
+
 }
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.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-01-30 15:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-30 15:43 [PATCH v2] LoongArch: Do not relax against __[start|stop]_SECNAME symbol Lulu Cai

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).