PR27100, final link failed: bad value
authorAlan Modra <amodra@gmail.com>
Thu, 24 Dec 2020 05:26:23 +0000 (15:56 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 24 Dec 2020 12:28:03 +0000 (22:58 +1030)
The failure on this PR is due to using the same bfd section for
multiple output sections.  Commit 21401fc7bf67 managed to create
duplicate linker script output section statements, but not the actual
bfd sections.

PR 27100
* ldlang.h (lang_output_section_statement_type): Add dup_output.
* ldlang.c (lang_output_section_statement_lookup): Set dup_output.
(init_os): Test dup_output rather than constraint.
* testsuite/ld-scripts/pr27100.d,
* testsuite/ld-scripts/pr27100.s,
* testsuite/ld-scripts/pr27100.t: New test.
* testsuite/ld-scripts/data.exp: Run it.  Don't exclude aout here.
* testsuite/ld-scripts/data.d: Do so here instead.
* testsuite/ld-scripts/fill.d: Likewise.
* testsuite/ld-scripts/fill16.d: Likewise.

ld/ChangeLog
ld/ldlang.c
ld/ldlang.h
ld/testsuite/ld-scripts/data.d
ld/testsuite/ld-scripts/data.exp
ld/testsuite/ld-scripts/fill.d
ld/testsuite/ld-scripts/fill16.d
ld/testsuite/ld-scripts/pr27100.d [new file with mode: 0644]
ld/testsuite/ld-scripts/pr27100.s [new file with mode: 0644]
ld/testsuite/ld-scripts/pr27100.t [new file with mode: 0644]

index c34409c575ff46428b282db9ac9740f1da06a346..7d67ef200a7e08d5c8fa51bc0236cc3a99ad78ff 100644 (file)
@@ -1,3 +1,17 @@
+2020-12-24  Alan Modra  <amodra@gmail.com>
+
+       PR 27100
+       * ldlang.h (lang_output_section_statement_type): Add dup_output.
+       * ldlang.c (lang_output_section_statement_lookup): Set dup_output.
+       (init_os): Test dup_output rather than constraint.
+       * testsuite/ld-scripts/pr27100.d,
+       * testsuite/ld-scripts/pr27100.s,
+       * testsuite/ld-scripts/pr27100.t: New test.
+       * testsuite/ld-scripts/data.exp: Run it.  Don't exclude aout here.
+       * testsuite/ld-scripts/data.d: Do so here instead.
+       * testsuite/ld-scripts/fill.d: Likewise.
+       * testsuite/ld-scripts/fill16.d: Likewise.
+
 2020-12-23  H.J. Lu  <hongjiu.lu@intel.com>
 
        * NEWS: Mention LAM_U48 and LAM_U57 support.
index 41000da1e15a6d58250b6c36132ada899598c74c..a2b6b4dc0abf33c0d3b327c29661ea7fcb991ad3 100644 (file)
@@ -1526,6 +1526,8 @@ lang_output_section_statement_lookup (const char *name,
 
   entry->s.output_section_statement.name = name;
   entry->s.output_section_statement.constraint = constraint;
+  entry->s.output_section_statement.dup_output = (create == 2
+                                                 || constraint == SPECIAL);
   return &entry->s.output_section_statement;
 }
 
@@ -2387,7 +2389,7 @@ init_os (lang_output_section_statement_type *s, flagword flags)
   if (strcmp (s->name, DISCARD_SECTION_NAME) == 0)
     einfo (_("%F%P: illegal use of `%s' section\n"), DISCARD_SECTION_NAME);
 
-  if (s->constraint != SPECIAL)
+  if (!s->dup_output)
     s->bfd_section = bfd_get_section_by_name (link_info.output_bfd, s->name);
   if (s->bfd_section == NULL)
     s->bfd_section = bfd_make_section_anyway_with_flags (link_info.output_bfd,
index 0f1b607f7358fc413f708b563cf6649358b43ad5..fe601a8547fbc3551c7d588759a2af0c08d01d21 100644 (file)
@@ -173,6 +173,9 @@ typedef struct lang_output_section_statement_struct
   unsigned int after_end : 1;
   /* If this section uses the alignment of its input sections.  */
   unsigned int align_lma_with_input : 1;
+  /* If script has duplicate output section statements of the same name
+     create duplicate output sections.  */
+  unsigned int dup_output : 1;
 } lang_output_section_statement_type;
 
 typedef struct
index b7ca0a741ce5cce91b503b1cdf2e98baefc31646..9784672db46e6de3b39c146b38f8604c836a2525 100644 (file)
@@ -1,6 +1,7 @@
 #source: data.s
 #ld: -T data.t
 #objdump: -s -j .text
+#notarget: [is_aout_format]
 #xfail: tic4x-*-* tic54x-*-*
 
 .*:     file format .*
index 4e20cf7ec154d15ba4f0acec5fa5846aad20f70b..673b2f5a4d1dc316bdc79c514081b8133d288c8b 100644 (file)
 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
 # MA 02110-1301, USA.
 
-# An a.out "objdump -s -j .text" has the file header visible inside the
-# text segment, confusing run_dump_test.
-if {[is_aout_format]} {
-       unsupported data
-       unsupported fill
-       return
-}
-
 set old_LDFLAGS $LDFLAGS
 if { [is_xcoff_format] } then {
     set LDFLAGS "$LDFLAGS -bnogc"
@@ -35,5 +27,6 @@ if { [is_xcoff_format] } then {
 run_dump_test data
 run_dump_test fill
 run_dump_test fill16
+run_dump_test pr27100
 
 set LDFLAGS $old_LDFLAGS
index 54715c58d8e43f903dc9f29c029ffda03679a080..d3b5ea939ce674511b8318496de306ef6a43e59b 100644 (file)
@@ -3,6 +3,7 @@
 #source: fill_2.s
 #ld: -T fill.t
 #objdump: -s -j .text
+#notarget: [is_aout_format]
 #skip: ia64-*-* mips*-*-freebsd* mips*-*-gnu* mips*-*-irix* mips*-*-kfreebsd*
 #skip: mips*-*-linux* mips*-*-netbsd* mips*-*-openbsd* mips*-*-sysv4*
 #skip: tilegx*-*-* tilepro-*-* x86_64-*-cygwin x86_64-*-mingw* x86_64-*-pe*
index 19be5f2c46d8d694f7ab12a356dccb2e5b5dd460..91dc0a0b40b8054030e1e0bf0ff7ee8ef03853ac 100644 (file)
@@ -3,6 +3,7 @@
 #source: fill16_2.s
 #ld: -T fill.t
 #objdump: -s -j .text
+#notarget: [is_aout_format]
 #skip: arm-*-coff i[3-7]86-*-coff [is_xcoff_format]
 #xfail: alpha*-*-*ecoff sh-*-pe sparc*-*-coff
 #xfail: tic30-*-coff tic4x-*-* tic54x-*-* z8k-*-*
diff --git a/ld/testsuite/ld-scripts/pr27100.d b/ld/testsuite/ld-scripts/pr27100.d
new file mode 100644 (file)
index 0000000..28b5875
--- /dev/null
@@ -0,0 +1,10 @@
+#ld: -r -T pr27100.t
+#objdump: -h
+#notarget: [is_aout_format]
+#xfail: alpha*-*-*vms* mmix-*-* *c54x-*-* [is_xcoff_format]
+
+#...
+.* \.data +0+60 .*
+#...
+.* \.data +0+10 .*
+#pass
diff --git a/ld/testsuite/ld-scripts/pr27100.s b/ld/testsuite/ld-scripts/pr27100.s
new file mode 100644 (file)
index 0000000..3eb147d
--- /dev/null
@@ -0,0 +1,2 @@
+ .data
+ .space 80
diff --git a/ld/testsuite/ld-scripts/pr27100.t b/ld/testsuite/ld-scripts/pr27100.t
new file mode 100644 (file)
index 0000000..b94b8e9
--- /dev/null
@@ -0,0 +1,2 @@
+SECTIONS { .data ALIGN (16) : { aa = .; LONG(0xdeadbeef); . = ALIGN (16); } }
+SECTIONS { .data ALIGN (16) : { bb = .; LONG(0x00c0ffee); . = ALIGN (16); } }