Skip to content

Commit 6f0a35f

Browse files
committed
[AArch64] Use FirsRelocationKind+i fixup kinds to force relocations
For RELA targets, fixup kinds that force relocations (GOT, TLS, ALIGN, RELAX, etc) can bypass `applyFixup` and be encoded as `FirstRelocationKind+i`, as seen in LoongArch.
1 parent 2721f5a commit 6f0a35f

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

llvm/include/llvm/MC/MCFixup.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class MCFixup {
8989
FI.Loc = Loc;
9090
return FI;
9191
}
92+
static MCFixup create(uint32_t Offset, const MCExpr *Value, unsigned Kind,
93+
SMLoc Loc = SMLoc()) {
94+
return create(Offset, Value, MCFixupKind(Kind), Loc);
95+
}
9296

9397
MCFixupKind getKind() const { return Kind; }
9498

llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ class AArch64AsmBackend : public MCAsmBackend {
6767
{"fixup_aarch64_pcrel_branch26", 0, 26, PCRelFlagVal},
6868
{"fixup_aarch64_pcrel_call26", 0, 26, PCRelFlagVal}};
6969

70-
// Fixup kinds from .reloc directive are like R_AARCH64_NONE. They do not
71-
// require any extra processing.
72-
if (Kind >= FirstLiteralRelocationKind)
70+
// Fixup kinds from raw relocation types and .reloc directives force
71+
// relocations and do not need these fields.
72+
if (Kind >= FirstRelocationKind)
7373
return MCAsmBackend::getFixupKindInfo(FK_NONE);
7474

7575
if (Kind < FirstTargetFixupKind)
@@ -442,7 +442,7 @@ void AArch64AsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
442442
if (!Value)
443443
return; // Doesn't change encoding.
444444
unsigned Kind = Fixup.getKind();
445-
if (Kind >= FirstLiteralRelocationKind)
445+
if (Kind >= FirstRelocationKind)
446446
return;
447447
unsigned NumBytes = getFixupKindNumBytes(Kind);
448448
MCFixupKindInfo Info = getFixupKindInfo(Fixup.getKind());

llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
127127
break;
128128
}
129129

130+
// Extract the relocation type from the fixup kind, after applying STT_TLS as
131+
// needed.
132+
if (Kind >= FirstRelocationKind)
133+
return Kind - FirstRelocationKind;
134+
130135
if (IsPCRel) {
131136
switch (Kind) {
132137
case FK_Data_1:

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,8 @@ void AArch64MCCodeEmitter::encodeInstruction(const MCInst &MI,
749749
auto Reloc = STI.getTargetTriple().getEnvironment() == Triple::GNUILP32
750750
? ELF::R_AARCH64_P32_TLSDESC_CALL
751751
: ELF::R_AARCH64_TLSDESC_CALL;
752-
Fixups.push_back(
753-
MCFixup::create(0, MI.getOperand(0).getExpr(),
754-
MCFixupKind(FirstLiteralRelocationKind + Reloc)));
752+
Fixups.push_back(MCFixup::create(0, MI.getOperand(0).getExpr(),
753+
FirstRelocationKind + Reloc));
755754
return;
756755
}
757756

0 commit comments

Comments
 (0)