LLVM: lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

20

21using namespace llvm;

22

24 switch (Kind) {

25 default:

33

35 return (Value >> 2) & 0x3fffffff;

36

37 case ELF::R_SPARC_WDISP22:

38 return (Value >> 2) & 0x3fffff;

39

40 case ELF::R_SPARC_WDISP19:

41 return (Value >> 2) & 0x7ffff;

42

43 case ELF::R_SPARC_WDISP16: {

44

45

46

47 unsigned d16hi = (Value >> 16) & 0x3;

48 unsigned d16lo = (Value >> 2) & 0x3fff;

49 return (d16hi << 20) | d16lo;

50 }

51

52 case ELF::R_SPARC_WDISP10: {

53

55

56

57

58

59 unsigned d10hi = (Value >> 10) & 0x3;

60 unsigned d10lo = (Value >> 2) & 0xff;

61 return (d10hi << 19) | (d10lo << 5);

62 }

63

64 case ELF::R_SPARC_HIX22:

65 return (~Value >> 10) & 0x3fffff;

66

67 case ELF::R_SPARC_PC22:

68 case ELF::R_SPARC_HI22:

69 case ELF::R_SPARC_LM22:

70 return (Value >> 10) & 0x3fffff;

71

73 return Value & 0x1fff;

74

75 case ELF::R_SPARC_5:

76 return Value & 0x1f;

77

78 case ELF::R_SPARC_LOX10:

79 return (Value & 0x3ff) | 0x1c00;

80

81 case ELF::R_SPARC_PC10:

82 case ELF::R_SPARC_LO10:

83 return Value & 0x3ff;

84

85 case ELF::R_SPARC_H44:

86 return (Value >> 22) & 0x3fffff;

87 case ELF::R_SPARC_M44:

88 return (Value >> 12) & 0x3ff;

89 case ELF::R_SPARC_L44:

90 return Value & 0xfff;

91

92 case ELF::R_SPARC_HH22:

93 return (Value >> 42) & 0x3fffff;

94 case ELF::R_SPARC_HM10:

95 return (Value >> 32) & 0x3ff;

96 }

97}

98

99

101 switch (Kind) {

102 default:

103 return 4;

105 return 1;

107 return 2;

109 return 8;

110 }

111}

112

113namespace {

115protected:

116 bool Is64Bit;

117 bool IsV8Plus;

118

119public:

120 SparcAsmBackend(const MCSubtargetInfo &STI)

121 : MCAsmBackend(STI.getTargetTriple().isLittleEndian()

124 Is64Bit(STI.getTargetTriple().isArch64Bit()),

125 IsV8Plus(STI.hasFeature(Sparc::FeatureV8Plus)) {}

126

127 std::optional getFixupKind(StringRef Name) const override;

128 MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;

129 void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target,

130 uint8_t *Data, uint64_t Value, bool IsResolved) override;

131

132 bool writeNopData(raw_ostream &OS, uint64_t Count,

133 const MCSubtargetInfo *STI) const override {

134

135

136

137

139

140 uint64_t NumNops = Count / 4;

141 for (uint64_t i = 0; i != NumNops; ++i)

143

144 return true;

145 }

146};

147

148class ELFSparcAsmBackend : public SparcAsmBackend {

150

151public:

152 ELFSparcAsmBackend(const MCSubtargetInfo &STI, Triple::OSType OSType)

153 : SparcAsmBackend(STI), OSType(OSType) {}

154

155 std::unique_ptr

156 createObjectTargetWriter() const override {

159 }

160};

161}

162

163std::optional SparcAsmBackend::getFixupKind(StringRef Name) const {

164 unsigned Type;

165 Type = llvm::StringSwitch(Name)

166#define ELF_RELOC(X, Y) .Case(#X, Y)

167#include "llvm/BinaryFormat/ELFRelocs/Sparc.def"

168#undef ELF_RELOC

169 .Case("BFD_RELOC_NONE", ELF::R_SPARC_NONE)

170 .Case("BFD_RELOC_8", ELF::R_SPARC_8)

171 .Case("BFD_RELOC_16", ELF::R_SPARC_16)

172 .Case("BFD_RELOC_32", ELF::R_SPARC_32)

173 .Case("BFD_RELOC_64", ELF::R_SPARC_64)

174 .Default(-1u);

175 if (Type == -1u)

176 return std::nullopt;

178}

179

180MCFixupKindInfo SparcAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {

181

183

184 {"fixup_sparc_call30", 2, 30, 0},

185 {"fixup_sparc_13", 19, 13, 0},

186 };

187

189

190 {"fixup_sparc_call30", 0, 30, 0},

191 {"fixup_sparc_13", 0, 13, 0},

192 };

193

194

199 "Invalid kind!");

202

204 }

205

206 MCFixupKindInfo Info{};

207 switch (uint16_t(Kind)) {

208 case ELF::R_SPARC_PC10:

209 Info = {"", 22, 10, 0};

210 break;

211 case ELF::R_SPARC_PC22:

212 Info = {"", 10, 22, 0};

213 break;

214 case ELF::R_SPARC_WDISP10:

215 Info = {"", 0, 32, 0};

216 break;

217 case ELF::R_SPARC_WDISP16:

218 Info = {"", 0, 32, 0};

219 break;

220 case ELF::R_SPARC_WDISP19:

221 Info = {"", 13, 19, 0};

222 break;

223 case ELF::R_SPARC_WDISP22:

224 Info = {"", 10, 22, 0};

225 break;

226

227 case ELF::R_SPARC_HI22:

228 Info = {"", 10, 22, 0};

229 break;

230 case ELF::R_SPARC_LO10:

231 Info = {"", 22, 10, 0};

232 break;

233 case ELF::R_SPARC_HH22:

234 Info = {"", 10, 22, 0};

235 break;

236 case ELF::R_SPARC_HM10:

237 Info = {"", 22, 10, 0};

238 break;

239 case ELF::R_SPARC_LM22:

240 Info = {"", 10, 22, 0};

241 break;

242 case ELF::R_SPARC_HIX22:

243 Info = {"", 10, 22, 0};

244 break;

245 case ELF::R_SPARC_LOX10:

246 Info = {"", 19, 13, 0};

247 break;

248 }

250 Info.TargetOffset = 32 - Info.TargetOffset - Info.TargetSize;

252}

253

254void SparcAsmBackend::applyFixup(const MCFragment &F, const MCFixup &Fixup,

255 const MCValue &Target, uint8_t *Data,

256 uint64_t Value, bool IsResolved) {

257 maybeAddReloc(F, Fixup, Target, Value, IsResolved);

258 if (!IsResolved)

259 return;

261

263

264

265 for (unsigned i = 0; i != NumBytes; ++i) {

267 Data[Idx] |= uint8_t((Value >> (i * 8)) & 0xff);

268 }

269}

270

unsigned const MachineRegisterInfo * MRI

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)

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

Analysis containing CSE Info

PowerPC TLS Dynamic Call Fixup

static unsigned adjustFixupValue(unsigned Kind, uint64_t Value)

Definition SparcAsmBackend.cpp:23

static unsigned getFixupKindNumBytes(unsigned Kind)

getFixupKindNumBytes - The number of bytes the fixup may change.

Definition SparcAsmBackend.cpp:100

This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...

Generic interface to target specific assembler backends.

virtual MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const

Get information on a fixup kind.

MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...

Generic base class for all target subtargets.

const Triple & getTargetTriple() const

StringRef - Represent a constant reference to a string, i.e.

Target - Wrapper for Target specific information.

OSType getOS() const

Get the parsed operating system type of this triple.

LLVM Value Representation.

raw_ostream & write_zeros(unsigned NumZeros)

write_zeros - Insert 'NumZeros' nulls.

@ fixup_sparc_13

fixup_sparc_13 - 13-bit fixup

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.

FunctionAddr VTableAddr Value

uint16_t MCFixupKind

Extensible enumeration to represent the type of a fixup.

std::unique_ptr< MCObjectTargetWriter > createSparcELFObjectWriter(bool Is64Bit, bool IsV8Plus, uint8_t OSABI)

FunctionAddr VTableAddr Count

@ FirstLiteralRelocationKind

@ 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.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

MCAsmBackend * createSparcAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)

Definition SparcAsmBackend.cpp:271