37 auto describeBranch = [&]() -> std::string {
40 Desc += (
Twine(
" to '") + Sym->getName() +
"'").str();
47 auto checkBrFixup = [&](
unsigned Bits) {
48 int64_t SVal = int64_t(
Value);
49 if ((
Value & 3) != 0) {
50 Ctx.reportError(Fixup.getLoc(),
"branch target not a multiple of four (" +
51 Twine(SVal) +
")" + describeBranch());
57 Ctx.reportError(Fixup.getLoc(),
58 "branch target out of range (" +
Twine(SVal) +
76 return Value & 0xfffc;
81 return Value & 0x3fffffc;
83 return Value & 0xffff;
86 return Value & 0xfffc;
89 return Value & 0xffffffff;
92 return Value & 0x3ffffffff;
131 PPCAsmBackend(
const Target &
T,
const Triple &TT)
136 MCFixupKindInfo getFixupKindInfo(
MCFixupKind Kind)
const override;
138 void applyFixup(
const MCFragment &,
const MCFixup &Fixup,
140 bool IsResolved)
override;
145 if (
Target.getSpecifier())
148 switch ((
unsigned)Kind) {
157 if (
const auto *
A =
Target.getAddSym()) {
162 unsigned Other =
static_cast<const MCSymbolELF *
>(
A)->getOther() << 2;
166 auto *S =
static_cast<const MCSymbolXCOFF *
>(
A);
167 return !
Target.isAbsolute() && S->isExternal() &&
176 const MCSubtargetInfo *STI)
const override {
178 for (
uint64_t i = 0; i != NumNops; ++i)
192 {
"fixup_ppc_br24", 6, 24, 0},
193 {
"fixup_ppc_br24_notoc", 6, 24, 0},
194 {
"fixup_ppc_brcond14", 16, 14, 0},
195 {
"fixup_ppc_br24abs", 6, 24, 0},
196 {
"fixup_ppc_brcond14abs", 16, 14, 0},
197 {
"fixup_ppc_half16", 0, 16, 0},
198 {
"fixup_ppc_half16ds", 0, 14, 0},
199 {
"fixup_ppc_pcrel32", 0, 32, 0},
200 {
"fixup_ppc_imm32", 0, 32, 0},
201 {
"fixup_ppc_pcrel34", 0, 34, 0},
202 {
"fixup_ppc_imm34", 0, 34, 0},
203 {
"fixup_ppc_nofixup", 0, 0, 0}};
206 {
"fixup_ppc_br24", 2, 24, 0},
207 {
"fixup_ppc_br24_notoc", 2, 24, 0},
208 {
"fixup_ppc_brcond14", 2, 14, 0},
209 {
"fixup_ppc_br24abs", 2, 24, 0},
210 {
"fixup_ppc_brcond14abs", 2, 14, 0},
211 {
"fixup_ppc_half16", 0, 16, 0},
212 {
"fixup_ppc_half16ds", 2, 14, 0},
213 {
"fixup_ppc_pcrel32", 0, 32, 0},
214 {
"fixup_ppc_imm32", 0, 32, 0},
215 {
"fixup_ppc_pcrel34", 0, 34, 0},
216 {
"fixup_ppc_imm34", 0, 34, 0},
217 {
"fixup_ppc_nofixup", 0, 0, 0}};
235void PPCAsmBackend::applyFixup(
const MCFragment &
F,
const MCFixup &Fixup,
236 const MCValue &TargetVal, uint8_t *
Data,
242 Target.setAddSym(
nullptr);
246 Asm->getWriter().recordRelocation(
F, Fixup, Target,
Value);
251 const MCSection *Sec =
F.getParent();
253 Sec ? Sec->
getName() : StringRef(),
254 Asm->getFragmentOffset(
F) +
Fixup.getOffset());
263 for (
unsigned i = 0; i != NumBytes; ++i) {
265 Data[i] |= uint8_t((
Value >> (Idx * 8)) & 0xff);
272class ELFPPCAsmBackend :
public PPCAsmBackend {
274 ELFPPCAsmBackend(
const Target &
T,
const Triple &TT) : PPCAsmBackend(
T,
TT) {}
276 std::unique_ptr<MCObjectTargetWriter>
277 createObjectTargetWriter()
const override {
279 bool Is64 =
TT.isPPC64();
283 std::optional<MCFixupKind>
getFixupKind(StringRef Name)
const override;
286class XCOFFPPCAsmBackend :
public PPCAsmBackend {
288 XCOFFPPCAsmBackend(
const Target &
T,
const Triple &TT)
289 : PPCAsmBackend(
T,
TT) {}
291 std::unique_ptr<MCObjectTargetWriter>
292 createObjectTargetWriter()
const override {
299std::optional<MCFixupKind>
300ELFPPCAsmBackend::getFixupKind(StringRef Name)
const {
301 if (
TT.isOSBinFormatELF()) {
304 Type = llvm::StringSwitch<unsigned>(Name)
305#define ELF_RELOC(X, Y) .Case(#X, Y)
306#include "llvm/BinaryFormat/ELFRelocs/PowerPC64.def"
308 .Case(
"BFD_RELOC_NONE", ELF::R_PPC64_NONE)
309 .Case(
"BFD_RELOC_16", ELF::R_PPC64_ADDR16)
310 .Case(
"BFD_RELOC_32", ELF::R_PPC64_ADDR32)
311 .Case(
"BFD_RELOC_64", ELF::R_PPC64_ADDR64)
314 Type = llvm::StringSwitch<unsigned>(Name)
315#define ELF_RELOC(X, Y) .Case(#X, Y)
316#include "llvm/BinaryFormat/ELFRelocs/PowerPC.def"
318 .Case(
"BFD_RELOC_NONE", ELF::R_PPC_NONE)
319 .Case(
"BFD_RELOC_16", ELF::R_PPC_ADDR16)
320 .Case(
"BFD_RELOC_32", ELF::R_PPC_ADDR32)
334 if (TT.isOSBinFormatXCOFF())
335 return new XCOFFPPCAsmBackend(
T, TT);
337 return new ELFPPCAsmBackend(
T, TT);
static unsigned getFixupKindNumBytes(unsigned Kind)
The number of bytes the fixup may change.
static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target, uint64_t Value, MCContext &Ctx, const Triple &TheTriple, bool IsResolved)
static bool shouldForceRelocation(const MCFixup &Fixup)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static unsigned getFixupKindNumBytes(unsigned Kind)
static uint64_t adjustFixupValue(MCContext &Ctx, const MCFixup &Fixup, unsigned Kind, uint64_t Value, const MCValue &Target, StringRef SecName, uint64_t SrcOffset)
MachineRegisterInfo & MRI
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
Generic interface to target specific assembler backends.
virtual MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
Context object for machine code objects.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
StringRef getName() const
Generic base class for all target subtargets.
const Triple & getTargetTriple() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Twine utohexstr(uint64_t Val)
LLVM Value Representation.
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ fixup_ppc_brcond14abs
14-bit absolute relocation for conditional branches.
@ fixup_ppc_half16
A 16-bit fixup corresponding to lo16(_foo) or ha16(_foo) for instrs like 'li' or 'addis'.
@ fixup_ppc_brcond14
14-bit PC relative relocation for conditional branches.
@ fixup_ppc_half16dq
A 16-bit fixup corresponding to lo16(_foo) with implied 3 zero bits for instrs like 'lxv'.
@ fixup_ppc_half16ds
A 14-bit fixup corresponding to lo16(_foo) with implied 2 zero bits for instrs like 'std'.
@ fixup_ppc_nofixup
Not a true fixup, but ties a symbol to a call to __tls_get_addr for the TLS general and local dynamic...
@ fixup_ppc_br24abs
24-bit absolute relocation for direct branches like 'ba' and 'bla'.
VE::Fixups getFixupKind(uint8_t S)
Error applyFixup(LinkGraph &G, Block &B, const Edge &E, const ArmConfig &ArmCfg)
Apply fixup expression for edge to block content.
bool isRelocation(MCFixupKind FixupKind)
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
This is an optimization pass for GlobalISel generic memory operations.
constexpr int64_t minIntN(int64_t N)
Gets the minimum value for a N-bit signed integer.
MCAsmBackend * createPPCAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
constexpr MCFixupKind FirstTargetFixupKind
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
uint16_t MCFixupKind
Extensible enumeration to represent the type of a fixup.
std::unique_ptr< MCObjectTargetWriter > createPPCXCOFFObjectWriter(bool Is64Bit)
Construct a PPC XCOFF object writer.
@ FK_Data_8
A eight-byte fixup.
@ FK_Data_1
A one-byte fixup.
@ FK_Data_4
A four-byte fixup.
@ FK_Data_2
A two-byte fixup.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
constexpr int64_t maxIntN(int64_t N)
Gets the maximum value for a N-bit signed integer.
std::unique_ptr< MCObjectTargetWriter > createPPCELFObjectWriter(bool Is64Bit, uint8_t OSABI)
Construct an PPC ELF object writer.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
constexpr MCFixupKind FirstLiteralRelocationKind
Target independent information on a fixup kind.