This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] Fix riscv malloc error on small alignment after norvc.
- From: Jim Wilson <jimw at sifive dot com>
- To: binutils at sourceware dot org
- Cc: Jim Wilson <jimw at sifive dot com>
- Date: Wed, 29 Nov 2017 10:37:56 -0800
- Subject: [PATCH] Fix riscv malloc error on small alignment after norvc.
- Authentication-results: sourceware.org; auth=none
Without this patch, on the included testcase, we get
rohan:2035$ bin/riscv32-unknown-elf-as align-1.s
align-1.s: Assembler messages:
align-1.s:3: Fatal error: can't extend frag 18446744073709551614 chars
rohan:2036$
because the code is trying to malloc (unsigned long)-2 bytes. This is fixed
with an early out exit because no alignment nops are required in this case.
This also adds a new testcase, and simplifies the riscv gas testsuite logic
a little.
Tested with binutils make check on riscv32-elf and riscv64-elf. There were
no regressions. Committed.
Jim
gas/
* config/tc-riscv.c (riscv_frag_align_code): New local insn_alignment.
Early return if bytes less than or equal to insn_alignment.
* testsuite/gas/riscv/align-1.l: New.
* testsuite/gas/riscv/align-1.s: New.
* testsuite/gas/riscv/riscv.exp: Use run_dump_tests. Use run_list_test
for align-1.
---
gas/config/tc-riscv.c | 12 ++++++++++--
gas/testsuite/gas/riscv/align-1.l | 1 +
gas/testsuite/gas/riscv/align-1.s | 3 +++
gas/testsuite/gas/riscv/riscv.exp | 11 ++---------
4 files changed, 16 insertions(+), 11 deletions(-)
create mode 100644 gas/testsuite/gas/riscv/align-1.l
create mode 100644 gas/testsuite/gas/riscv/align-1.s
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 8bb400e100..c2e5f30e50 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -2319,10 +2319,18 @@ bfd_boolean
riscv_frag_align_code (int n)
{
bfd_vma bytes = (bfd_vma) 1 << n;
- bfd_vma worst_case_bytes = bytes - (riscv_opts.rvc ? 2 : 4);
- char *nops = frag_more (worst_case_bytes);
+ bfd_vma insn_alignment = riscv_opts.rvc ? 2 : 4;
+ bfd_vma worst_case_bytes = bytes - insn_alignment;
+ char *nops;
expressionS ex;
+ /* If we are moving to a smaller alignment than the instruction size, then no
+ alignment is required. */
+ if (bytes <= insn_alignment)
+ return TRUE;
+
+ nops = frag_more (worst_case_bytes);
+
/* When not relaxing, riscv_handle_align handles code alignment. */
if (!riscv_opts.relax)
return FALSE;
diff --git a/gas/testsuite/gas/riscv/align-1.l b/gas/testsuite/gas/riscv/align-1.l
new file mode 100644
index 0000000000..8ea739b764
--- /dev/null
+++ b/gas/testsuite/gas/riscv/align-1.l
@@ -0,0 +1 @@
+# No warning or error expected.
diff --git a/gas/testsuite/gas/riscv/align-1.s b/gas/testsuite/gas/riscv/align-1.s
new file mode 100644
index 0000000000..ee6a94dea7
--- /dev/null
+++ b/gas/testsuite/gas/riscv/align-1.s
@@ -0,0 +1,3 @@
+ .option norvc
+ .align 2
+ .align 1
diff --git a/gas/testsuite/gas/riscv/riscv.exp b/gas/testsuite/gas/riscv/riscv.exp
index 5ef92f5006..162c77d96a 100644
--- a/gas/testsuite/gas/riscv/riscv.exp
+++ b/gas/testsuite/gas/riscv/riscv.exp
@@ -19,13 +19,6 @@
# MA 02110-1301, USA.
if [istarget riscv*-*-*] {
- run_dump_test "t_insns"
- run_dump_test "fmv.x"
- run_dump_test "c-lui-fail"
- run_dump_test "c-addi4spn-fail"
- run_dump_test "c-addi16sp-fail"
- run_dump_test "satp"
- run_dump_test "eh-relocs"
- run_dump_test "c-lw"
- run_dump_test "c-ld"
+ run_dump_tests [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
+ run_list_test "align-1"
}
--
2.14.1