Skip to content

Commit abaa55d

Browse files
committed
COFF: 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 970ed59 commit abaa55d

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,18 @@ unsigned AArch64WinCOFFObjectWriter::getRelocType(
4949
MCContext &Ctx, const MCValue &Target, const MCFixup &Fixup,
5050
bool IsCrossSection, const MCAsmBackend &MAB) const {
5151
unsigned FixupKind = Fixup.getKind();
52+
bool PCRel = Fixup.isPCRel();
5253
if (IsCrossSection) {
5354
// IMAGE_REL_ARM64_REL64 does not exist. We treat FK_Data_8 as FK_PCRel_4 so
5455
// that .xword a-b can lower to IMAGE_REL_ARM64_REL32. This allows generic
5556
// instrumentation to not bother with the COFF limitation. A negative value
5657
// needs attention.
57-
if (FixupKind != FK_Data_4 && FixupKind != FK_Data_8) {
58+
if (PCRel || (FixupKind != FK_Data_4 && FixupKind != FK_Data_8)) {
5859
Ctx.reportError(Fixup.getLoc(), "Cannot represent this expression");
5960
return COFF::IMAGE_REL_ARM64_ADDR32;
6061
}
61-
FixupKind = FK_PCRel_4;
62+
FixupKind = FK_Data_4;
63+
PCRel = true;
6264
}
6365

6466
auto Spec = Target.getSpecifier();
@@ -93,10 +95,9 @@ unsigned AArch64WinCOFFObjectWriter::getRelocType(
9395
return COFF::IMAGE_REL_ARM64_ABSOLUTE; // Dummy return value
9496
}
9597

96-
case FK_PCRel_4:
97-
return COFF::IMAGE_REL_ARM64_REL32;
98-
9998
case FK_Data_4:
99+
if (PCRel)
100+
return COFF::IMAGE_REL_ARM64_REL32;
100101
switch (Spec) {
101102
default:
102103
return COFF::IMAGE_REL_ARM64_ADDR32;

llvm/lib/Target/ARM/MCTargetDesc/ARMWinCOFFObjectWriter.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ unsigned ARMWinCOFFObjectWriter::getRelocType(MCContext &Ctx,
4747
const MCAsmBackend &MAB) const {
4848
auto Spec = Target.getSpecifier();
4949
unsigned FixupKind = Fixup.getKind();
50+
bool PCRel = false;
5051
if (IsCrossSection) {
51-
if (FixupKind != FK_Data_4) {
52+
if (PCRel || FixupKind != FK_Data_4) {
5253
Ctx.reportError(Fixup.getLoc(), "Cannot represent this expression");
5354
return COFF::IMAGE_REL_ARM_ADDR32;
5455
}
55-
FixupKind = FK_PCRel_4;
56+
FixupKind = FK_Data_4;
57+
PCRel = true;
5658
}
5759

5860

@@ -62,6 +64,8 @@ unsigned ARMWinCOFFObjectWriter::getRelocType(MCContext &Ctx,
6264
return COFF::IMAGE_REL_ARM_ABSOLUTE;
6365
}
6466
case FK_Data_4:
67+
if (PCRel)
68+
return COFF::IMAGE_REL_ARM_REL32;
6569
switch (Spec) {
6670
case MCSymbolRefExpr::VK_COFF_IMGREL32:
6771
return COFF::IMAGE_REL_ARM_ADDR32NB;
@@ -70,8 +74,6 @@ unsigned ARMWinCOFFObjectWriter::getRelocType(MCContext &Ctx,
7074
default:
7175
return COFF::IMAGE_REL_ARM_ADDR32;
7276
}
73-
case FK_PCRel_4:
74-
return COFF::IMAGE_REL_ARM_REL32;
7577
case FK_SecRel_2:
7678
return COFF::IMAGE_REL_ARM_SECTION;
7779
case FK_SecRel_4:

0 commit comments

Comments
 (0)