aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Coplan <alex.coplan@arm.com>2020-05-29 16:04:50 +0100
committerAndreas K. Hüttel <dilfridge@gentoo.org>2020-07-31 03:23:28 +0300
commit354c142bf8aaa9e3653afdcebd6df4d60248c0ff (patch)
treed966681d8f0411cc2adfd6fd55aa70651cd7926e
parentPrevent a potential use-after-fee memory corruption bug in the linker (for PE... (diff)
downloadbinutils-gdb-354c142bf8aaa9e3653afdcebd6df4d60248c0ff.tar.gz
binutils-gdb-354c142bf8aaa9e3653afdcebd6df4d60248c0ff.tar.bz2
binutils-gdb-354c142bf8aaa9e3653afdcebd6df4d60248c0ff.zip
gas: Fix checking for backwards .org with negative offset
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) (cherry picked from commit 7324292cd94269c6542492beea9a11f11d0bd8b1)
-rw-r--r--gas/ChangeLog13
-rw-r--r--gas/testsuite/gas/aarch64/org-neg.d3
-rw-r--r--gas/testsuite/gas/aarch64/org-neg.l2
-rw-r--r--gas/testsuite/gas/aarch64/org-neg.s2
-rw-r--r--gas/testsuite/gas/arm/org-neg.d3
-rw-r--r--gas/testsuite/gas/arm/org-neg.l2
-rw-r--r--gas/testsuite/gas/arm/org-neg.s2
-rw-r--r--gas/write.c4
8 files changed, 29 insertions, 2 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 13ff6add65..92957f531b 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -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
index 0000000000..83e6af6afb
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/org-neg.d
@@ -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
index 0000000000..f8414adc19
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/org-neg.l
@@ -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
index 0000000000..403e70d5e0
--- /dev/null
+++ b/gas/testsuite/gas/aarch64/org-neg.s
@@ -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
index 0000000000..83e6af6afb
--- /dev/null
+++ b/gas/testsuite/gas/arm/org-neg.d
@@ -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
index 0000000000..f8414adc19
--- /dev/null
+++ b/gas/testsuite/gas/arm/org-neg.l
@@ -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
index 0000000000..f60486e2c8
--- /dev/null
+++ b/gas/testsuite/gas/arm/org-neg.s
@@ -0,0 +1,2 @@
+.=-1
+nop
diff --git a/gas/write.c b/gas/write.c
index 5d9a239422..acdf07b344 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -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;