Skip to content

Commit 6b23f4f

Browse files
authored
[LoongArch] Add R_LARCH_MARK_LA relocation for la.abs
Match gas behavior: generate `R_LARCH_MARK_LA` relocation for `la.abs`. Reviewers: heiher, SixWeining Reviewed By: SixWeining, heiher Pull Request: #161062
1 parent a8034d1 commit 6b23f4f

File tree

6 files changed

+19
-1
lines changed

6 files changed

+19
-1
lines changed

llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ class ELFLinkGraphBuilder_loongarch : public ELFLinkGraphBuilder<ELFT> {
365365
uint32_t Type = Rel.getType(false);
366366
int64_t Addend = Rel.r_addend;
367367

368+
// ignore
369+
if (Type == ELF::R_LARCH_MARK_LA)
370+
return Error::success();
371+
368372
if (Type == ELF::R_LARCH_RELAX) {
369373
if (BlockToFix.edges_empty())
370374
return make_error<StringError>(

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,9 @@ void RuntimeDyldELF::resolveLoongArch64Relocation(const SectionEntry &Section,
781781
default:
782782
report_fatal_error("Relocation type not implemented yet!");
783783
break;
784+
case ELF::R_LARCH_MARK_LA:
785+
// ignore
786+
break;
784787
case ELF::R_LARCH_32:
785788
support::ulittle32_t::ref{TargetPtr} =
786789
static_cast<uint32_t>(Value + Addend);

llvm/lib/Target/LoongArch/AsmParser/LoongArchAsmParser.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,10 @@ void LoongArchAsmParser::emitLoadAddressAbs(MCInst &Inst, SMLoc IDLoc,
957957
: Inst.getOperand(2).getExpr();
958958
InstSeq Insts;
959959

960+
// To distinguish between la.abs and %abs_hi20, la.abs will generate
961+
// R_LARCH_MARK_LA and R_LARCH_ABS_HI20 relocations.
960962
Insts.push_back(
961-
LoongArchAsmParser::Inst(LoongArch::LU12I_W, ELF::R_LARCH_ABS_HI20));
963+
LoongArchAsmParser::Inst(LoongArch::LU12I_W, ELF::R_LARCH_MARK_LA));
962964
Insts.push_back(
963965
LoongArchAsmParser::Inst(LoongArch::ORI, ELF::R_LARCH_ABS_LO12));
964966

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCAsmInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static StringRef getLoongArchSpecifierName(uint16_t S) {
3232
return "b16";
3333
case ELF::R_LARCH_B21:
3434
return "b21";
35+
case ELF::R_LARCH_MARK_LA:
3536
case ELF::R_LARCH_ABS_HI20:
3637
return "abs_hi20";
3738
case ELF::R_LARCH_ABS_LO12:

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ LoongArchMCCodeEmitter::getExprOpValue(const MCInst &MI, const MCOperand &MO,
161161
case ELF::R_LARCH_B26:
162162
FixupKind = LoongArch::fixup_loongarch_b26;
163163
break;
164+
case ELF::R_LARCH_MARK_LA:
165+
// Match gas behavior: generate `R_LARCH_MARK_LA` relocation when using
166+
// `la.abs`.
167+
Fixups.push_back(
168+
MCFixup::create(0, MCConstantExpr::create(0, Ctx),
169+
FirstLiteralRelocationKind + ELF::R_LARCH_MARK_LA));
170+
[[fallthrough]];
164171
case ELF::R_LARCH_ABS_HI20:
165172
FixupKind = LoongArch::fixup_loongarch_abs_hi20;
166173
break;

llvm/test/MC/LoongArch/Macros/macros-la.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ la.abs $a0, sym_abs
2626
# ABS-NEXT: lu32i.d $a0, %abs64_lo20(sym_abs)
2727
# ABS-NEXT: lu52i.d $a0, $a0, %abs64_hi12(sym_abs)
2828
# ABS-EMPTY:
29+
# RELOC-NEXT: R_LARCH_MARK_LA - 0x0
2930
# RELOC-NEXT: R_LARCH_ABS_HI20 sym_abs 0x0
3031
# RELOC-NEXT: R_LARCH_ABS_LO12 sym_abs 0x0
3132
# RELOC-NEXT: R_LARCH_ABS64_LO20 sym_abs 0x0

0 commit comments

Comments
 (0)