]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: Fix checking for backwards .org with negative offset
authorAlex Coplan <alex.coplan@arm.com>
Fri, 29 May 2020 15:04:50 +0000 (16:04 +0100)
committerAlan Modra <amodra@gmail.com>
Wed, 10 Jun 2020 06:21:02 +0000 (15:51 +0930)
This patch fixes internal errors in (at least) arm and aarch64 GAS
when assembling code that attempts a negative .org.  The bug appears
to be a regression introduced in binutils-2.29 by commit 9875b36538d.

* write.c (relax_segment): Fix handling of negative offset when
relaxing an rs_org frag.
* testsuite/gas/aarch64/org-neg.d: New test.
* testsuite/gas/aarch64/org-neg.l: Error output for test.
* testsuite/gas/aarch64/org-neg.s: Input for test.
* testsuite/gas/arm/org-neg.d: New test.
* testsuite/gas/arm/org-neg.l: Error output for test.
* testsuite/gas/arm/org-neg.s: Input for test.

(cherry picked from commit c39c821c1da3e8a64eff5984a39e104eb798e8b8)

gas/ChangeLog
gas/testsuite/gas/aarch64/org-neg.d [new file with mode: 0644]
gas/testsuite/gas/aarch64/org-neg.l [new file with mode: 0644]
gas/testsuite/gas/aarch64/org-neg.s [new file with mode: 0644]
gas/testsuite/gas/arm/org-neg.d [new file with mode: 0644]
gas/testsuite/gas/arm/org-neg.l [new file with mode: 0644]
gas/testsuite/gas/arm/org-neg.s [new file with mode: 0644]
gas/write.c

index 13ff6add655749d5a55186802f79a7381d21c016..92957f531baea352e2bd904f9664263b2cf94872 100644 (file)
@@ -1,3 +1,16 @@
+2020-06-10  Alex Coplan  <alex.coplan@arm.com>
+
+       Backport from master
+       2020-06-01  Alex Coplan  <alex.coplan@arm.com>
+       * write.c (relax_segment): Fix handling of negative offset when
+       relaxing an rs_org frag.
+       * testsuite/gas/aarch64/org-neg.d: New test.
+       * testsuite/gas/aarch64/org-neg.l: Error output for test.
+       * testsuite/gas/aarch64/org-neg.s: Input for test.
+       * testsuite/gas/arm/org-neg.d: New test.
+       * testsuite/gas/arm/org-neg.l: Error output for test.
+       * testsuite/gas/arm/org-neg.s: Input for test.
+
 2020-05-18  Alexander Fedotov <alfedotov@gmail.com>
 
        PR 25992
diff --git a/gas/testsuite/gas/aarch64/org-neg.d b/gas/testsuite/gas/aarch64/org-neg.d
new file mode 100644 (file)
index 0000000..83e6af6
--- /dev/null
@@ -0,0 +1,3 @@
+#name: negative org should not cause internal error
+#source: org-neg.s
+#error_output: org-neg.l
diff --git a/gas/testsuite/gas/aarch64/org-neg.l b/gas/testsuite/gas/aarch64/org-neg.l
new file mode 100644 (file)
index 0000000..f8414ad
--- /dev/null
@@ -0,0 +1,2 @@
+[^:]*: Assembler messages:
+.*: Error: attempt to move .org backwards
diff --git a/gas/testsuite/gas/aarch64/org-neg.s b/gas/testsuite/gas/aarch64/org-neg.s
new file mode 100644 (file)
index 0000000..403e70d
--- /dev/null
@@ -0,0 +1,2 @@
+.=-1
+ret
diff --git a/gas/testsuite/gas/arm/org-neg.d b/gas/testsuite/gas/arm/org-neg.d
new file mode 100644 (file)
index 0000000..83e6af6
--- /dev/null
@@ -0,0 +1,3 @@
+#name: negative org should not cause internal error
+#source: org-neg.s
+#error_output: org-neg.l
diff --git a/gas/testsuite/gas/arm/org-neg.l b/gas/testsuite/gas/arm/org-neg.l
new file mode 100644 (file)
index 0000000..f8414ad
--- /dev/null
@@ -0,0 +1,2 @@
+[^:]*: Assembler messages:
+.*: Error: attempt to move .org backwards
diff --git a/gas/testsuite/gas/arm/org-neg.s b/gas/testsuite/gas/arm/org-neg.s
new file mode 100644 (file)
index 0000000..f60486e
--- /dev/null
@@ -0,0 +1,2 @@
+.=-1
+nop
index 5d9a2394224d0c36129cc70f0d5755c7014ff9bb..acdf07b3448b43d0e2d970a9c78d5aa082179f67 100644 (file)
@@ -2936,7 +2936,7 @@ relax_segment (struct frag *segment_frag_root, segT segment, int pass)
 
              case rs_org:
                {
-                 addressT target = offset;
+                 offsetT target = offset;
                  addressT after;
 
                  if (symbolP)
@@ -2956,7 +2956,7 @@ relax_segment (struct frag *segment_frag_root, segT segment, int pass)
                  /* 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)
+                 if ((offsetT) (address + fragP->fr_fix) > target)
                    {
                      growth = 0;