public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: PR27100, final link failed: bad value
Date: Thu, 24 Dec 2020 23:02:22 +1030	[thread overview]
Message-ID: <20201224123222.GA8873@bubble.grove.modra.org> (raw)

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.

diff --git a/ld/ldlang.c b/ld/ldlang.c
index 41000da1e1..a2b6b4dc0a 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -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,
diff --git a/ld/ldlang.h b/ld/ldlang.h
index 0f1b607f73..fe601a8547 100644
--- a/ld/ldlang.h
+++ b/ld/ldlang.h
@@ -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
diff --git a/ld/testsuite/ld-scripts/data.d b/ld/testsuite/ld-scripts/data.d
index b7ca0a741c..9784672db4 100644
--- a/ld/testsuite/ld-scripts/data.d
+++ b/ld/testsuite/ld-scripts/data.d
@@ -1,6 +1,7 @@
 #source: data.s
 #ld: -T data.t
 #objdump: -s -j .text
+#notarget: [is_aout_format]
 #xfail: tic4x-*-* tic54x-*-*
 
 .*:     file format .*
diff --git a/ld/testsuite/ld-scripts/data.exp b/ld/testsuite/ld-scripts/data.exp
index 4e20cf7ec1..673b2f5a4d 100644
--- a/ld/testsuite/ld-scripts/data.exp
+++ b/ld/testsuite/ld-scripts/data.exp
@@ -19,14 +19,6 @@
 # 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
diff --git a/ld/testsuite/ld-scripts/fill.d b/ld/testsuite/ld-scripts/fill.d
index 54715c58d8..d3b5ea939c 100644
--- a/ld/testsuite/ld-scripts/fill.d
+++ b/ld/testsuite/ld-scripts/fill.d
@@ -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*
diff --git a/ld/testsuite/ld-scripts/fill16.d b/ld/testsuite/ld-scripts/fill16.d
index 19be5f2c46..91dc0a0b40 100644
--- a/ld/testsuite/ld-scripts/fill16.d
+++ b/ld/testsuite/ld-scripts/fill16.d
@@ -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
index 0000000000..28b5875dbc
--- /dev/null
+++ b/ld/testsuite/ld-scripts/pr27100.d
@@ -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
index 0000000000..3eb147dd3a
--- /dev/null
+++ b/ld/testsuite/ld-scripts/pr27100.s
@@ -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
index 0000000000..b94b8e90a2
--- /dev/null
+++ b/ld/testsuite/ld-scripts/pr27100.t
@@ -0,0 +1,2 @@
+SECTIONS { .data ALIGN (16) : { aa = .; LONG(0xdeadbeef); . = ALIGN (16); } }
+SECTIONS { .data ALIGN (16) : { bb = .; LONG(0x00c0ffee); . = ALIGN (16); } }

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2020-12-24 12:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201224123222.GA8873@bubble.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).