27enum X86_32RelType { RT32_NONE, RT32_32, RT32_16, RT32_8 };
28enum X86_64RelType { RT64_NONE, RT64_64, RT64_32, RT64_32S, RT64_16, RT64_8 };
33 ~X86ELFObjectWriter()
override =
default;
37 bool IsPCRel)
const override;
40 void checkIs32(
SMLoc Loc, X86_64RelType
Type)
const;
41 void checkIs64(
SMLoc Loc, X86_64RelType
Type)
const;
43 X86_32RelType
Type,
bool IsPCRel,
46 X86_64RelType
Type,
bool IsPCRel,
52X86ELFObjectWriter::X86ELFObjectWriter(
bool IsELF64,
uint8_t OSABI,
62 switch (
unsigned(Kind)) {
97void X86ELFObjectWriter::checkIs32(
SMLoc Loc, X86_64RelType
Type)
const {
99 reportError(Loc,
"32 bit reloc applied to a field with a different size");
102void X86ELFObjectWriter::checkIs64(
SMLoc Loc, X86_64RelType
Type)
const {
104 reportError(Loc,
"64 bit reloc applied to a field with a different size");
108 X86_64RelType
Type,
bool IsPCRel,
118 return ELF::R_X86_64_NONE;
121 return IsPCRel ? ELF::R_X86_64_PC64 : ELF::R_X86_64_64;
123 return IsPCRel ? ELF::R_X86_64_PC32 : ELF::R_X86_64_32;
125 return ELF::R_X86_64_32S;
127 return IsPCRel ? ELF::R_X86_64_PC16 : ELF::R_X86_64_16;
129 return IsPCRel ? ELF::R_X86_64_PC8 : ELF::R_X86_64_8;
135 return IsPCRel ? ELF::R_X86_64_GOTPC64 : ELF::R_X86_64_GOT64;
137 return IsPCRel ? ELF::R_X86_64_GOTPC32 : ELF::R_X86_64_GOT32;
149 return ELF::R_X86_64_GOTOFF64;
154 return ELF::R_X86_64_TPOFF64;
156 return ELF::R_X86_64_TPOFF32;
168 return ELF::R_X86_64_DTPOFF64;
170 return ELF::R_X86_64_DTPOFF32;
182 return ELF::R_X86_64_SIZE64;
184 return ELF::R_X86_64_SIZE32;
193 return ELF::R_X86_64_TLSDESC_CALL;
196 ? ELF::R_X86_64_CODE_4_GOTPC32_TLSDESC
197 : ELF::R_X86_64_GOTPC32_TLSDESC;
199 checkIs32(Loc,
Type);
200 return ELF::R_X86_64_TLSGD;
202 checkIs32(Loc,
Type);
205 return ELF::R_X86_64_CODE_4_GOTTPOFF;
207 return ELF::R_X86_64_CODE_6_GOTTPOFF;
208 return ELF::R_X86_64_GOTTPOFF;
210 checkIs32(Loc,
Type);
211 return ELF::R_X86_64_TLSLD;
213 checkIs32(Loc,
Type);
214 return ELF::R_X86_64_PLT32;
216 checkIs32(Loc,
Type);
220 if (!getContext().getTargetOptions()->X86RelaxRelocations)
221 return ELF::R_X86_64_GOTPCREL;
222 switch (
unsigned(Kind)) {
224 return ELF::R_X86_64_GOTPCREL;
226 return ELF::R_X86_64_GOTPCRELX;
229 return ELF::R_X86_64_REX_GOTPCRELX;
232 return ELF::R_X86_64_CODE_4_GOTPCRELX;
236 checkIs32(Loc,
Type);
237 return ELF::R_X86_64_GOTPCREL;
239 checkIs64(Loc,
Type);
240 return ELF::R_X86_64_PLTOFF64;
245 X86_32RelType
Type,
bool IsPCRel,
255 return ELF::R_386_NONE;
258 return IsPCRel ? ELF::R_386_PC32 : ELF::R_386_32;
260 return IsPCRel ? ELF::R_386_PC16 : ELF::R_386_16;
262 return IsPCRel ? ELF::R_386_PC8 : ELF::R_386_8;
269 return ELF::R_386_GOTPC;
272 if (!getContext().getTargetOptions()->X86RelaxRelocations)
273 return ELF::R_386_GOT32;
281 return ELF::R_386_GOTOFF;
283 return ELF::R_386_TLS_DESC_CALL;
285 return ELF::R_386_TLS_GOTDESC;
290 return ELF::R_386_TLS_LE_32;
295 return ELF::R_386_TLS_LDO_32;
300 return ELF::R_386_TLS_GD;
305 return ELF::R_386_TLS_IE_32;
309 return ELF::R_386_PLT32;
314 return ELF::R_386_TLS_IE;
319 return ELF::R_386_TLS_LE;
324 return ELF::R_386_TLS_GOTIE;
329 return ELF::R_386_TLS_LDM;
332 return ELF::R_386_NONE;
335unsigned X86ELFObjectWriter::getRelocType(
const MCFixup &
Fixup,
337 bool IsPCRel)
const {
361 return getRelocType64(
Fixup.getLoc(), Specifier,
Type, IsPCRel, Kind);
364 "Unsupported ELF machine type.");
366 X86_32RelType RelType = RT32_NONE;
372 return ELF::R_386_NONE;
384 return getRelocType32(
Fixup.getLoc(), Specifier, RelType, IsPCRel, Kind);
387bool X86ELFObjectWriter::needsRelocateWithSymbol(
const MCValue &V,
388 unsigned Type)
const {
389 switch (
V.getSpecifier()) {
400std::unique_ptr<MCObjectTargetWriter>
402 return std::make_unique<X86ELFObjectWriter>(IsELF64, OSABI, EMachine);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Error reportError(StringRef Message)
PowerPC TLS Dynamic Call Fixup
static X86_64RelType getType64(MCFixupKind Kind, X86::Specifier &Specifier, bool &IsPCRel)
virtual unsigned getRelocType(const MCFixup &Fixup, const MCValue &Target, bool IsPCRel) const =0
virtual bool needsRelocateWithSymbol(const MCValue &, unsigned Type) const
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Represents a location in source code.
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ reloc_riprel_4byte_movq_load_rex2
@ reloc_signed_4byte_relax
@ reloc_branch_4byte_pcrel
@ reloc_riprel_4byte_relax
@ reloc_riprel_4byte_relax_evex
@ reloc_riprel_4byte_relax_rex
@ reloc_global_offset_table
@ reloc_riprel_4byte_movq_load
@ reloc_riprel_4byte_relax_rex2
This is an optimization pass for GlobalISel generic memory operations.
@ 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.
std::unique_ptr< MCObjectTargetWriter > createX86ELFObjectWriter(bool IsELF64, uint8_t OSABI, uint16_t EMachine)
Construct an X86 ELF object writer.