public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alex Coplan <alex.coplan@arm.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: Binutils <binutils@sourceware.org>
Subject: Re: [PATCH] gas: Fix internal error in S_SET_SEGMENT
Date: Mon, 3 Aug 2020 15:22:41 +0100	[thread overview]
Message-ID: <20200803142241.jxtqma5ijk3243vg@arm.com> (raw)
In-Reply-To: <CAMe9rOpfWfpENKmmzZ-51z7dc21O57miQT89e+SHcfHhd7d5Ow@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1638 bytes --]

Hi H.J,

Sorry for the delay; just got back from some time off.

> -----Original Message-----
> From: H.J. Lu <hjl.tools@gmail.com>
> Sent: 22 July 2020 15:40
> To: Alex Coplan <Alex.Coplan@arm.com>
> Cc: Binutils <binutils@sourceware.org>
> Subject: Re: [PATCH] gas: Fix internal error in S_SET_SEGMENT
> 
> > gas/ChangeLog:
> >
> > 2020-07-22  Alex Coplan  <alex.coplan@arm.com>
> >
> >         * config/obj-elf.c (obj_elf_change_section): When
> >         repurposing an existing symbol, ensure that we set sy_value as
> >         per other (fresh) section symbols.
> >         * testsuite/gas/aarch64/section-symbol-redef.d: New test.
> >         * testsuite/gas/aarch64/section-symbol-redef.s: Input for test.
> >
> 
> Why are tests arm specific?  Can you put them to ELF tests?

Thanks for pointing this out. I wasn't sure if there was a
suitably-generic place for these to go, but it seems that the ELF test
directory is the right place.

See the updated patch attached. The test has been tweaked to fix the
indentation for targets that assume anything in the first column is a
label, and to skip on targets that either don't support assignment
(bfin) or require attributes for sections (h8300).

Is the updated version OK for master?

Thanks,
Alex

---

gas/ChangeLog:

2020-08-03  Alex Coplan  <alex.coplan@arm.com>

	* config/obj-elf.c (obj_elf_change_section): When repurposing an
	existing symbol, ensure that we set sy_value as per other (fresh)
	section symbols.
	* testsuite/gas/elf/elf.exp: Add new test.
	* testsuite/gas/elf/section-symbol-redef.d: New test.
	* testsuite/gas/elf/section-symbol-redef.s: Input for test.


[-- Attachment #2: patch_v2.txt --]
[-- Type: text/plain, Size: 1834 bytes --]

diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index de22b5a1da8..c11a1da2295 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -759,7 +759,14 @@ obj_elf_change_section (const char *name,
       /* Add a symbol for this section to the symbol table.  */
       secsym = symbol_find (name);
       if (secsym != NULL)
-	symbol_set_bfdsym (secsym, sec->symbol);
+	{
+	  /* We could be repurposing an undefined symbol here: make sure we
+	     reset sy_value to look like other section symbols in order to avoid
+	     trying to incorrectly resolve this section symbol later on.  */
+	  static const expressionS expr = { .X_op = O_constant };
+	  symbol_set_value_expression (secsym, &expr);
+	  symbol_set_bfdsym (secsym, sec->symbol);
+	}
       else
 	symbol_table_insert (section_symbol (sec));
     }
diff --git a/gas/testsuite/gas/elf/elf.exp b/gas/testsuite/gas/elf/elf.exp
index 86b304ae34f..8cd61b36754 100644
--- a/gas/testsuite/gas/elf/elf.exp
+++ b/gas/testsuite/gas/elf/elf.exp
@@ -303,6 +303,7 @@ if { [is_elf_format] } then {
     run_dump_test "strtab"
 
     run_dump_test "bignums"
+    run_dump_test "section-symbol-redef"
     
     load_lib gas-dg.exp
     dg-init
diff --git a/gas/testsuite/gas/elf/section-symbol-redef.d b/gas/testsuite/gas/elf/section-symbol-redef.d
new file mode 100644
index 00000000000..88807a196a7
--- /dev/null
+++ b/gas/testsuite/gas/elf/section-symbol-redef.d
@@ -0,0 +1,6 @@
+#readelf: -x myseg
+#skip: bfin-*-*
+#skip: h8300-*
+
+Hex dump of section .*:
+  0x0+ 2a\s+\*
diff --git a/gas/testsuite/gas/elf/section-symbol-redef.s b/gas/testsuite/gas/elf/section-symbol-redef.s
new file mode 100644
index 00000000000..87e65699b48
--- /dev/null
+++ b/gas/testsuite/gas/elf/section-symbol-redef.s
@@ -0,0 +1,3 @@
+  myseg=not_defined_here
+  .section myseg
+  .byte 42

  reply	other threads:[~2020-08-03 14:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-22 14:23 Alex Coplan
2020-07-22 14:40 ` H.J. Lu
2020-08-03 14:22   ` Alex Coplan [this message]
2020-08-17  9:07     ` Alex Coplan
2020-08-17 11:26       ` Nick Clifton
2020-08-17 13:28         ` Alex Coplan
2020-09-01 15:47           ` Alex Coplan
2020-09-01 23:44             ` Alan Modra

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=20200803142241.jxtqma5ijk3243vg@arm.com \
    --to=alex.coplan@arm.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /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).