Skip to content

Commit 6bf6729

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.5-bogner
1 parent 491c7bd commit 6bf6729

File tree

31 files changed

+125
-169
lines changed

31 files changed

+125
-169
lines changed

llvm/include/llvm/MC/MCAsmBackend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class LLVM_ABI MCAsmBackend {
123123
/// appropriate. Errors (such as an out of range fixup value) should be
124124
/// reported via \p Ctx.
125125
virtual void applyFixup(const MCFragment &, const MCFixup &,
126-
const MCValue &Target, MutableArrayRef<char> Data,
127-
uint64_t Value, bool IsResolved) = 0;
126+
const MCValue &Target, char *Data, uint64_t Value,
127+
bool IsResolved) = 0;
128128

129129
/// @}
130130

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ class MCAssembler {
9999
/// \param RecordReloc Record relocation if needed.
100100
/// relocation.
101101
bool evaluateFixup(const MCFragment &F, MCFixup &Fixup, MCValue &Target,
102-
uint64_t &Value, bool RecordReloc,
103-
MutableArrayRef<char> Contents) const;
102+
uint64_t &Value, bool RecordReloc, char *Data) const;
104103

105104
/// Check whether a fixup can be satisfied, or whether it needs to be relaxed
106105
/// (increased in size, in order to hold its value correctly).

llvm/lib/MC/MCAssembler.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
140140

141141
bool MCAssembler::evaluateFixup(const MCFragment &F, MCFixup &Fixup,
142142
MCValue &Target, uint64_t &Value,
143-
bool RecordReloc,
144-
MutableArrayRef<char> Contents) const {
143+
bool RecordReloc, char *Data) const {
145144
++stats::evaluateFixup;
146145

147146
// FIXME: This code has some duplication with recordRelocation. We should
@@ -185,7 +184,7 @@ bool MCAssembler::evaluateFixup(const MCFragment &F, MCFixup &Fixup,
185184

186185
if (IsResolved && mc::isRelocRelocation(Fixup.getKind()))
187186
IsResolved = false;
188-
getBackend().applyFixup(F, Fixup, Target, Contents, Value, IsResolved);
187+
getBackend().applyFixup(F, Fixup, Target, Data, Value, IsResolved);
189188
return true;
190189
}
191190

@@ -703,21 +702,24 @@ void MCAssembler::layout() {
703702
for (MCFixup &Fixup : F.getFixups()) {
704703
uint64_t FixedValue;
705704
MCValue Target;
705+
assert(mc::isRelocRelocation(Fixup.getKind()) ||
706+
Fixup.getOffset() <= F.getFixedSize());
706707
evaluateFixup(F, Fixup, Target, FixedValue,
707-
/*RecordReloc=*/true, Contents);
708+
/*RecordReloc=*/true,
709+
Contents.data() + Fixup.getOffset());
708710
}
709-
if (F.getVarFixups().size()) {
710-
// In the variable part, fixup offsets are relative to the fixed part's
711-
// start. Extend the variable contents to the left to account for the
712-
// fixed part size.
713-
Contents = MutableArrayRef(F.getParent()->ContentStorage)
714-
.slice(F.VarContentStart - Contents.size(), F.getSize());
715-
for (MCFixup &Fixup : F.getVarFixups()) {
716-
uint64_t FixedValue;
717-
MCValue Target;
718-
evaluateFixup(F, Fixup, Target, FixedValue,
719-
/*RecordReloc=*/true, Contents);
720-
}
711+
// In the variable part, fixup offsets are relative to the fixed part's
712+
// start.
713+
for (MCFixup &Fixup : F.getVarFixups()) {
714+
uint64_t FixedValue;
715+
MCValue Target;
716+
assert(mc::isRelocRelocation(Fixup.getKind()) ||
717+
(Fixup.getOffset() >= F.getFixedSize() &&
718+
Fixup.getOffset() <= F.getSize()));
719+
char *Data =
720+
F.getVarContents().data() + (Fixup.getOffset() - F.getFixedSize());
721+
evaluateFixup(F, Fixup, Target, FixedValue,
722+
/*RecordReloc=*/true, Data);
721723
}
722724
}
723725
}

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ class AArch64AsmBackend : public MCAsmBackend {
7979
}
8080

8181
void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target,
82-
MutableArrayRef<char> Data, uint64_t Value,
83-
bool IsResolved) override;
82+
char *Data, uint64_t Value, bool IsResolved) override;
8483

8584
bool fixupNeedsRelaxation(const MCFixup &Fixup,
8685
uint64_t Value) const override;
@@ -421,9 +420,8 @@ static bool shouldForceRelocation(const MCFixup &Fixup) {
421420
}
422421

423422
void AArch64AsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
424-
const MCValue &Target,
425-
MutableArrayRef<char> Data, uint64_t Value,
426-
bool IsResolved) {
423+
const MCValue &Target, char *Data,
424+
uint64_t Value, bool IsResolved) {
427425
if (shouldForceRelocation(Fixup))
428426
IsResolved = false;
429427
maybeAddReloc(F, Fixup, Target, Value, IsResolved);
@@ -471,15 +469,15 @@ void AArch64AsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
471469
if (FulleSizeInBytes == 0) {
472470
// Handle as little-endian
473471
for (unsigned i = 0; i != NumBytes; ++i) {
474-
Data[Offset + i] |= uint8_t((Value >> (i * 8)) & 0xff);
472+
Data[i] |= uint8_t((Value >> (i * 8)) & 0xff);
475473
}
476474
} else {
477475
// Handle as big-endian
478-
assert((Offset + FulleSizeInBytes) <= Data.size() && "Invalid fixup size!");
476+
assert(Offset + FulleSizeInBytes <= F.getSize() && "Invalid fixup size!");
479477
assert(NumBytes <= FulleSizeInBytes && "Invalid fixup size!");
480478
for (unsigned i = 0; i != NumBytes; ++i) {
481479
unsigned Idx = FulleSizeInBytes - 1 - i;
482-
Data[Offset + Idx] |= uint8_t((Value >> (i * 8)) & 0xff);
480+
Data[Idx] |= uint8_t((Value >> (i * 8)) & 0xff);
483481
}
484482
}
485483

@@ -492,9 +490,9 @@ void AArch64AsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
492490
// If the immediate is negative, generate MOVN else MOVZ.
493491
// (Bit 30 = 0) ==> MOVN, (Bit 30 = 1) ==> MOVZ.
494492
if (SignedValue < 0)
495-
Data[Offset + 3] &= ~(1 << 6);
493+
Data[3] &= ~(1 << 6);
496494
else
497-
Data[Offset + 3] |= (1 << 6);
495+
Data[3] |= (1 << 6);
498496
}
499497
}
500498

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class AMDGPUAsmBackend : public MCAsmBackend {
3333
AMDGPUAsmBackend(const Target &T) : MCAsmBackend(llvm::endianness::little) {}
3434

3535
void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target,
36-
MutableArrayRef<char> Data, uint64_t Value,
37-
bool IsResolved) override;
36+
char *Data, uint64_t Value, bool IsResolved) override;
3837
bool fixupNeedsRelaxation(const MCFixup &Fixup,
3938
uint64_t Value) const override;
4039

@@ -129,9 +128,8 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
129128
}
130129

131130
void AMDGPUAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
132-
const MCValue &Target,
133-
MutableArrayRef<char> Data, uint64_t Value,
134-
bool IsResolved) {
131+
const MCValue &Target, char *Data,
132+
uint64_t Value, bool IsResolved) {
135133
if (Target.getSpecifier())
136134
IsResolved = false;
137135
maybeAddReloc(F, Fixup, Target, Value, IsResolved);
@@ -154,7 +152,7 @@ void AMDGPUAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
154152
// For each byte of the fragment that the fixup touches, mask in the bits from
155153
// the fixup value.
156154
for (unsigned i = 0; i != NumBytes; ++i)
157-
Data[Offset + i] |= static_cast<uint8_t>((Value >> (i * 8)) & 0xff);
155+
Data[i] |= static_cast<uint8_t>((Value >> (i * 8)) & 0xff);
158156
}
159157

160158
std::optional<MCFixupKind>

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,9 +1108,8 @@ std::optional<bool> ARMAsmBackend::evaluateFixup(const MCFragment &F,
11081108
}
11091109

11101110
void ARMAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
1111-
const MCValue &Target,
1112-
MutableArrayRef<char> Data, uint64_t Value,
1113-
bool IsResolved) {
1111+
const MCValue &Target, char *Data,
1112+
uint64_t Value, bool IsResolved) {
11141113
if (IsResolved && shouldForceRelocation(Fixup, Target))
11151114
IsResolved = false;
11161115
maybeAddReloc(F, Fixup, Target, Value, IsResolved);
@@ -1131,7 +1130,7 @@ void ARMAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
11311130
unsigned FullSizeBytes;
11321131
if (Endian == llvm::endianness::big) {
11331132
FullSizeBytes = getFixupKindContainerSizeBytes(Kind);
1134-
assert((Offset + FullSizeBytes) <= Data.size() && "Invalid fixup size!");
1133+
assert((Offset + FullSizeBytes) <= F.getSize() && "Invalid fixup size!");
11351134
assert(NumBytes <= FullSizeBytes && "Invalid fixup size!");
11361135
}
11371136

@@ -1141,7 +1140,7 @@ void ARMAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
11411140
for (unsigned i = 0; i != NumBytes; ++i) {
11421141
unsigned Idx =
11431142
Endian == llvm::endianness::little ? i : (FullSizeBytes - 1 - i);
1144-
Data[Offset + Idx] |= uint8_t((Value >> (i * 8)) & 0xff);
1143+
Data[Idx] |= uint8_t((Value >> (i * 8)) & 0xff);
11451144
}
11461145
}
11471146

llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class ARMAsmBackend : public MCAsmBackend {
4040
std::optional<bool> evaluateFixup(const MCFragment &, MCFixup &, MCValue &,
4141
uint64_t &) override;
4242
void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target,
43-
MutableArrayRef<char> Data, uint64_t Value,
44-
bool IsResolved) override;
43+
char *Data, uint64_t Value, bool IsResolved) override;
4544

4645
unsigned getRelaxedOpcode(unsigned Op, const MCSubtargetInfo &STI) const;
4746

llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,8 @@ AVRAsmBackend::createObjectTargetWriter() const {
368368
}
369369

370370
void AVRAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
371-
const MCValue &Target,
372-
MutableArrayRef<char> Data, uint64_t Value,
373-
bool IsResolved) {
371+
const MCValue &Target, char *Data,
372+
uint64_t Value, bool IsResolved) {
374373
// AVR sets the fixup value to bypass the assembly time overflow with a
375374
// relocation.
376375
if (IsResolved) {
@@ -404,7 +403,7 @@ void AVRAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
404403
// bits from the fixup value.
405404
for (unsigned i = 0; i < NumBytes; ++i) {
406405
uint8_t mask = (((Value >> (i * 8)) & 0xff));
407-
Data[Offset + i] |= mask;
406+
Data[i] |= mask;
408407
}
409408
}
410409

llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class AVRAsmBackend : public MCAsmBackend {
3838
createObjectTargetWriter() const override;
3939

4040
void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target,
41-
MutableArrayRef<char> Data, uint64_t Value,
42-
bool IsResolved) override;
41+
char *Data, uint64_t Value, bool IsResolved) override;
4342

4443
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
4544
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;

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

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ class BPFAsmBackend : public MCAsmBackend {
2727
~BPFAsmBackend() override = default;
2828

2929
void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target,
30-
MutableArrayRef<char> Data, uint64_t Value,
31-
bool IsResolved) override;
30+
char *Data, uint64_t Value, bool IsResolved) override;
3231

3332
std::unique_ptr<MCObjectTargetWriter>
3433
createObjectTargetWriter() const override;
@@ -66,35 +65,32 @@ bool BPFAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
6665
}
6766

6867
void BPFAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
69-
const MCValue &Target,
70-
MutableArrayRef<char> Data, uint64_t Value,
71-
bool IsResolved) {
68+
const MCValue &Target, char *Data,
69+
uint64_t Value, bool IsResolved) {
7270
maybeAddReloc(F, Fixup, Target, Value, IsResolved);
7371
if (Fixup.getKind() == FK_SecRel_8) {
7472
// The Value is 0 for global variables, and the in-section offset
7573
// for static variables. Write to the immediate field of the inst.
7674
assert(Value <= UINT32_MAX);
77-
support::endian::write<uint32_t>(&Data[Fixup.getOffset() + 4],
78-
static_cast<uint32_t>(Value),
75+
support::endian::write<uint32_t>(Data + 4, static_cast<uint32_t>(Value),
7976
Endian);
8077
} else if (Fixup.getKind() == FK_Data_4 && !Fixup.isPCRel()) {
81-
support::endian::write<uint32_t>(&Data[Fixup.getOffset()], Value, Endian);
78+
support::endian::write<uint32_t>(Data, Value, Endian);
8279
} else if (Fixup.getKind() == FK_Data_8) {
83-
support::endian::write<uint64_t>(&Data[Fixup.getOffset()], Value, Endian);
80+
support::endian::write<uint64_t>(Data, Value, Endian);
8481
} else if (Fixup.getKind() == FK_Data_4 && Fixup.isPCRel()) {
8582
Value = (uint32_t)((Value - 8) / 8);
8683
if (Endian == llvm::endianness::little) {
87-
Data[Fixup.getOffset() + 1] = 0x10;
88-
support::endian::write32le(&Data[Fixup.getOffset() + 4], Value);
84+
Data[1] = 0x10;
85+
support::endian::write32le(Data + 4, Value);
8986
} else {
90-
Data[Fixup.getOffset() + 1] = 0x1;
91-
support::endian::write32be(&Data[Fixup.getOffset() + 4], Value);
87+
Data[1] = 0x1;
88+
support::endian::write32be(Data + 4, Value);
9289
}
9390
} else if (Fixup.getKind() == BPF::FK_BPF_PCRel_4) {
9491
// The input Value represents the number of bytes.
9592
Value = (uint32_t)((Value - 8) / 8);
96-
support::endian::write<uint32_t>(&Data[Fixup.getOffset() + 4], Value,
97-
Endian);
93+
support::endian::write<uint32_t>(Data + 4, Value, Endian);
9894
} else {
9995
assert(Fixup.getKind() == FK_Data_2 && Fixup.isPCRel());
10096

@@ -103,8 +99,7 @@ void BPFAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,
10399
report_fatal_error("Branch target out of insn range");
104100

105101
Value = (uint16_t)((Value - 8) / 8);
106-
support::endian::write<uint16_t>(&Data[Fixup.getOffset() + 2], Value,
107-
Endian);
102+
support::endian::write<uint16_t>(Data + 2, Value, Endian);
108103
}
109104
}
110105

0 commit comments

Comments
 (0)