Hello, This patch fixes internal errors in (at least) arm and aarch64 GAS when assembling code that attempts a negative .org. For example, assembling: .=-1 nop would give: test.s: Assembler messages: test.s:1: Error: attempt to .org/.space/.nops backwards? (-1) test.s: Internal error in check_mapping_symbols at ../../../binutils-gdb/gas/config/tc-aarch64.c:8557. Please report this bug. on aarch64, and: test.s: Assembler messages: test.s:1: Error: attempt to .org/.space/.nops backwards? (-1) test.s: Internal error in make_mapping_symbol at ../../../../src/binutils-gdb/gas/config/tc-arm.c:3017. Please report this bug. on arm. The bug appears to be a regression introduced in binutils-2.29 by this commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9875b36538d35f2292ddc3bb5e7c60e1582aa087 The problem is in the rs_org case of the main switch statement in gas/write.c:relax_segment(). This code assigns the signed variable `offset' to the unsigned variable `target' and then proceeds to do an unsigned comparison: if (address + fragP->fr_fix > target) which fails in this case because `offset' was -1 and so `target' wrapped to become UINT64_MAX. This patch uses a signed type for `target' and casts the LHS to ensure a signed comparison is used here. Testing: * New tests for arm and aarch64. * Regression tested on a wide variety of targets. * Bootstrapped on aarch64. Ok for master and backport to binutils-2.34? Thanks, Alex --- gas/ChangeLog: 2020-05-29 Alex Coplan * 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. * write.c (relax_segment): Fix handling of negative offset when relaxing an rs_org frag.