Fix riscv malloc error on small alignment after norvc.
authorJim Wilson <jimw@sifive.com>
Wed, 29 Nov 2017 18:36:46 +0000 (10:36 -0800)
committerJim Wilson <jimw@sifive.com>
Wed, 29 Nov 2017 18:36:46 +0000 (10:36 -0800)
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/ChangeLog
gas/config/tc-riscv.c
gas/testsuite/gas/riscv/align-1.l [new file with mode: 0644]
gas/testsuite/gas/riscv/align-1.s [new file with mode: 0644]
gas/testsuite/gas/riscv/riscv.exp

index 8124043fac3f44a9d48e7600a6e460094020b827..5e4edeab7c5b94b8707275bd884c3d4a3d97dcac 100644 (file)
@@ -1,5 +1,12 @@
 2017-11-29  Jim Wilson  <jimw@sifive.com>
 
+       * 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.
+
        PR gas/22464
        * doc/c-i386.texi (-n): Clarify docs.
 
index 8bb400e1001bbb74ade4db73c6c2c3e552634ee5..c2e5f30e506e3a4b4d4530565bd6d05e9c7bd5a7 100644 (file)
@@ -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 (file)
index 0000000..8ea739b
--- /dev/null
@@ -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 (file)
index 0000000..ee6a94d
--- /dev/null
@@ -0,0 +1,3 @@
+       .option norvc
+       .align 2
+       .align 1
index 5ef92f500698f8a2418e8bf447f501d999eb99b9..162c77d96ad05c614e12fa55e6d15eba16275a6f 100644 (file)
 # 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"
 }