[LoongArch] Insert nops and emit align reloc when handle alignment directive (#72962)
commitc51ab483e6c2d991a01179584705b83fbea1940d
authorJinyang He <hejinyang@loongson.cn>
Wed, 24 Jan 2024 01:17:49 +0000 (24 09:17 +0800)
committerGitHub <noreply@github.com>
Wed, 24 Jan 2024 01:17:49 +0000 (24 09:17 +0800)
tree5abd1d5ffabdc9842e776243715ebab449eca637
parentc41472dbafd0dcacd943a95a9a099c1942d50394
[LoongArch] Insert nops and emit align reloc when handle alignment directive (#72962)

Refer to RISCV, we will fix up the alignment if linker relaxation
changes code size and breaks alignment. Insert enough Nops and emit
R_LARCH_ALIGN relocation type so that linker could satisfy the alignment
by removing Nops.
It does so only in sections with the SHF_EXECINSTR flag.

In LoongArch psABI v2.30, R_LARCH_ALIGN requires symbol index. The
lowest 8 bits of addend represent alignment and the other bits of addend
represent the maximum number of bytes to emit.
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchFixupKinds.h
llvm/test/MC/LoongArch/Relocations/align-non-executable.s [new file with mode: 0644]
llvm/test/MC/LoongArch/Relocations/relax-addsub.s
llvm/test/MC/LoongArch/Relocations/relax-align.s [new file with mode: 0644]