]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
LoongArch: Do not relax against __[start|stop]_SECNAME symbol
authorLulu Cai <cailulu@loongson.cn>
Fri, 31 Jan 2025 10:37:00 +0000 (10:37 +0000)
committerNick Clifton <nickc@redhat.com>
Fri, 31 Jan 2025 10:37:00 +0000 (10:37 +0000)
bfd/elfnn-loongarch.c
ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
ld/testsuite/ld-loongarch-elf/relax.exp
ld/testsuite/ld-loongarch-elf/start_stop.d [new file with mode: 0644]
ld/testsuite/ld-loongarch-elf/start_stop.s [new file with mode: 0644]

index fc1cbbea71a365e3bbc8f6bc6f6f72fb1c9e35cf..a04f00d1b841d5fb3818b442b473e646567ac22e 100644 (file)
@@ -5634,10 +5634,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
index 0295be815623cf0af167f5acf8f56449fca35531..7e5fdfa66a090f08cbde436c9d5bab65e699bb92 100644 (file)
@@ -154,6 +154,7 @@ if [istarget "loongarch64-*-*"] {
       ] \
   ]
 
+  if [check_pie_support] {
   # Using DESC and IE to access the same tls symbol but with
   # -mno-relax requires allocating GOT entries for both DESC and IE,
   # not just IE
@@ -169,6 +170,7 @@ if [istarget "loongarch64-*-*"] {
          "desc-ie-norelax" \
       ] \
   ] \
+  }
 }
 
 if [istarget "loongarch64-*-*"] {
index 81924cd35cb1604f9baa4cd26044b74f128ccd63..98504cf9dfb9abf15ce095b8ef8d840f9a8a3347 100644 (file)
@@ -412,6 +412,8 @@ if [istarget loongarch64-*-*] {
                  "relax-segment-max" \
              ] \
          ]
+
+      run_dump_test "start_stop"
     }
 
     run_ld_link_tests \
diff --git a/ld/testsuite/ld-loongarch-elf/start_stop.d b/ld/testsuite/ld-loongarch-elf/start_stop.d
new file mode 100644 (file)
index 0000000..b887dcc
--- /dev/null
@@ -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 (file)
index 0000000..f50bc60
--- /dev/null
@@ -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