9#ifndef LLVM_MC_MCMACHOBJECTWRITER_H
10#define LLVM_MC_MCMACHOBJECTWRITER_H
35 const unsigned Is64Bit : 1;
99 bool EmitBuildVersion;
113 struct MachSymbolData {
122 struct IndirectSymbolData {
123 MCSymbolMachO *Symbol;
128 std::unique_ptr<MCMachObjectTargetWriter> TargetObjectWriter;
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) {}
140 DenseMap<const MCSection *, std::vector<RelAndSymbol>> Relocations;
141 std::vector<IndirectSymbolData> IndirectSymbols;
142 DenseMap<const MCSection *, unsigned> IndirectSymBase;
144 std::vector<DataRegionData> DataRegions;
147 DenseMap<const MCSection *, uint64_t> SectionDataOffset;
151 SmallVector<MCSection *, 0> SectionOrder;
158 std::vector<MachSymbolData> LocalSymbolData;
159 std::vector<MachSymbolData> ExternalSymbolData;
160 std::vector<MachSymbolData> UndefinedSymbolData;
165 MCLOHContainer LOHContainer;
167 VersionInfoType VersionInfo{};
168 VersionInfoType TargetVariantVersionInfo{};
170 std::optional<std::string> TargetTriple;
173 std::vector<std::vector<std::string>> LinkerOptions;
175 MachSymbolData *findSymbolData(
const MCSymbol &Sym);
177 void writeWithPadding(StringRef Str,
uint64_t Size);
182 : TargetObjectWriter(
std::
move(MOTW)),
192 void reset()
override;
199 return IndirectSymbols;
217 bool doesSymbolRequireExternRelocation(
const MCSymbol &S);
223 VersionInfo.EmitBuildVersion =
false;
224 VersionInfo.TypeOrPlatform.Type =
Type;
225 VersionInfo.Major = Major;
226 VersionInfo.Minor = Minor;
227 VersionInfo.Update = Update;
228 VersionInfo.SDKVersion = SDKVersion;
231 unsigned Minor,
unsigned Update,
233 VersionInfo.EmitBuildVersion =
true;
234 VersionInfo.TypeOrPlatform.Platform = Platform;
235 VersionInfo.Major = Major;
236 VersionInfo.Minor = Minor;
237 VersionInfo.Update = Update;
238 VersionInfo.SDKVersion = SDKVersion;
241 unsigned Major,
unsigned Minor,
243 TargetVariantVersionInfo.EmitBuildVersion =
true;
244 TargetVariantVersionInfo.TypeOrPlatform.Platform = Platform;
245 TargetVariantVersionInfo.Major = Major;
246 TargetVariantVersionInfo.Minor = Minor;
247 TargetVariantVersionInfo.Update = Update;
248 TargetVariantVersionInfo.SDKVersion = SDKVersion;
254 return LinkerOptions;
262 bool is64Bit()
const {
return TargetObjectWriter->is64Bit(); }
264 uint32_t CPUType = TargetObjectWriter->getCPUType();
271 unsigned LoadCommandsSize,
bool SubsectionsViaSymbols);
277 void writeSegmentLoadCommand(
StringRef Name,
unsigned NumSections,
285 uint64_t RelocationsStart,
unsigned NumRelocations);
291 void writeDysymtabLoadCommand(
297 void writeNlist(MachSymbolData &MSD,
const MCAssembler &Asm);
302 void writeLinkerOptionsLoadCommand(
const std::vector<std::string> &
Options);
325 RelAndSymbol
P(RelSymbol, MRE);
326 Relocations[Sec].push_back(
P);
336 std::vector<MachSymbolData> &LocalSymbolData,
337 std::vector<MachSymbolData> &ExternalSymbolData,
338 std::vector<MachSymbolData> &UndefinedSymbolData);
340 void computeSectionAddresses(
const MCAssembler &Asm);
342 void executePostLayoutBinding()
override;
344 bool isSymbolRefDifferenceFullyResolvedImpl(
const MCSymbol &SymA,
346 bool IsPCRel)
const override;
This file defines the DenseMap class.
bool operator<(const DeltaInfo &LHS, int64_t Delta)
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
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
MCMachObjectTargetWriter(bool Is64Bit_, uint32_t CPUType_, uint32_t CPUSubtype_)
unsigned getLocalDifferenceRelocationType() const
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)
MCLOHContainer & getLOHContainer()
void addRelocation(const MCSymbol *RelSymbol, const MCSection *Sec, MachO::any_relocation_info &MRE)
const llvm::SmallVectorImpl< MCSection * > & getSectionOrder() const
std::vector< DataRegionData > & getDataRegions()
support::endian::Writer W
const MCSymbol & findAliasedSymbol(const MCSymbol &Sym) const
std::vector< IndirectSymbolData > & getIndirectSymbols()
void setAssembler(MCAssembler *Asm) override
void setTargetTriple(StringRef Triple)
void reset() override
lifetime management
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())
MachObjectWriter(std::unique_ptr< MCMachObjectTargetWriter > MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
std::vector< std::vector< std::string > > & getLinkerOptions()
struct { bool EmitBuildVersion; union { MCVersionMinType Type; MachO::PlatformType Platform; } TypeOrPlatform; unsigned Major; unsigned Minor; unsigned Update; VersionTuple SDKVersion; } VersionInfoType
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Utility for building string tables with deduplicated suffixes.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
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.
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.