public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: <binutils@sourceware.org>
Subject: [PATCH] gas: fix bogus error on .org involving expression
Date: Wed, 02 Mar 2016 11:29:00 -0000	[thread overview]
Message-ID: <56D6DCAB02000078000D845A@prv-mh.provo.novell.com> (raw)

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

For years I have been carrying this change, and it was long forgotten
what it was originally meant to deal with, hence I've never submitted
it. Until I came across an issue with Linux kernel like alternative
instruction patching, where the space needed to hold the replacement
instruction was allocated using .org. Things built fine for me (since
I had the patch in place), and things also built fine on 2.20. But
assemblers from at least 2.22 onwards produce an undefined symbol
warning for the "orig" label in the new test case, followed by an
error complaining that .org would be moving backwards (which is a
logical consequence of the undefined symbol getting replaced by plain
zero).

gas/
2016-03-02  Jan Beulich  <jbeulich@suse.com>

	* expr.c (expr): Set retval to expr_section for expressions
	involving symbols, which cannot be resolved right away.

gas/testsuite/
2016-03-02  Jan Beulich  <jbeulich@suse.com>

	* expr-org.s, expr.org.d: New.
	* gas.exp: Run new test.

--- 2016-03-02/gas/expr.c
+++ 2016-03-02/gas/expr.c
@@ -1998,7 +1998,11 @@ expr (int rankarg,		/* Larger # is highe
 		  retval = absolute_section;
 		  rightseg = absolute_section;
 		}
+	      else
+		retval = expr_section;
 	    }
+	  else
+	    retval = expr_section;
 	}
       else
 	{
@@ -2010,17 +2014,18 @@ expr (int rankarg,		/* Larger # is highe
 	  resultP->X_add_number = 0;
 	  resultP->X_unsigned = 1;
 	  resultP->X_extrabit = 0;
+	  retval = expr_section;
 	}
 
       if (retval != rightseg)
 	{
-	  if (retval == undefined_section)
+	  if (retval == expr_section)
 	    ;
-	  else if (rightseg == undefined_section)
+	  else if (rightseg == expr_section)
 	    retval = rightseg;
-	  else if (retval == expr_section)
+	  else if (retval == undefined_section)
 	    ;
-	  else if (rightseg == expr_section)
+	  else if (rightseg == undefined_section)
 	    retval = rightseg;
 	  else if (retval == reg_section)
 	    ;
--- 2016-03-02/gas/testsuite/gas/all/expr-org.d
+++ 2016-03-02/gas/testsuite/gas/all/expr-org.d
@@ -0,0 +1,11 @@
+#objdump: -s -j .data -j .alt
+#name: .org with expression (with forward reference)
+
+.*: .*
+
+Contents of section \.data:
+ 0000 [0f][0f]ffff[0f][0f] 01 [ .]*
+
+Contents of section \.alt:
+ 0000 00000000 [ .]*
+#pass
--- 2016-03-02/gas/testsuite/gas/all/expr-org.s
+++ 2016-03-02/gas/testsuite/gas/all/expr-org.s
@@ -0,0 +1,10 @@
+	.data
+orig:
+	.byte	0
+	.org	orig + (alt_end - alt_begin), 0xff
+	.pushsection .alt, "a", @progbits
+alt_begin:
+	.long	0
+alt_end:
+	.popsection
+	.byte	1
--- 2016-03-02/gas/testsuite/gas/all/gas.exp
+++ 2016-03-02/gas/testsuite/gas/all/gas.exp
@@ -371,6 +371,7 @@ if {  ([istarget "i*86-*-*pe*"] && ![ist
 if { ![istarget "bfin-*-*"] && ![istarget "nds32*-*-*"] } then {
     run_dump_test assign
 }
+run_dump_test expr-org
 run_dump_test sleb128
 run_dump_test sleb128-2
 run_dump_test sleb128-3




[-- Attachment #2: binutils-master-master-org-expression.patch --]
[-- Type: text/plain, Size: 3019 bytes --]

gas: fix bogus error on .org involving expression

For years I have been carrying this change, and it was long forgotten
what it was originally meant to deal with, hence I've never submitted
it. Until I came across an issue with Linux kernel like alternative
instruction patching, where the space needed to hold the replacement
instruction was allocated using .org. Things built fine for me (since
I had the patch in place), and things also built fine on 2.20. But
assemblers from at least 2.22 onwards produce an undefined symbol
warning for the "orig" label in the new test case, followed by an
error complaining that .org would be moving backwards (which is a
logical consequence of the undefined symbol getting replaced by plain
zero).

gas/
2016-03-02  Jan Beulich  <jbeulich@suse.com>

	* expr.c (expr): Set retval to expr_section for expressions
	involving symbols, which cannot be resolved right away.

gas/testsuite/
2016-03-02  Jan Beulich  <jbeulich@suse.com>

	* expr-org.s, expr.org.d: New.
	* gas.exp: Run new test.

--- 2016-03-02/gas/expr.c
+++ 2016-03-02/gas/expr.c
@@ -1998,7 +1998,11 @@ expr (int rankarg,		/* Larger # is highe
 		  retval = absolute_section;
 		  rightseg = absolute_section;
 		}
+	      else
+		retval = expr_section;
 	    }
+	  else
+	    retval = expr_section;
 	}
       else
 	{
@@ -2010,17 +2014,18 @@ expr (int rankarg,		/* Larger # is highe
 	  resultP->X_add_number = 0;
 	  resultP->X_unsigned = 1;
 	  resultP->X_extrabit = 0;
+	  retval = expr_section;
 	}
 
       if (retval != rightseg)
 	{
-	  if (retval == undefined_section)
+	  if (retval == expr_section)
 	    ;
-	  else if (rightseg == undefined_section)
+	  else if (rightseg == expr_section)
 	    retval = rightseg;
-	  else if (retval == expr_section)
+	  else if (retval == undefined_section)
 	    ;
-	  else if (rightseg == expr_section)
+	  else if (rightseg == undefined_section)
 	    retval = rightseg;
 	  else if (retval == reg_section)
 	    ;
--- 2016-03-02/gas/testsuite/gas/all/expr-org.d
+++ 2016-03-02/gas/testsuite/gas/all/expr-org.d
@@ -0,0 +1,11 @@
+#objdump: -s -j .data -j .alt
+#name: .org with expression (with forward reference)
+
+.*: .*
+
+Contents of section \.data:
+ 0000 [0f][0f]ffff[0f][0f] 01 [ .]*
+
+Contents of section \.alt:
+ 0000 00000000 [ .]*
+#pass
--- 2016-03-02/gas/testsuite/gas/all/expr-org.s
+++ 2016-03-02/gas/testsuite/gas/all/expr-org.s
@@ -0,0 +1,10 @@
+	.data
+orig:
+	.byte	0
+	.org	orig + (alt_end - alt_begin), 0xff
+	.pushsection .alt, "a", @progbits
+alt_begin:
+	.long	0
+alt_end:
+	.popsection
+	.byte	1
--- 2016-03-02/gas/testsuite/gas/all/gas.exp
+++ 2016-03-02/gas/testsuite/gas/all/gas.exp
@@ -371,6 +371,7 @@ if {  ([istarget "i*86-*-*pe*"] && ![ist
 if { ![istarget "bfin-*-*"] && ![istarget "nds32*-*-*"] } then {
     run_dump_test assign
 }
+run_dump_test expr-org
 run_dump_test sleb128
 run_dump_test sleb128-2
 run_dump_test sleb128-3

             reply	other threads:[~2016-03-02 11:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-02 11:29 Jan Beulich [this message]
2016-03-16 16:40 ` Ping: " Jan Beulich
2016-03-16 23:46   ` Alan Modra
2016-03-17  8:16     ` Jan Beulich
2016-03-22  9:19     ` Jan Beulich
2016-03-22 12:26       ` Hans-Peter Nilsson
2016-03-22 16:49         ` Jan Beulich
2016-03-23 18:55       ` augustine.sterling
2022-06-27 14:07 Jan Beulich
2022-06-28  3:15 ` Alan Modra
2022-06-28  7:13   ` Jan Beulich
2022-08-12 11:20   ` Jan Beulich

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=56D6DCAB02000078000D845A@prv-mh.provo.novell.com \
    --to=jbeulich@suse.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).