Skip to content

Commit

Permalink
Apply llvm.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky committed Dec 28, 2021
1 parent fed4134 commit 67f5503
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 6 deletions.
5 changes: 5 additions & 0 deletions llvm/include/llvm/MC/MCObjectStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class MCObjectStreamer : public MCStreamer {
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
void emitValueImpl(const MCExpr *Value, unsigned Size,
SMLoc Loc = SMLoc()) override;
/// \brief EmitValueImpl with additional param, that allows to emit PCRelative
/// MCFixup.
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc,
bool isPCRelative);

void emitULEB128Value(const MCExpr *Value) override;
void emitSLEB128Value(const MCExpr *Value) override;
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
Expand Down
4 changes: 4 additions & 0 deletions llvm/include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class ARMTargetStreamer : public MCTargetStreamer {
virtual void emitPad(int64_t Offset);
virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
bool isVector);
virtual void emitLsda(const MCSymbol *Symbol);
virtual void emitUnwindRaw(int64_t StackOffset,
const SmallVectorImpl<uint8_t> &Opcodes);

Expand Down Expand Up @@ -669,6 +670,9 @@ class MCStreamer {
/// etc.
virtual void emitBytes(StringRef Data);

/// \brief Emit the given \p Instruction data into the current section.
virtual void emitInstructionBytes(StringRef Data);

/// Functionally identical to EmitBytes. When emitting textual assembly, this
/// method uses .byte directives instead of .ascii or .asciz for readability.
virtual void emitBinaryData(StringRef Data);
Expand Down
9 changes: 7 additions & 2 deletions llvm/lib/MC/MCObjectStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void MCObjectStreamer::emitCFISections(bool EH, bool Debug) {
}

void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
SMLoc Loc) {
SMLoc Loc, bool isPCRelative) {
MCStreamer::emitValueImpl(Value, Size, Loc);
MCDataFragment *DF = getOrCreateDataFragment();
flushPendingLabels(DF, DF->getContents().size());
Expand All @@ -243,10 +243,15 @@ void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
}
DF->getFixups().push_back(
MCFixup::create(DF->getContents().size(), Value,
MCFixup::getKindForSize(Size, false), Loc));
MCFixup::getKindForSize(Size, isPCRelative), Loc));
DF->getContents().resize(DF->getContents().size() + Size, 0);
}

void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
SMLoc Loc) {
emitValueImpl(Value, Size, Loc, false);
}

MCSymbol *MCObjectStreamer::emitCFILabel() {
MCSymbol *Label = getContext().createTempSymbol("cfi");
emitLabel(Label);
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/MC/MCStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ void MCStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
void MCStreamer::changeSection(MCSection *, const MCExpr *) {}
void MCStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
void MCStreamer::emitBytes(StringRef Data) {}
void MCStreamer::emitInstructionBytes(StringRef Data) { emitBytes(Data); }
void MCStreamer::emitBinaryData(StringRef Data) { emitBytes(Data); }
void MCStreamer::emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) {
visitUsedExpr(*Value);
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/MC/WinCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,9 @@ void WinCOFFObjectWriter::recordRelocation(MCAssembler &Asm,
if ((Header.Machine == COFF::IMAGE_FILE_MACHINE_AMD64 &&
Reloc.Data.Type == COFF::IMAGE_REL_AMD64_REL32) ||
(Header.Machine == COFF::IMAGE_FILE_MACHINE_I386 &&
Reloc.Data.Type == COFF::IMAGE_REL_I386_REL32))
Reloc.Data.Type == COFF::IMAGE_REL_I386_REL32) ||
(Header.Machine == COFF::IMAGE_FILE_MACHINE_ARM64 &&
Reloc.Data.Type == COFF::IMAGE_REL_ARM64_REL32))
FixedValue += 4;

if (Header.Machine == COFF::IMAGE_FILE_MACHINE_ARMNT) {
Expand Down
11 changes: 9 additions & 2 deletions llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ static unsigned getFixupKindNumBytes(unsigned Kind) {
case AArch64::fixup_aarch64_pcrel_call26:
case FK_Data_4:
case FK_SecRel_4:
case FK_PCRel_4:
return 4;

case FK_Data_8:
Expand Down Expand Up @@ -330,13 +331,19 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target,
case FK_Data_8:
case FK_SecRel_2:
case FK_SecRel_4:
case FK_PCRel_4:
return Value;
}
}

Optional<MCFixupKind> AArch64AsmBackend::getFixupKind(StringRef Name) const {
if (!TheTriple.isOSBinFormatELF())
return None;
if (!TheTriple.isOSBinFormatELF()) {
return StringSwitch<Optional<MCFixupKind>>(Name)
.Case("R_AARCH64_CALL26", (MCFixupKind)AArch64::fixup_aarch64_pcrel_call26)
.Case("R_AARCH64_ADR_PREL_PG_HI21", (MCFixupKind)AArch64::fixup_aarch64_pcrel_adrp_imm21)
.Case("R_AARCH64_ADD_ABS_LO12_NC", (MCFixupKind)AArch64::fixup_aarch64_add_imm12)
.Default(MCAsmBackend::getFixupKind(Name));
}

unsigned Type = llvm::StringSwitch<unsigned>(Name)
#define ELF_RELOC(X, Y) .Case(#X, Y)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
return ELF::R_AARCH64_NONE;
case FK_Data_2:
return R_CLS(PREL16);
case FK_PCRel_4:
case FK_Data_4: {
return Target.getAccessVariant() == MCSymbolRefExpr::VK_PLT
? R_CLS(PLT32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ unsigned AArch64WinCOFFObjectWriter::getRelocType(
case FK_Data_8:
return COFF::IMAGE_REL_ARM64_ADDR64;

case FK_PCRel_4:
return COFF::IMAGE_REL_ARM64_REL32;

case FK_SecRel_2:
return COFF::IMAGE_REL_ARM64_SECTION;

Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
case FK_Data_2:
case FK_Data_4:
return Value;
case FK_PCRel_4:
return Value;
case FK_SecRel_2:
return Value;
case FK_SecRel_4:
Expand Down Expand Up @@ -967,6 +969,9 @@ static unsigned getFixupKindNumBytes(unsigned Kind) {
case ARM::fixup_le:
return 4;

case FK_PCRel_4:
return 4;

case FK_SecRel_2:
return 2;
case FK_SecRel_4:
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
case MCSymbolRefExpr::VK_ARM_PREL31:
return ELF::R_ARM_PREL31;
}
case FK_PCRel_4:
return ELF::R_ARM_REL32;
case ARM::fixup_arm_blx:
case ARM::fixup_arm_uncondbl:
switch (Modifier) {
Expand Down
37 changes: 36 additions & 1 deletion llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class ARMTargetAsmStreamer : public ARMTargetStreamer {
void emitPad(int64_t Offset) override;
void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
bool isVector) override;
void emitLsda(const MCSymbol* Symbol) override;
void emitUnwindRaw(int64_t Offset,
const SmallVectorImpl<uint8_t> &Opcodes) override;

Expand Down Expand Up @@ -272,6 +273,8 @@ void ARMTargetAsmStreamer::emitUnwindRaw(int64_t Offset,
OS << '\n';
}

void ARMTargetAsmStreamer::emitLsda(const MCSymbol* Symbol) {}

class ARMTargetELFStreamer : public ARMTargetStreamer {
private:
// This structure holds all attributes, accounting for
Expand Down Expand Up @@ -388,6 +391,7 @@ class ARMTargetELFStreamer : public ARMTargetStreamer {
void emitPad(int64_t Offset) override;
void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
bool isVector) override;
void emitLsda(const MCSymbol *Symbol) override;
void emitUnwindRaw(int64_t Offset,
const SmallVectorImpl<uint8_t> &Opcodes) override;

Expand Down Expand Up @@ -457,6 +461,7 @@ class ARMELFStreamer : public MCELFStreamer {
void emitMovSP(unsigned Reg, int64_t Offset = 0);
void emitPad(int64_t Offset);
void emitRegSave(const SmallVectorImpl<unsigned> &RegList, bool isVector);
void emitLsda(const MCSymbol* Symbol);
void emitUnwindRaw(int64_t Offset, const SmallVectorImpl<uint8_t> &Opcodes);
void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
SMLoc Loc) override {
Expand Down Expand Up @@ -536,6 +541,18 @@ class ARMELFStreamer : public MCELFStreamer {
MCELFStreamer::emitBytes(Data);
}

/// This function is the one used to emit instruction data into the ELF
/// streamer. We override it to add the appropriate mapping symbol if
/// necessary.
void emitInstructionBytes(StringRef Data) override {
if (IsThumb)
EmitThumbMappingSymbol();
else
EmitARMMappingSymbol();

MCELFStreamer::emitBytes(Data);
}

void FlushPendingMappingSymbol() {
if (!LastEMSInfo->hasInfo())
return;
Expand Down Expand Up @@ -699,6 +716,7 @@ class ARMELFStreamer : public MCELFStreamer {
bool CantUnwind;
SmallVector<uint8_t, 64> Opcodes;
UnwindOpcodeAssembler UnwindOpAsm;
const MCSymbol *Lsda;
};

} // end anonymous namespace
Expand Down Expand Up @@ -741,6 +759,10 @@ void ARMTargetELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
getStreamer().emitRegSave(RegList, isVector);
}

void ARMTargetELFStreamer::emitLsda(const MCSymbol *Symbol) {
getStreamer().emitLsda(Symbol);
}

void ARMTargetELFStreamer::emitUnwindRaw(int64_t Offset,
const SmallVectorImpl<uint8_t> &Opcodes) {
getStreamer().emitUnwindRaw(Offset, Opcodes);
Expand Down Expand Up @@ -1241,6 +1263,7 @@ void ARMELFStreamer::EHReset() {
PendingOffset = 0;
UsedFP = false;
CantUnwind = false;
Lsda = nullptr;

Opcodes.clear();
UnwindOpAsm.Reset();
Expand Down Expand Up @@ -1343,6 +1366,8 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) {
}

// Finalize the unwind opcode sequence
if (Lsda != nullptr && Opcodes.size() <= 4u)
PersonalityIndex = ARM::EHABI::AEABI_UNWIND_CPP_PR1;
UnwindOpAsm.Finalize(PersonalityIndex, Opcodes);

// For compact model 0, we have to emit the unwind opcodes in the .ARM.exidx
Expand Down Expand Up @@ -1387,7 +1412,13 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) {
//
// In case that the .handlerdata directive is not specified by the
// programmer, we should emit zero to terminate the handler data.
if (NoHandlerData && !Personality)
if (Lsda != nullptr) {
const MCSymbolRefExpr *LsdaRef =
MCSymbolRefExpr::create(Lsda,
MCSymbolRefExpr::VK_None,
getContext());
emitValue(LsdaRef, 4);
} else if (NoHandlerData && !Personality)
emitInt32(0);
}

Expand Down Expand Up @@ -1470,6 +1501,10 @@ void ARMELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
UnwindOpAsm.EmitRegSave(Mask);
}

void ARMELFStreamer::emitLsda(const MCSymbol *Symbol) {
Lsda = Symbol;
}

void ARMELFStreamer::emitUnwindRaw(int64_t Offset,
const SmallVectorImpl<uint8_t> &Opcodes) {
FlushPendingOffset();
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void ARMTargetStreamer::emitMovSP(unsigned Reg, int64_t Offset) {}
void ARMTargetStreamer::emitPad(int64_t Offset) {}
void ARMTargetStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
bool isVector) {}
void ARMTargetStreamer::emitLsda(const MCSymbol *Symbol) {}
void ARMTargetStreamer::emitUnwindRaw(int64_t StackOffset,
const SmallVectorImpl<uint8_t> &Opcodes) {
}
Expand Down

0 comments on commit 67f5503

Please sign in to comment.