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

25#include

26#include

27#include

28#include

29

30namespace llvm {

31

33

35 const unsigned Is64Bit : 1;

37protected:

39public:

41

42protected:

45

49

50public:

52

57

58

59

60

62

63

64

65

66

67

68 bool is64Bit() const { return Is64Bit; }

74

75

76

77

78

79

84

85

86};

87

89public:

95

96

97

99 bool EmitBuildVersion;

100 union {

103 } TypeOrPlatform;

104 unsigned Major;

105 unsigned Minor;

106 unsigned Update;

107

109 };

110

111private:

112

113 struct MachSymbolData {

117

118

120 };

121

122 struct IndirectSymbolData {

123 MCSymbolMachO *Symbol;

124 MCSection *Section;

125 };

126

127

128 std::unique_ptr TargetObjectWriter;

129

130

131

132

133 struct RelAndSymbol {

135 MachO::any_relocation_info MRE;

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

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

138 };

139

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

141 std::vector IndirectSymbols;

142 DenseMap<const MCSection *, unsigned> IndirectSymBase;

143

144 std::vector DataRegions;

145

146 DenseMap<const MCSection *, uint64_t> SectionAddress;

147

148

149

150 SmallVector<MCSection *, 0> SectionOrder;

151

152

153

154

155

157 std::vector LocalSymbolData;

158 std::vector ExternalSymbolData;

159 std::vector UndefinedSymbolData;

160

161

162

163

164 MCLOHContainer LOHContainer;

165

166 VersionInfoType VersionInfo{};

167 VersionInfoType TargetVariantVersionInfo{};

168

169

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

171

172 MachSymbolData *findSymbolData(const MCSymbol &Sym);

173

174 void writeWithPadding(StringRef Str, uint64_t Size);

175

176public:

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

182 W(OS,

184

186

188

189 void reset() override;

191

192

193

194

196 return IndirectSymbols;

197 }

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

200 return SectionOrder;

201 }

203

205 return SectionAddress.lookup(Sec);

206 }

208

211

213

215

216 bool doesSymbolRequireExternRelocation(const MCSymbol &S);

217

218

220 unsigned Update,

222 VersionInfo.EmitBuildVersion = false;

223 VersionInfo.TypeOrPlatform.Type = Type;

224 VersionInfo.Major = Major;

225 VersionInfo.Minor = Minor;

226 VersionInfo.Update = Update;

227 VersionInfo.SDKVersion = SDKVersion;

228 }

230 unsigned Minor, unsigned Update,

232 VersionInfo.EmitBuildVersion = true;

233 VersionInfo.TypeOrPlatform.Platform = Platform;

234 VersionInfo.Major = Major;

235 VersionInfo.Minor = Minor;

236 VersionInfo.Update = Update;

237 VersionInfo.SDKVersion = SDKVersion;

238 }

240 unsigned Major, unsigned Minor,

242 TargetVariantVersionInfo.EmitBuildVersion = true;

243 TargetVariantVersionInfo.TypeOrPlatform.Platform = Platform;

244 TargetVariantVersionInfo.Major = Major;

245 TargetVariantVersionInfo.Minor = Minor;

246 TargetVariantVersionInfo.Update = Update;

247 TargetVariantVersionInfo.SDKVersion = SDKVersion;

248 }

249

251 return LinkerOptions;

252 }

253

254

255

256

257

258

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

261 uint32_t CPUType = TargetObjectWriter->getCPUType();

263 }

264

265

266

268 unsigned LoadCommandsSize, bool SubsectionsViaSymbols);

269

270

271

272

273

274 void writeSegmentLoadCommand(StringRef Name, unsigned NumSections,

276 uint64_t SectionDataStartOffset,

279

282 uint64_t RelocationsStart, unsigned NumRelocations);

283

284 void writeSymtabLoadCommand(uint32_t SymbolOffset, uint32_t NumSymbols,

287

288 void writeDysymtabLoadCommand(

293

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

295

298

299 void writeLinkerOptionsLoadCommand(const std::vectorstd::string &Options);

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

322 RelAndSymbol P(RelSymbol, MRE);

323 Relocations[Sec].push_back(P);

324 }

325

328

329 void bindIndirectSymbols(MCAssembler &Asm);

330

331

332 void computeSymbolTable(MCAssembler &Asm,

333 std::vector &LocalSymbolData,

334 std::vector &ExternalSymbolData,

335 std::vector &UndefinedSymbolData);

336

337 void computeSectionAddresses(const MCAssembler &Asm);

338

339 void executePostLayoutBinding() override;

340

341 bool isSymbolRefDifferenceFullyResolvedImpl(const MCSymbol &SymA,

343 bool IsPCRel) const override;

344

345 void populateAddrSigSection(MCAssembler &Asm);

346

347 uint64_t writeObject() override;

348};

349}

350

351#endif

This file defines the DenseMap class.

bool operator<(const DeltaInfo &LHS, int64_t Delta)

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

~MCMachObjectTargetWriter() override

uint32_t getCPUType() const

Definition MCMachObjectWriter.h:69

unsigned LocalDifference_RIT

Definition MCMachObjectWriter.h:40

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

uint32_t CPUSubtype

Definition MCMachObjectWriter.h:38

void setLocalDifferenceRelocationType(unsigned Type)

Definition MCMachObjectWriter.h:46

uint32_t getCPUSubtype() const

Definition MCMachObjectWriter.h:70

bool is64Bit() const

Definition MCMachObjectWriter.h:68

static bool classof(const MCObjectTargetWriter *W)

Definition MCMachObjectWriter.h:54

Triple::ObjectFormatType getFormat() const override

Definition MCMachObjectWriter.h:53

MCMachObjectTargetWriter(bool Is64Bit_, uint32_t CPUType_, uint32_t CPUSubtype_)

virtual void reset()

Definition MCMachObjectWriter.h:61

unsigned getLocalDifferenceRelocationType() const

Definition MCMachObjectWriter.h:71

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

This represents a section on a Mach-O system (used by Mac OS X).

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

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

Definition MCMachObjectWriter.h:239

MCLOHContainer & getLOHContainer()

Definition MCMachObjectWriter.h:202

bool is64Bit() const

Definition MCMachObjectWriter.h:259

uint64_t getSectionAddress(const MCSection *Sec) const

Definition MCMachObjectWriter.h:204

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

Definition MCMachObjectWriter.h:320

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

Definition MCMachObjectWriter.h:199

std::vector< DataRegionData > & getDataRegions()

Definition MCMachObjectWriter.h:198

support::endian::Writer W

Definition MCMachObjectWriter.h:185

const MCSymbol & findAliasedSymbol(const MCSymbol &Sym) const

std::vector< IndirectSymbolData > & getIndirectSymbols()

Definition MCMachObjectWriter.h:195

void setAssembler(MCAssembler *Asm) override

void reset() override

lifetime management

bool isX86_64() const

Definition MCMachObjectWriter.h:260

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

Mach-O deployment target version information.

Definition MCMachObjectWriter.h:219

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

Definition MCMachObjectWriter.h:229

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

Definition MCMachObjectWriter.h:177

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

Definition MCMachObjectWriter.h:250

struct { bool EmitBuildVersion; union { MCVersionMinType Type; MachO::PlatformType Platform; } TypeOrPlatform; unsigned Major; unsigned Minor; unsigned Update; VersionTuple SDKVersion; } VersionInfoType

Definition MCMachObjectWriter.h:98

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.

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.

FunctionAddr VTableAddr uintptr_t uintptr_t DataSize

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.

MCSymbol * End

Definition MCMachObjectWriter.h:93

MachO::DataRegionType Kind

Definition MCMachObjectWriter.h:91

MCSymbol * Start

Definition MCMachObjectWriter.h:92

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