This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Fix riscv malloc error on small alignment after norvc.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=36877bfb88f99dd0e4336f98233f7caaa1d594a7

commit 36877bfb88f99dd0e4336f98233f7caaa1d594a7
Author: Jim Wilson <jimw@sifive.com>
Date:   Wed Nov 29 10:36:46 2017 -0800

    Fix riscv malloc error on small alignment after norvc.
    
    	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.

Diff:
---
 gas/ChangeLog                     |  7 +++++++
 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 ++---------
 5 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 8124043..5e4edea 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -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.
 
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 8bb400e..c2e5f30 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 0000000..8ea739b
--- /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 0000000..ee6a94d
--- /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 5ef92f5..162c77d 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"
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]