bfd: xtensa: fix __stop_SECTION literal drop
authorAlexey Lapshin <alexey.lapshin@espressif.com>
Thu, 23 Feb 2023 10:48:16 +0000 (10:48 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 23 Feb 2023 10:48:16 +0000 (10:48 +0000)
bfd/elf32-xtensa.c
ld/testsuite/ld- [new file with mode: 0644]
ld/testsuite/ld-xtensa/startstop.d [new file with mode: 0644]
ld/testsuite/ld-xtensa/startstop.s [new file with mode: 0644]
ld/testsuite/ld-xtensa/xtensa.exp

index 84ff90044330aa4e32b646a5fcdaeac923c77c9d..7772e2a5f9088e02cdce0e30411a6751c3087b5b 100644 (file)
@@ -5230,6 +5230,13 @@ literal_value_equal (const literal_value *src1,
      (if undefined or weak).  */
   h1 = r_reloc_get_hash_entry (&src1->r_rel);
   h2 = r_reloc_get_hash_entry (&src2->r_rel);
+
+  /* Keep start_stop literals always unique to avoid dropping it due to them
+     having late initialization.
+     Now they are equal because initialized with zeroed values.  */
+  if (h2 && h2->start_stop)
+      return false;
+
   if (r_reloc_is_defined (&src1->r_rel)
       && (final_static_link
          || ((!h1 || h1->root.type != bfd_link_hash_defweak)
diff --git a/ld/testsuite/ld- b/ld/testsuite/ld-
new file mode 100644 (file)
index 0000000..6cea49a
--- /dev/null
@@ -0,0 +1,6 @@
+#as:
+#ld:
+#objdump: -h
+#...
+.*TEST_SECTION\.literal[ ]*00000008.*
+#...
diff --git a/ld/testsuite/ld-xtensa/startstop.d b/ld/testsuite/ld-xtensa/startstop.d
new file mode 100644 (file)
index 0000000..6cea49a
--- /dev/null
@@ -0,0 +1,6 @@
+#as:
+#ld:
+#objdump: -h
+#...
+.*TEST_SECTION\.literal[ ]*00000008.*
+#...
diff --git a/ld/testsuite/ld-xtensa/startstop.s b/ld/testsuite/ld-xtensa/startstop.s
new file mode 100644 (file)
index 0000000..b94b0ec
--- /dev/null
@@ -0,0 +1,16 @@
+       .file   "startstop.s"
+       .text
+       .section        .rodata
+       .align  4
+.LC0:
+       .section        TEST_SECTION,"aw"
+       .align  4
+       .literal_position
+       .literal .LC1, __start_TEST_SECTION
+       .literal .LC2, __stop_TEST_SECTION
+       .align  4
+       .global _start
+       .type   _start, @function
+_start:
+       l32r    a2, .LC1
+       l32r    a3, .LC2
index e671cabae4ad0289bc3967dd46c067b0bb773ddc..9af59f9fc5a806c114daf4024eefa9d91e177396 100644 (file)
@@ -41,3 +41,5 @@ run_dump_test "relax-undef-weak-pie-export-dynamic"
 run_dump_test "relax-undef-weak-local-pie"
 run_dump_test "relax-undef-weak-shared"
 run_dump_test "relax-undef-weak-local-shared"
+
+run_dump_test "startstop"