9#ifndef LLVM_MC_MCMACHOBJECTWRITER_H
10#define LLVM_MC_MCMACHOBJECTWRITER_H
30class MachObjectWriter;
33 const unsigned Is64Bit : 1;
97 bool EmitBuildVersion;
111 struct MachSymbolData {
114 uint8_t SectionIndex;
120 struct IndirectSymbolData {
126 std::unique_ptr<MCMachObjectTargetWriter> TargetObjectWriter;
131 struct RelAndSymbol {
133 MachO::any_relocation_info MRE;
134 RelAndSymbol(
const MCSymbol *Sym,
const MachO::any_relocation_info &MRE)
138 DenseMap<const MCSection *, std::vector<RelAndSymbol>> Relocations;
139 std::vector<IndirectSymbolData> IndirectSymbols;
140 DenseMap<const MCSection *, unsigned> IndirectSymBase;
142 std::vector<DataRegionData> DataRegions;
148 SmallVector<MCSection *, 0> SectionOrder;
154 StringTableBuilder StringTable;
155 std::vector<MachSymbolData> LocalSymbolData;
156 std::vector<MachSymbolData> ExternalSymbolData;
157 std::vector<MachSymbolData> UndefinedSymbolData;
162 MCLOHContainer LOHContainer;
168 std::vector<std::vector<std::string>> LinkerOptions;
170 MachSymbolData *findSymbolData(
const MCSymbol &
Sym);
177 : TargetObjectWriter(
std::
move(MOTW)),
190 void reset()
override;
200 return IndirectSymbols;
210 return SectionAddress.lookup(Sec);
227 VersionInfo.EmitBuildVersion =
false;
228 VersionInfo.TypeOrPlatform.Type =
Type;
229 VersionInfo.Major =
Major;
230 VersionInfo.Minor =
Minor;
231 VersionInfo.Update =
Update;
237 VersionInfo.EmitBuildVersion =
true;
238 VersionInfo.TypeOrPlatform.Platform =
Platform;
239 VersionInfo.Major =
Major;
240 VersionInfo.Minor =
Minor;
241 VersionInfo.Update =
Update;
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;
256 return LinkerOptions;
264 bool is64Bit()
const {
return TargetObjectWriter->is64Bit(); }
266 uint32_t CPUType = TargetObjectWriter->getCPUType();
287 uint64_t RelocationsStart,
unsigned NumRelocations);
327 RelAndSymbol
P(RelSymbol, MRE);
328 Relocations[Sec].push_back(
P);
339 std::vector<MachSymbolData> &LocalSymbolData,
340 std::vector<MachSymbolData> &ExternalSymbolData,
341 std::vector<MachSymbolData> &UndefinedSymbolData);
350 bool IsPCRel)
const override;
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.
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
union llvm::MachObjectWriter::@345 TypeOrPlatform
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.
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.