This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed v2] GAS: Fix bogus "attempt to move .org backwards" relaxation errors


Fix a commit 6afe8e98a664 ("internal error for backwards .org"), 
<https://www.sourceware.org/ml/binutils/2008-06/msg00212.html>, 
GAS regression that caused legitimate code to fail assembly with an 
"attempt to move .org backwards" error.

For example with the `mips-linux' target we get:

$ cat org.s
	.set	mips16
	la	$2, foo
	.org	0x1000
	.align	2
foo:
	.half	0
$ as -o org.o org.s
org.s: Assembler messages:
org.s:3: Error: attempt to move .org backwards
$

where the location pointer is obviously not moved backwards with `.org'.

The cause is positive `stretch' in relaxation due to a PC-relative ADDIU 
instruction (produced from the LA macro used) getting expanded from 2 to 
4 bytes as `foo' is noticed to be out of range for the short encoding.  
This in turn triggers logic in `relax_segment' which concludes in the 
processing of an `rs_org' frag produced that the location pointer is 
moved backwards while in fact only the amount to space forward to the 
location requested has shrunk, resulting in a negative growth of the 
frag.

Correct the bad logic then and instead verify that the fixed part of an 
`rs_org' frag has not overrun the location requested, as per the comment 
already included with the error message:

/* Growth may be negative, but variable part of frag
   cannot have fewer than 0 chars.  That is, we can't
   .org backwards.  */

which accurately describes the regression scenario.  Move the comment 
ahead the conditional noted, for clarity.

Add generic and MIPS test cases for the `.org' pseudo-op, including the 
test case discussed though not integrated with the offending commit in 
particular, adjusted to work across all targets.

	gas/
	* write.c (relax_segment) <rs_org>: Only bail out if the fixed 
	part of the frag has overrun the location requested.

	* testsuite/gas/all/org-1.d: New test.
	* testsuite/gas/all/org-2.d: New test.
	* testsuite/gas/all/org-3.d: New test.
	* testsuite/gas/all/org-4.d: New test.
	* testsuite/gas/all/org-5.d: New test.
	* testsuite/gas/all/org-6.d: New test.
	* testsuite/gas/all/org-1.l: New stderr output.
	* testsuite/gas/all/org-2.l: New stderr output.
	* testsuite/gas/all/org-3.l: New stderr output.
	* testsuite/gas/all/org-1.s: New test source.
	* testsuite/gas/all/org-2.s: New test source.
	* testsuite/gas/all/org-3.s: New test source.
	* testsuite/gas/all/org-4.s: New test source.
	* testsuite/gas/all/org-5.s: New test source.
	* testsuite/gas/all/org-6.s: New test source.
	* testsuite/gas/all/gas.exp: Run the new tests.

	* testsuite/gas/mips/org-1.d: New test.
	* testsuite/gas/mips/org-2.d: New test.
	* testsuite/gas/mips/org-3.d: New test.
	* testsuite/gas/mips/org-4.d: New test.
	* testsuite/gas/mips/org-5.d: New test.
	* testsuite/gas/mips/org-6.d: New test.
	* testsuite/gas/mips/org-7.d: New test.
	* testsuite/gas/mips/org-8.d: New test.
	* testsuite/gas/mips/org-9.d: New test.
	* testsuite/gas/mips/org-10.d: New test.
	* testsuite/gas/mips/org-11.d: New test.
	* testsuite/gas/mips/org-12.d: New test.
	* testsuite/gas/mips/org-1.l: New stderr output.
	* testsuite/gas/mips/org-4.l: New stderr output.
	* testsuite/gas/mips/org-5.l: New stderr output.
	* testsuite/gas/mips/org-6.l: New stderr output.
	* testsuite/gas/mips/org-10.l: New stderr output.
	* testsuite/gas/mips/org-1.s: New test source.
	* testsuite/gas/mips/org-2.s: New test source.
	* testsuite/gas/mips/org-3.s: New test source.
	* testsuite/gas/mips/org-4.s: New test source.
	* testsuite/gas/mips/org-5.s: New test source.
	* testsuite/gas/mips/org-6.s: New test source.
	* testsuite/gas/mips/org-7.s: New test source.
	* testsuite/gas/mips/org-8.s: New test source.
	* testsuite/gas/mips/org-9.s: New test source.
	* testsuite/gas/mips/org-10.s: New test source.
	* testsuite/gas/mips/org-11.s: New test source.
	* testsuite/gas/mips/org-12.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.
---
On Wed, 1 Mar 2017, Alan Modra wrote:

> On Wed, Mar 01, 2017 at 05:13:44PM +0000, Maciej W. Rozycki wrote:
> > Index: binutils/gas/write.c
> > ===================================================================
> > --- binutils.orig/gas/write.c	2017-03-01 14:12:17.313787305 +0000
> > +++ binutils/gas/write.c	2017-03-01 14:23:24.928461971 +0000
> > @@ -2692,7 +2692,7 @@ relax_segment (struct frag *segment_frag
> >  		  know (fragP->fr_next);
> >  		  after = fragP->fr_next->fr_address + stretch;
> >  		  growth = target - after;
> > -		  if (growth < 0)
> > +		  if (address + fragP->fr_fix > target)
> >  		    {
> >  		      growth = 0;
> >  
> 
> OK, but please move the comment from as_bad_where call to just before
> the test.

 Thanks for your review.  For the record here's what I have applied then.

  Maciej

Changes from v1:

- use a local symbol with branches too across MIPS tests,

- move the comment from `as_bad_where' ahead the containing conditional.

binutils-gas-relax-segment-org-negative.diff
Index: binutils/gas/testsuite/gas/all/gas.exp
===================================================================
--- binutils.orig/gas/testsuite/gas/all/gas.exp	2017-03-01 14:12:17.159877717 +0000
+++ binutils/gas/testsuite/gas/all/gas.exp	2017-03-01 14:23:24.142399027 +0000
@@ -455,3 +455,31 @@ load_lib gas-dg.exp
 dg-init
 dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/err-*.s $srcdir/$subdir/warn-*.s]] "" ""
 dg-finish
+
+# Set $nop_type appropriately to indicate the NOP instruction mnemonic.
+case $target_triplet in {
+    { "mmix-*-*" } {
+	set nop_type 5
+    }
+    { "i960-*-*" } {
+	set nop_type 4
+    }
+    { "i370-*-*" } {
+	set nop_type 3
+    }
+    { "or1k*-*-*" } {
+	set nop_type 2
+    }
+    { "ia64-*-*" } {
+	set nop_type 1
+    }
+    default {
+	set nop_type 0
+    }
+}
+run_dump_test "org-1" [list [list as "--defsym nop_type=$nop_type"]]
+run_dump_test "org-2"
+run_dump_test "org-3"
+run_dump_test "org-4"
+run_dump_test "org-5"
+run_dump_test "org-6"
Index: binutils/gas/testsuite/gas/all/org-1.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-1.d	2017-03-01 14:23:24.152518806 +0000
@@ -0,0 +1,3 @@
+#name: .org test 1
+#as: -gdwarf2
+#error-output: org-1.l
Index: binutils/gas/testsuite/gas/all/org-1.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-1.l	2017-03-01 14:23:24.166651867 +0000
@@ -0,0 +1,2 @@
+.*: Assembler messages:
+.*:22: Error: attempt to move \.org backwards
Index: binutils/gas/testsuite/gas/all/org-1.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-1.s	2017-03-01 14:34:07.509613397 +0000
@@ -0,0 +1,25 @@
+	.macro	i_nop
+	.if	nop_type == 1
+	nop	0
+	.elseif	nop_type == 2
+	l.nop
+	.elseif	nop_type == 3
+	nopr	1
+	.elseif	nop_type == 4
+	mov	g0, g0
+	.elseif	nop_type == 5
+	set	$0, $0
+	.else
+	nop
+	.endif
+	.endm
+
+	.text
+	.org	0x20
+	.globl	foo
+foo:
+	i_nop
+	.org	0x10
+	.globl	bar
+bar:
+	i_nop
Index: binutils/gas/testsuite/gas/all/org-2.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-2.d	2017-03-01 14:23:24.176721957 +0000
@@ -0,0 +1,2 @@
+#name: .org test 2
+#error-output: org-2.l
Index: binutils/gas/testsuite/gas/all/org-2.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-2.l	2017-03-01 14:23:24.186933519 +0000
@@ -0,0 +1,2 @@
+.*: Assembler messages:
+.*:6: Error: attempt to move \.org backwards
Index: binutils/gas/testsuite/gas/all/org-2.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-2.s	2017-03-01 14:23:24.200214531 +0000
@@ -0,0 +1,9 @@
+	.data
+	.org	0x10
+	.globl	foo
+foo:
+	.byte	0, 1, 2, 3
+	.org	0x10
+	.globl	bar
+bar:
+	.byte	0, 1, 2, 3
Index: binutils/gas/testsuite/gas/all/org-3.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-3.d	2017-03-01 14:23:24.222509695 +0000
@@ -0,0 +1,2 @@
+#name: .org test 3
+#error-output: org-3.l
Index: binutils/gas/testsuite/gas/all/org-3.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-3.l	2017-03-01 14:23:24.249928277 +0000
@@ -0,0 +1,2 @@
+.*: Assembler messages:
+.*:6: Error: attempt to move \.org backwards
Index: binutils/gas/testsuite/gas/all/org-3.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-3.s	2017-03-01 14:23:24.261150876 +0000
@@ -0,0 +1,9 @@
+	.data
+	.org	0x10
+	.globl	foo
+foo:
+	.byte	0, 1, 2, 3
+	.org	0x13
+	.globl	bar
+bar:
+	.byte	0, 1, 2, 3
Index: binutils/gas/testsuite/gas/all/org-4.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-4.d	2017-03-01 14:23:24.280319831 +0000
@@ -0,0 +1,5 @@
+#nm: -g --defined-only
+#name: .org test 4
+
+0+000014 . bar
+0+000010 . foo
Index: binutils/gas/testsuite/gas/all/org-4.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-4.s	2017-03-01 14:23:24.301647020 +0000
@@ -0,0 +1,9 @@
+	.data
+	.org	0x10
+	.globl	foo
+foo:
+	.byte	0, 1, 2, 3
+	.org	0x14
+	.globl	bar
+bar:
+	.byte	0, 1, 2, 3
Index: binutils/gas/testsuite/gas/all/org-5.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-5.d	2017-03-01 14:23:24.317764381 +0000
@@ -0,0 +1,5 @@
+#nm: -g --defined-only
+#name: .org test 5
+
+0+000015 . bar
+0+000010 . foo
Index: binutils/gas/testsuite/gas/all/org-5.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-5.s	2017-03-01 14:23:24.342091187 +0000
@@ -0,0 +1,9 @@
+	.data
+	.org	0x10
+	.globl	foo
+foo:
+	.byte	0, 1, 2, 3
+	.org	0x15
+	.globl	bar
+bar:
+	.byte	0, 1, 2, 3
Index: binutils/gas/testsuite/gas/all/org-6.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-6.d	2017-03-01 14:23:24.358293907 +0000
@@ -0,0 +1,5 @@
+#nm: -g --defined-only
+#name: .org test 6
+
+0+000018 . bar
+0+000010 . foo
Index: binutils/gas/testsuite/gas/all/org-6.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/all/org-6.s	2017-03-01 14:23:24.366433510 +0000
@@ -0,0 +1,9 @@
+	.data
+	.org	0x10
+	.globl	foo
+foo:
+	.byte	0, 1, 2, 3
+	.org	0x18
+	.globl	bar
+bar:
+	.byte	0, 1, 2, 3
Index: binutils/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips.exp	2017-03-01 14:12:17.233626688 +0000
+++ binutils/gas/testsuite/gas/mips/mips.exp	2017-03-01 14:23:24.391754456 +0000
@@ -1806,6 +1806,19 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test "debug-label-end-2"
     run_dump_test "debug-label-end-3"
 
+    run_dump_test "org-1"
+    run_dump_test "org-2"
+    run_dump_test "org-3"
+    run_dump_test "org-4"
+    run_dump_test "org-5"
+    run_dump_test "org-6"
+    run_dump_test "org-7"
+    run_dump_test "org-8"
+    run_dump_test "org-9"
+    run_dump_test "org-10"
+    run_dump_test "org-11"
+    run_dump_test "org-12"
+
     run_dump_test_arches "r6"		[mips_arch_list_matching mips32r6]
     if $has_newabi {
 	run_dump_test_arches "r6-n32"	[mips_arch_list_matching mips64r6]
Index: binutils/gas/testsuite/gas/mips/org-1.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-1.d	2017-03-01 14:23:24.419064093 +0000
@@ -0,0 +1,7 @@
+#nm: -g --defined-only
+#as: --relax-branch
+#name: MIPS .org test 1
+#stderr: org-1.l
+
+0+100000 . bar
+0+000000 . foo
Index: binutils/gas/testsuite/gas/mips/org-1.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-1.l	2017-03-01 14:23:24.437389782 +0000
@@ -0,0 +1,2 @@
+.*: Assembler messages:
+.*:4: Warning: relaxed out-of-range branch into a jump
Index: binutils/gas/testsuite/gas/mips/org-1.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-1.s	2017-03-01 17:25:53.230674220 +0000
@@ -0,0 +1,9 @@
+	.text
+	.globl	foo
+foo:
+	beqz	$2, lbar
+	.org	0x100000
+	.globl	bar
+bar:
+lbar:
+	nop
Index: binutils/gas/testsuite/gas/mips/org-10.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-10.d	2017-03-01 14:23:24.480855483 +0000
@@ -0,0 +1,7 @@
+#nm: -g --defined-only
+#as: --relax-branch
+#name: MIPS .org test 10
+#stderr: org-10.l
+
+0+100000 . bar
+0+000000 . foo
Index: binutils/gas/testsuite/gas/mips/org-10.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-10.l	2017-03-01 14:23:24.536306615 +0000
@@ -0,0 +1,2 @@
+.*: Assembler messages:
+.*:4: Warning: relaxed out-of-range branch into a jump
Index: binutils/gas/testsuite/gas/mips/org-10.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-10.s	2017-03-01 17:26:38.231011723 +0000
@@ -0,0 +1,11 @@
+	.text
+	.globl	foo
+foo:
+	beqz	$2, lbar
+	.org	0x10
+	nop
+	.space	0xfffec
+	.globl	bar
+bar:
+lbar:
+	nop
Index: binutils/gas/testsuite/gas/mips/org-11.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-11.d	2017-03-01 14:23:24.559756932 +0000
@@ -0,0 +1,6 @@
+#nm: -g --defined-only
+#as: -32
+#name: MIPS .org test 11
+
+0+001000 . bar
+0+000000 . foo
Index: binutils/gas/testsuite/gas/mips/org-11.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-11.s	2017-03-01 14:23:24.578853597 +0000
@@ -0,0 +1,13 @@
+	.set	mips16
+	.text
+	.globl	foo
+foo:
+	la	$2, lbar
+	.org	0x4
+	nop
+	.space	0xffa
+	.align	2
+	.globl	bar
+bar = .
+lbar = .
+	nop
Index: binutils/gas/testsuite/gas/mips/org-12.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-12.d	2017-03-01 14:23:24.586925792 +0000
@@ -0,0 +1,5 @@
+#nm: -g --defined-only
+#name: MIPS .org test 12
+
+0+001000 . bar
+0+000000 . foo
Index: binutils/gas/testsuite/gas/mips/org-12.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-12.s	2017-03-01 17:26:48.849272808 +0000
@@ -0,0 +1,13 @@
+	.set	micromips
+	.text
+	.globl	foo
+foo:
+	addu	$4, $3, $2
+	beqz	$2, lbar
+	.org	0x6
+	nop
+	.space	0xff8
+	.globl	bar
+bar:
+lbar:
+	nop
Index: binutils/gas/testsuite/gas/mips/org-2.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-2.d	2017-03-01 14:23:24.601047029 +0000
@@ -0,0 +1,6 @@
+#nm: -g --defined-only
+#as: -32
+#name: MIPS .org test 2
+
+0+001000 . bar
+0+000000 . foo
Index: binutils/gas/testsuite/gas/mips/org-2.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-2.s	2017-03-01 14:23:24.603054738 +0000
@@ -0,0 +1,11 @@
+	.set	mips16
+	.text
+	.globl	foo
+foo:
+	la	$2, lbar
+	.org	0x1000
+	.align	2
+	.globl	bar
+bar = .
+lbar = .
+	nop
Index: binutils/gas/testsuite/gas/mips/org-3.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-3.d	2017-03-01 14:23:24.620149361 +0000
@@ -0,0 +1,5 @@
+#nm: -g --defined-only
+#name: MIPS .org test 3
+
+0+001000 . bar
+0+000000 . foo
Index: binutils/gas/testsuite/gas/mips/org-3.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-3.s	2017-03-01 17:27:00.714223753 +0000
@@ -0,0 +1,11 @@
+	.set	micromips
+	.text
+	.globl	foo
+foo:
+	addu	$4, $3, $2
+	beqz	$2, lbar
+	.org	0x1000
+	.globl	bar
+bar:
+lbar:
+	nop
Index: binutils/gas/testsuite/gas/mips/org-4.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-4.d	2017-03-01 14:23:24.665456322 +0000
@@ -0,0 +1,3 @@
+#as: --relax-branch
+#name: MIPS .org test 4
+#error-output: org-4.l
Index: binutils/gas/testsuite/gas/mips/org-4.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-4.l	2017-03-01 14:23:24.677507009 +0000
@@ -0,0 +1,3 @@
+.*: Assembler messages:
+.*:5: Error: attempt to move \.org backwards
+.*:4: Warning: relaxed out-of-range branch into a jump
Index: binutils/gas/testsuite/gas/mips/org-4.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-4.s	2017-03-01 17:27:19.337039547 +0000
@@ -0,0 +1,11 @@
+	.text
+	.globl	foo
+foo:
+	beqz	$2, lbar
+	.org	0xc
+	nop
+	.space	0xffff0
+	.globl	bar
+bar:
+lbar:
+	nop
Index: binutils/gas/testsuite/gas/mips/org-5.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-5.d	2017-03-01 14:23:24.714041924 +0000
@@ -0,0 +1,3 @@
+#as: -32
+#name: MIPS .org test 5
+#error-output: org-5.l
Index: binutils/gas/testsuite/gas/mips/org-5.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-5.l	2017-03-01 14:23:24.740374688 +0000
@@ -0,0 +1,2 @@
+.*: Assembler messages:
+.*:6: Error: attempt to move \.org backwards
Index: binutils/gas/testsuite/gas/mips/org-5.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-5.s	2017-03-01 14:23:24.747465371 +0000
@@ -0,0 +1,13 @@
+	.set	mips16
+	.text
+	.globl	foo
+foo:
+	la	$2, lbar
+	.org	0x2
+	nop
+	.space	0xffc
+	.align	2
+	.globl	bar
+bar = .
+lbar = .
+	nop
Index: binutils/gas/testsuite/gas/mips/org-6.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-6.d	2017-03-01 14:23:24.769724690 +0000
@@ -0,0 +1,2 @@
+#name: MIPS .org test 6
+#error-output: org-6.l
Index: binutils/gas/testsuite/gas/mips/org-6.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-6.l	2017-03-01 14:23:24.790903056 +0000
@@ -0,0 +1,2 @@
+.*: Assembler messages:
+.*:7: Error: attempt to move \.org backwards
Index: binutils/gas/testsuite/gas/mips/org-6.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-6.s	2017-03-01 17:27:33.237465253 +0000
@@ -0,0 +1,13 @@
+	.set	micromips
+	.text
+	.globl	foo
+foo:
+	addu	$4, $3, $2
+	beqz	$2, lbar
+	.org	0x4
+	nop
+	.space	0xffa
+	.globl	bar
+bar:
+lbar:
+	nop
Index: binutils/gas/testsuite/gas/mips/org-7.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-7.d	2017-03-01 14:23:24.819271347 +0000
@@ -0,0 +1,6 @@
+#nm: -g --defined-only
+#as: --relax-branch
+#name: MIPS .org test 7
+
+0+010000 . bar
+0+000000 . foo
Index: binutils/gas/testsuite/gas/mips/org-7.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-7.s	2017-03-01 17:27:41.450108345 +0000
@@ -0,0 +1,11 @@
+	.text
+	.globl	foo
+foo:
+	beqz	$2, lbar
+	.org	0x8
+	nop
+	.space	0xfff4
+	.globl	bar
+bar:
+lbar:
+	nop
Index: binutils/gas/testsuite/gas/mips/org-8.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-8.d	2017-03-01 14:23:24.841464867 +0000
@@ -0,0 +1,6 @@
+#nm: -g --defined-only
+#as: -32
+#name: MIPS .org test 8
+
+0+000100 . bar
+0+000000 . foo
Index: binutils/gas/testsuite/gas/mips/org-8.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-8.s	2017-03-01 14:23:24.859586003 +0000
@@ -0,0 +1,13 @@
+	.set	mips16
+	.text
+	.globl	foo
+foo:
+	la	$2, lbar
+	.org	0x2
+	nop
+	.space	0xfc
+	.align	2
+	.globl	bar
+bar = .
+lbar = .
+	nop
Index: binutils/gas/testsuite/gas/mips/org-9.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-9.d	2017-03-01 14:23:24.883841508 +0000
@@ -0,0 +1,5 @@
+#nm: -g --defined-only
+#name: MIPS .org test 9
+
+0+000080 . bar
+0+000000 . foo
Index: binutils/gas/testsuite/gas/mips/org-9.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/org-9.s	2017-03-01 17:27:59.033337776 +0000
@@ -0,0 +1,13 @@
+	.set	micromips
+	.text
+	.globl	foo
+foo:
+	addu	$4, $3, $2
+	beqz	$2, lbar
+	.org	0x4
+	nop
+	.space	0x7a
+	.globl	bar
+bar:
+lbar:
+	nop
Index: binutils/gas/write.c
===================================================================
--- binutils.orig/gas/write.c	2017-03-01 14:12:17.313787305 +0000
+++ binutils/gas/write.c	2017-03-02 00:38:15.148053661 +0000
@@ -2692,7 +2692,11 @@ relax_segment (struct frag *segment_frag
 		  know (fragP->fr_next);
 		  after = fragP->fr_next->fr_address + stretch;
 		  growth = target - after;
-		  if (growth < 0)
+
+		  /* Growth may be negative, but variable part of frag
+		     cannot have fewer than 0 chars.  That is, we can't
+		     .org backwards.  */
+		  if (address + fragP->fr_fix > target)
 		    {
 		      growth = 0;
 
@@ -2714,9 +2718,6 @@ relax_segment (struct frag *segment_frag
 			  break;
 			}
 
-		      /* Growth may be negative, but variable part of frag
-			 cannot have fewer than 0 chars.  That is, we can't
-			 .org backwards.  */
 		      as_bad_where (fragP->fr_file, fragP->fr_line,
 				    _("attempt to move .org backwards"));
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]