[PATCH] RISC-V: Error for relaxable branch in absolute section.
Jim Wilson
jimw@sifive.com
Thu Sep 24 22:20:18 GMT 2020
Emit an error instead of crashing in frag_new, handling this same as the
i386 port.
Tested with riscv{32,64}-{elf,linux} cross build and test. There were no
regressions. The new testcase fails without the patch and works with the
patch.
Committed.
Jim
gas/
PR 26400
* config/tc-riscv.c (append_insn): If in absolute section, emit
error before add_relaxed_insn call.
* testsuite/gas/riscv/absolute-sec.d: New.
* testsuite/gas/riscv/absolute-sec.l: New.
* testsuite/gas/riscv/absolute-sec.s: New.
---
gas/config/tc-riscv.c | 7 +++++++
gas/testsuite/gas/riscv/absolute-sec.d | 3 +++
gas/testsuite/gas/riscv/absolute-sec.l | 2 ++
gas/testsuite/gas/riscv/absolute-sec.s | 2 ++
4 files changed, 14 insertions(+)
create mode 100644 gas/testsuite/gas/riscv/absolute-sec.d
create mode 100644 gas/testsuite/gas/riscv/absolute-sec.l
create mode 100644 gas/testsuite/gas/riscv/absolute-sec.s
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index eb31e42a2e..7c228430ad 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -1106,6 +1106,13 @@ append_insn (struct riscv_cl_insn *ip, expressionS *address_expr,
int j = reloc_type == BFD_RELOC_RISCV_JMP;
int best_case = riscv_insn_length (ip->insn_opcode);
unsigned worst_case = relaxed_branch_length (NULL, NULL, 0);
+
+ if (now_seg == absolute_section)
+ {
+ as_bad (_("relaxable branches not supported in absolute section"));
+ return;
+ }
+
add_relaxed_insn (ip, worst_case, best_case,
RELAX_BRANCH_ENCODE (j, best_case == 2, worst_case),
address_expr->X_add_symbol,
diff --git a/gas/testsuite/gas/riscv/absolute-sec.d b/gas/testsuite/gas/riscv/absolute-sec.d
new file mode 100644
index 0000000000..c32e94eed1
--- /dev/null
+++ b/gas/testsuite/gas/riscv/absolute-sec.d
@@ -0,0 +1,3 @@
+#as:
+#source absolute-sec.s
+#error_output: absolute-sec.l
diff --git a/gas/testsuite/gas/riscv/absolute-sec.l b/gas/testsuite/gas/riscv/absolute-sec.l
new file mode 100644
index 0000000000..f5d32c47ac
--- /dev/null
+++ b/gas/testsuite/gas/riscv/absolute-sec.l
@@ -0,0 +1,2 @@
+.*: Assembler messages:
+.*: Error: relaxable branches not supported in absolute section
diff --git a/gas/testsuite/gas/riscv/absolute-sec.s b/gas/testsuite/gas/riscv/absolute-sec.s
new file mode 100644
index 0000000000..d7d67997da
--- /dev/null
+++ b/gas/testsuite/gas/riscv/absolute-sec.s
@@ -0,0 +1,2 @@
+ .offset 0
+ jal x0, 100
--
2.17.1
More information about the Binutils
mailing list