History

riscv: fix jal: fix reloc and parsing

Ekaitz Zarraga committed 2 years ago

Commit e02eec61 parent 02391331 file · +15 −8Browse files

Unified · Split

riscv64-asm.c+15−8
@@ -272,18 +272,25 @@ static void asm_jal_opcode(TCCState *s1, int token){ · 271 unmodified lines
272272 static const Operand ra = {.type = OP_REG, .reg = 1};
273273 Operand ops[2];
274274 parse_operand(s1, &ops[0]);
275− if ( tok == ',')
276− next();
277− else {
275+ if ( ops[0].type != OP_REG ) {
278276 /* no more operands, it's the pseudoinstruction:
279− * jal rs
277+ * jal offset
280278 * Expand to:
281− * jal ra, rs
279+ * jal ra, offset
282280 */
283− asm_emit_j(token, 0x6f, &ra, &ops[0]);
284− return;
281+ ops[1] = ops[0];
282+ ops[0] = ra;
283+ goto emit;
285284 }
285+ if ( tok == ',')
286+ next();
287+ else
288+ expect("','");
286289 parse_operand(s1, &ops[1]);
290+emit:
291+ if (ops[1].e.sym && ops[1].e.sym->type.t & (VT_EXTERN | VT_STATIC)){
292+ greloca(cur_text_section, ops[1].e.sym, ind, R_RISCV_JAL, 0);
293+ }
287294 asm_emit_j(token, 0x6f, &ops[0], &ops[1]);
288295 }
289296
@@ -722,7 +729,7 @@ static void asm_emit_j(int token, uint32_t opcode, const Operand* rd, const Oper · 432 unmodified lines
722729 imm = rs2->e.v;
723730
724731 /* even offsets in a +- 1 MiB range */
725− if (imm > 0x1ffffe) {
732+ if ((int)imm > (1 << 20) -1 || (int)imm <= -1 * ((1 << 20) -1)) {
726733 tcc_error("'%s': Expected second source operand that is an immediate value between 0 and 0x1fffff", get_tok_str(token, NULL));
727734 return;
728735 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t