LoongArch: gas: Add support for linker relaxation.
authormengqinggang <mengqinggang@loongson.cn>
Thu, 1 Dec 2022 08:17:46 +0000 (16:17 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Tue, 30 May 2023 11:56:46 +0000 (19:56 +0800)
commit56576f4a722b7398d35802ecf7d4185c27d6d69b
treeaf1fcc2ad90da18d0f2c8a4b0834d97343080b1e
parent762444623565211ab2b6ea1fd1a19f8dd7f98888
LoongArch: gas: Add support for linker relaxation.

Add gas -mrelax and -mno-relax option.
Add R_LARCH_RELAX reloc for instrction if it can be relaxed.
ADD R_LARCH_ALIGN reloc for align pseudo instruction because relax.
Add ADD/SUB reloc pair for debug and exception data to calculate symbol
substraction because relax.

gas/ChangeLog:

* config/tc-loongarch.c:
(struct loongarch_cl_insn): New macro_id member.
(enum options): New OPTION_RELAX and OPTION_NO_RELAX.
(struct option): New mrelax and mno-relax.
(md_parse_option): Likewise.
(get_internal_label):
(loongarch_args_parser_can_match_arg_helper): Generate relax reloc.
(move_insn): Set fx_frag and fx_where if exist.
(append_fixp_and_insn): Call frag_wane and frag_new for linker relax
relocs.
(loongarch_assemble_INSNs): New loongarch_cl_insn pointer parameter.
(md_assemble): Fix function call.
(fix_reloc_insn): Likewise.
(md_apply_fix): Generate ADD/SUB reloc pair for debug and exception
data.
(loongarch_fix_adjustable): Delete.
(md_convert_frag): Generate new fix.
(loongarch_pre_output_hook): New function.
(loongarch_make_nops): Likewise.
(loongarch_frag_align_code): Likewise.
(loongarch_insert_uleb128_fixes): Likewise.
(loongarch_md_finish): Likewise.
* config/tc-loongarch.h
(md_allow_local_subtract): New macro define.
(loongarch_frag_align_code): New declare.
(md_do_align): Likewise.
(loongarch_fix_adjustable): Delete.
(tc_fix_adjustable): New macro define.
(TC_FORCE_RELOCATION_SUB_SAME): Likewise.
(TC_LINKRELAX_FIXUP): Likewise.
(TC_FORCE_RELOCATION_LOCAL): Likewise.
(DWARF2_USE_FIXED_ADVANCE_PC): Likewise.
(MD_APPLY_SYM_VALUE): Likewise.
(tc_symbol_new_hook): New extern.
(NOP_OPCODE): Delete.
(loongarch_pre_output_hook): New macro define.
(md_pre_output_hook): Likewise.
(md_finish): Likewise.
(loongarch_md_finish): New extern.
* testsuite/gas/all/align.d: Mark as unsupported on LoongArch.
* testsuite/gas/all/gas.exp: Xfail loongarch*-*.
* testsuite/gas/all/relax.d: Likewise.
* testsuite/gas/elf/dwarf-5-irp.d: Likewise.
* testsuite/gas/elf/dwarf-5-loc0.d: Likewise.
* testsuite/gas/elf/dwarf-5-macro-include.d: Likewise.
* testsuite/gas/elf/dwarf-5-macro.d: Likewise.
* testsuite/gas/elf/dwarf2-11.d: Likewise.
* testsuite/gas/elf/dwarf2-15.d: Likewise.
* testsuite/gas/elf/dwarf2-16.d: Likewise.
* testsuite/gas/elf/dwarf2-17.d: Likewise.
* testsuite/gas/elf/dwarf2-18.d: Likewise.
* testsuite/gas/elf/dwarf2-19.d: Likewise.
* testsuite/gas/elf/dwarf2-5.d: Likewise.
* testsuite/gas/elf/ehopt0.d: Likewise.
* testsuite/gas/elf/elf.exp: Likewise.
* testsuite/gas/elf/section11.d: Likewise.
* testsuite/gas/lns/lns.exp: Likewise.
* testsuite/gas/loongarch/jmp_op.d: Regenerated.
* testsuite/gas/loongarch/li.d: Likewise.
* testsuite/gas/loongarch/macro_op.d: Likewise.
* testsuite/gas/loongarch/macro_op_32.d: Likewise.
* testsuite/gas/loongarch/macro_op_large_abs.d: Likewise.
* testsuite/gas/loongarch/macro_op_large_pc.d: Likewise.
* testsuite/gas/loongarch/relax_align.d: New test.
* testsuite/gas/loongarch/relax_align.s: New test.
* testsuite/gas/loongarch/uleb128.d: New test.
* testsuite/gas/loongarch/uleb128.s: New test.
30 files changed:
gas/config/tc-loongarch.c
gas/config/tc-loongarch.h
gas/testsuite/gas/all/align.d
gas/testsuite/gas/all/gas.exp
gas/testsuite/gas/all/relax.d
gas/testsuite/gas/elf/dwarf-5-irp.d
gas/testsuite/gas/elf/dwarf-5-loc0.d
gas/testsuite/gas/elf/dwarf-5-macro-include.d
gas/testsuite/gas/elf/dwarf-5-macro.d
gas/testsuite/gas/elf/dwarf2-11.d
gas/testsuite/gas/elf/dwarf2-15.d
gas/testsuite/gas/elf/dwarf2-16.d
gas/testsuite/gas/elf/dwarf2-17.d
gas/testsuite/gas/elf/dwarf2-18.d
gas/testsuite/gas/elf/dwarf2-19.d
gas/testsuite/gas/elf/dwarf2-5.d
gas/testsuite/gas/elf/ehopt0.d
gas/testsuite/gas/elf/elf.exp
gas/testsuite/gas/elf/section11.d
gas/testsuite/gas/lns/lns.exp
gas/testsuite/gas/loongarch/jmp_op.d
gas/testsuite/gas/loongarch/li.d
gas/testsuite/gas/loongarch/macro_op.d
gas/testsuite/gas/loongarch/macro_op_32.d
gas/testsuite/gas/loongarch/macro_op_large_abs.d
gas/testsuite/gas/loongarch/macro_op_large_pc.d
gas/testsuite/gas/loongarch/relax_align.d [new file with mode: 0644]
gas/testsuite/gas/loongarch/relax_align.s [new file with mode: 0644]
gas/testsuite/gas/loongarch/uleb128.d [new file with mode: 0644]
gas/testsuite/gas/loongarch/uleb128.s [new file with mode: 0644]