On Wed, 2023-02-08 at 12:37 +0800, Youling Tang wrote:
In the case of "[Patch v2 2/5] LoongArch: use la.pcrel instenad of
la.abs for exception handlerS", the above failure will occur.
Patch2 may have certain problems when using the old toolchains.
Youling.
Thanks for the test...
The problem is: old toolchain uses pcaddu12i/ori/lu32i.d/lu52i.d/add.d
for a 3-operand la.pcrel, while the new toolchain uses
pcalau12i/addi.d/lu32i/lu52i/add.d. (I've somehow forgotten all the
difference!)
We can fix it with something like...
+void reloc_handler(unsigned long handler, struct handler_reloc *rel)
+{
+ if (!rel)
+ return;
+
+ for (unsigned long i = 0; i < rel->cnt; i++) {
+ unsigned long pc = handler + rel->entries[i].offset;
+ unsigned long v = rel->entries[i].sym;
/* anchor etc. moved into do_reloc_pcalau12i */
+ union loongarch_instruction *insn =
+ (union loongarch_instruction *)pc;
switch insn[0]->reg1i20_format->reg1i20_format {
case pcaddu12i_op:
do_reloc_pcaddu12i(insn, pc, v);
break;
case pcalau12i_op: /* TODO: add it for asm/inst.h */
do_reloc_pcalau12i(insn, pc, v);
break;
default:
panic("what the f**k");
}
Alternatively, we can also emit the pcalau12i/addi.d/lu32i/lu52i
sequence and overwrite the pcaddu12i/ori sequence generated by the old
toolchain.
Which way do you like?