Skip to content

Commit a26f8f2

Browse files
committed
BPF: Replace deprecated FK_PCRel_ with FK_Data_ fixup and PCRel flag
We will unify the generic fixup kinds FK_Data_ and FK_PCRel_. A FK_PCRel_ kind is essentially the corresponding FK_Data_ fixup with the PCRel flag set.
1 parent 66952f7 commit a26f8f2

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ void BPFAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
7878
support::endian::write<uint32_t>(&Data[Fixup.getOffset() + 4],
7979
static_cast<uint32_t>(Value),
8080
Endian);
81-
} else if (Fixup.getKind() == FK_Data_4) {
81+
} else if (Fixup.getKind() == FK_Data_4 && !Fixup.isPCRel()) {
8282
support::endian::write<uint32_t>(&Data[Fixup.getOffset()], Value, Endian);
8383
} else if (Fixup.getKind() == FK_Data_8) {
8484
support::endian::write<uint64_t>(&Data[Fixup.getOffset()], Value, Endian);
85-
} else if (Fixup.getKind() == FK_PCRel_4) {
85+
} else if (Fixup.getKind() == FK_Data_4 && Fixup.isPCRel()) {
8686
Value = (uint32_t)((Value - 8) / 8);
8787
if (Endian == llvm::endianness::little) {
8888
Data[Fixup.getOffset() + 1] = 0x10;
@@ -97,7 +97,7 @@ void BPFAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
9797
support::endian::write<uint32_t>(&Data[Fixup.getOffset() + 4], Value,
9898
Endian);
9999
} else {
100-
assert(Fixup.getKind() == FK_PCRel_2);
100+
assert(Fixup.getKind() == FK_Data_2 && Fixup.isPCRel());
101101

102102
int64_t ByteOff = (int64_t)Value - 8;
103103
if (ByteOff > INT16_MAX * 8 || ByteOff < INT16_MIN * 8)

llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ unsigned BPFELFObjectWriter::getRelocType(const MCFixup &Fixup,
4545
case FK_SecRel_8:
4646
// LD_imm64 instruction.
4747
return ELF::R_BPF_64_64;
48-
case FK_PCRel_4:
49-
// CALL instruction.
50-
return ELF::R_BPF_64_32;
5148
case FK_Data_8:
5249
return ELF::R_BPF_64_ABS64;
5350
case FK_Data_4:
51+
if (Fixup.isPCRel()) // CALL instruction
52+
return ELF::R_BPF_64_32;
5453
if (const auto *A = Target.getAddSym()) {
5554
const MCSymbol &Sym = *A;
5655

llvm/lib/Target/BPF/MCTargetDesc/BPFMCCodeEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ unsigned BPFMCCodeEmitter::getMachineOpValue(const MCInst &MI,
107107

108108
if (MI.getOpcode() == BPF::JAL)
109109
// func call name
110-
addFixup(Fixups, 0, Expr, FK_PCRel_4, true);
110+
addFixup(Fixups, 0, Expr, FK_Data_4, true);
111111
else if (MI.getOpcode() == BPF::LD_imm64)
112112
addFixup(Fixups, 0, Expr, FK_SecRel_8);
113113
else if (MI.getOpcode() == BPF::JMPL)
114114
addFixup(Fixups, 0, Expr, BPF::FK_BPF_PCRel_4, true);
115115
else
116116
// bb label
117-
addFixup(Fixups, 0, Expr, FK_PCRel_2, true);
117+
addFixup(Fixups, 0, Expr, FK_Data_2, true);
118118

119119
return 0;
120120
}

0 commit comments

Comments
 (0)