LLVM: include/llvm/MC/MCMachObjectWriter.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_MC_MCMACHOBJECTWRITER_H

10#define LLVM_MC_MCMACHOBJECTWRITER_H

11

23#include

24#include

25#include

26#include

27

28namespace llvm {

29

30class MachObjectWriter;

31

33 const unsigned Is64Bit : 1;

35protected:

37public:

39

40protected:

43

46 }

47

48public:

50

54 }

55

56

57

58

60

61

62

63

64

65

66 bool is64Bit() const { return Is64Bit; }

71 }

72

73

74

75

76

77

82

83

84};

85

87public:

92 };

93

94

95

97 bool EmitBuildVersion;

98 union {

105

107 };

108

109private:

110

111 struct MachSymbolData {

115

116

117 bool operator<(const MachSymbolData &RHS) const;

118 };

119

120 struct IndirectSymbolData {

121 MCSymbol *Symbol;

122 MCSection *Section;

123 };

124

125

126 std::unique_ptr TargetObjectWriter;

127

128

129

130

131 struct RelAndSymbol {

133 MachO::any_relocation_info MRE;

134 RelAndSymbol(const MCSymbol *Sym, const MachO::any_relocation_info &MRE)

135 : Sym(Sym), MRE(MRE) {}

136 };

137

138 DenseMap<const MCSection *, std::vector> Relocations;

139 std::vector IndirectSymbols;

140 DenseMap<const MCSection *, unsigned> IndirectSymBase;

141

142 std::vector DataRegions;

143

145

146

147

148 SmallVector<MCSection *, 0> SectionOrder;

149

150

151

152

153

154 StringTableBuilder StringTable;

155 std::vector LocalSymbolData;

156 std::vector ExternalSymbolData;

157 std::vector UndefinedSymbolData;

158

159

160

161

162 MCLOHContainer LOHContainer;

163

166

167

168 std::vector<std::vectorstd::string> LinkerOptions;

169

170 MachSymbolData *findSymbolData(const MCSymbol &Sym);

171

172 void writeWithPadding(StringRef Str, uint64_t Size);

173

174public:

177 : TargetObjectWriter(std::move(MOTW)),

182

184

186

187

188

189

190 void reset() override;

191

192

193

194

195

196

198

200 return IndirectSymbols;

201 }

202 std::vector &getDataRegions() { return DataRegions; }

204 return SectionOrder;

205 }

208

210 return SectionAddress.lookup(Sec);

211 }

213

216

218

220

222

223

227 VersionInfo.EmitBuildVersion = false;

228 VersionInfo.TypeOrPlatform.Type = Type;

229 VersionInfo.Major = Major;

230 VersionInfo.Minor = Minor;

231 VersionInfo.Update = Update;

233 }

237 VersionInfo.EmitBuildVersion = true;

238 VersionInfo.TypeOrPlatform.Platform = Platform;

239 VersionInfo.Major = Major;

240 VersionInfo.Minor = Minor;

241 VersionInfo.Update = Update;

243 }

247 TargetVariantVersionInfo.EmitBuildVersion = true;

248 TargetVariantVersionInfo.TypeOrPlatform.Platform = Platform;

249 TargetVariantVersionInfo.Major = Major;

250 TargetVariantVersionInfo.Minor = Minor;

251 TargetVariantVersionInfo.Update = Update;

252 TargetVariantVersionInfo.SDKVersion = SDKVersion;

253 }

254

256 return LinkerOptions;

257 }

258

259

260

261

262

263

264 bool is64Bit() const { return TargetObjectWriter->is64Bit(); }

266 uint32_t CPUType = TargetObjectWriter->getCPUType();

268 }

269

270

271

274

275

276

277

278

281 uint64_t SectionDataStartOffset,

284

287 uint64_t RelocationsStart, unsigned NumRelocations);

288

292

298

300

303

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

327 RelAndSymbol P(RelSymbol, MRE);

328 Relocations[Sec].push_back(P);

329 }

330

333 uint64_t &FixedValue) override;

334

336

337

339 std::vector &LocalSymbolData,

340 std::vector &ExternalSymbolData,

341 std::vector &UndefinedSymbolData);

342

344

346

350 bool IsPCRel) const override;

351

353

355};

356}

357

358#endif

This file defines the DenseMap class.

PowerPC TLS Dynamic Call Fixup

Defines the llvm::VersionTuple class, which represents a version in the form major[....

Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...

uint32_t getCPUType() const

unsigned LocalDifference_RIT

virtual void recordRelocation(MachObjectWriter *Writer, MCAssembler &Asm, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0

void setLocalDifferenceRelocationType(unsigned Type)

uint32_t getCPUSubtype() const

static bool classof(const MCObjectTargetWriter *W)

Triple::ObjectFormatType getFormat() const override

virtual ~MCMachObjectTargetWriter()

unsigned getLocalDifferenceRelocationType() const

Base class for classes that define behaviour that is specific to both the target and the object forma...

Defines the object file and target independent interfaces used by the assembler backend to write nati...

bool SubsectionsViaSymbols

Instances of this class represent a uniqued identifier for a section in the current translation unit.

MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...

This represents an "assembler immediate".

uint64_t getPaddingSize(const MCAssembler &Asm, const MCSection *SD) const

void setTargetVariantBuildVersion(MachO::PlatformType Platform, unsigned Major, unsigned Minor, unsigned Update, VersionTuple SDKVersion)

void computeSectionAddresses(const MCAssembler &Asm)

void writeSection(const MCAssembler &Asm, const MCSection &Sec, uint64_t VMAddr, uint64_t FileOffset, unsigned Flags, uint64_t RelocationsStart, unsigned NumRelocations)

bool doesSymbolRequireExternRelocation(const MCSymbol &S)

MCLOHContainer & getLOHContainer()

MachO::PlatformType Platform

Used when EmitBuildVersion==true.

union llvm::MachObjectWriter::@348 TypeOrPlatform

SectionAddrMap & getSectionAddressMap()

void computeSymbolTable(MCAssembler &Asm, std::vector< MachSymbolData > &LocalSymbolData, std::vector< MachSymbolData > &ExternalSymbolData, std::vector< MachSymbolData > &UndefinedSymbolData)

Compute the symbol table data.

uint64_t getFragmentAddress(const MCAssembler &Asm, const MCFragment *Fragment) const

{ bool EmitBuildVersion VersionInfoType

void executePostLayoutBinding(MCAssembler &Asm) override

Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...

uint64_t getSectionAddress(const MCSection *Sec) const

void addRelocation(const MCSymbol *RelSymbol, const MCSection *Sec, MachO::any_relocation_info &MRE)

const llvm::SmallVectorImpl< MCSection * > & getSectionOrder() const

std::vector< DataRegionData > & getDataRegions()

void populateAddrSigSection(MCAssembler &Asm)

bool isFixupKindPCRel(const MCAssembler &Asm, unsigned Kind)

support::endian::Writer W

void writeLinkerOptionsLoadCommand(const std::vector< std::string > &Options)

void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) override

Record a relocation entry.

void writeNlist(MachSymbolData &MSD, const MCAssembler &Asm)

VersionTuple SDKVersion

An optional version of the SDK that was used to build the source.

bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, bool InSet, bool IsPCRel) const override

void writeDysymtabLoadCommand(uint32_t FirstLocalSymbol, uint32_t NumLocalSymbols, uint32_t FirstExternalSymbol, uint32_t NumExternalSymbols, uint32_t FirstUndefinedSymbol, uint32_t NumUndefinedSymbols, uint32_t IndirectSymbolOffset, uint32_t NumIndirectSymbols)

const MCSymbol & findAliasedSymbol(const MCSymbol &Sym) const

std::vector< IndirectSymbolData > & getIndirectSymbols()

uint64_t getSymbolAddress(const MCSymbol &S, const MCAssembler &Asm) const

MCVersionMinType Type

Used when EmitBuildVersion==false.

void writeSegmentLoadCommand(StringRef Name, unsigned NumSections, uint64_t VMAddr, uint64_t VMSize, uint64_t SectionDataStartOffset, uint64_t SectionDataSize, uint32_t MaxProt, uint32_t InitProt)

Write a segment load command.

const MCSymbol * getAtom(const MCSymbol &S) const

void writeLinkeditLoadCommand(uint32_t Type, uint32_t DataOffset, uint32_t DataSize)

void writeHeader(MachO::HeaderFileType Type, unsigned NumLoadCommands, unsigned LoadCommandsSize, bool SubsectionsViaSymbols)

void reset() override

lifetime management

void writeSymtabLoadCommand(uint32_t SymbolOffset, uint32_t NumSymbols, uint32_t StringTableOffset, uint32_t StringTableSize)

void bindIndirectSymbols(MCAssembler &Asm)

void setVersionMin(MCVersionMinType Type, unsigned Major, unsigned Minor, unsigned Update, VersionTuple SDKVersion=VersionTuple())

Mach-O deployment target version information.

void setBuildVersion(MachO::PlatformType Platform, unsigned Major, unsigned Minor, unsigned Update, VersionTuple SDKVersion=VersionTuple())

uint64_t writeObject(MCAssembler &Asm) override

Write the object file and returns the number of bytes written.

MachObjectWriter(std::unique_ptr< MCMachObjectTargetWriter > MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)

std::vector< std::vector< std::string > > & getLinkerOptions()

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

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

Utility for building string tables with deduplicated suffixes.

A table of densely packed, null-terminated strings indexed by offset.

Target - Wrapper for Target specific information.

The instances of the Type class are immutable: once they are created, they are never changed.

Represents a version number in the form major[.minor[.subminor[.build]]].

An abstract base class for streams implementations that also support a pwrite operation.

This is an optimization pass for GlobalISel generic memory operations.

bool operator<(int64_t V1, const APSInt &V2)

DenseMap< const MCSection *, uint64_t > SectionAddrMap

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

Implement std::hash so that hash_code can be used in STL containers.

MachO::DataRegionType Kind

Adapter to write values to a stream in a particular byte order.