Go to the documentation of this file.
40 const bool Is64Bit =
O.is64Bit();
42 for (
const auto &LC :
O.load_commands()) {
43 if (LC.C.cmd != (Is64Bit ? MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT))
46 unsigned NumberOfSections =
47 (Is64Bit ?
O.getSegment64LoadCommand(LC).nsects
48 :
O.getSegmentLoadCommand(LC).nsects);
49 P2CurrentAlignment = NumberOfSections ? 2 : P2MinAlignment;
50 for (
unsigned SI = 0;
SI < NumberOfSections; ++
SI) {
51 P2CurrentAlignment =
std::max(P2CurrentAlignment,
52 (Is64Bit ?
O.getSection64(LC,
SI).align
53 :
O.getSection(LC,
SI).align));
58 :
O.getSegmentLoadCommand(LC).vmaddr);
60 P2MinAlignment =
std::min(P2MinAlignment, P2CurrentAlignment);
70 switch (ObjectFile.getHeader().cputype) {
92 CPUSubType(
O.getHeader().cpusubtype),
108 return CPU.first.takeError();
111 return CPU.second.takeError();
113 return std::make_pair(*CPU.first, *CPU.second);
122 std::unique_ptr<MachOObjectFile> MFO =
nullptr;
123 std::unique_ptr<IRObjectFile> IRFO =
nullptr;
124 for (
const Archive::Child &Child :
A.children(Err)) {
129 if (
Bin->isMachOUniversalBinary())
131 (
"archive member " +
Bin->getFileName() +
132 " is a fat file (not allowed in an archive)")
135 if (
Bin->isMachO()) {
136 MachOObjectFile *
O = cast<MachOObjectFile>(Bin);
139 std::errc::invalid_argument,
140 "archive member %s is a MachO, while previous archive member "
141 "%s was an IR LLVM object",
142 O->getFileName().str().c_str(), IRFO->getFileName().str().c_str());
145 std::tie(MFO->getHeader().cputype, MFO->getHeader().cpusubtype) !=
146 std::tie(
O->getHeader().cputype,
O->getHeader().cpusubtype)) {
148 std::errc::invalid_argument,
149 (
"archive member " +
O->getFileName() +
" cputype (" +
150 Twine(
O->getHeader().cputype) +
") and cpusubtype(" +
151 Twine(
O->getHeader().cpusubtype) +
152 ") does not match previous archive members cputype (" +
153 Twine(MFO->getHeader().cputype) +
") and cpusubtype(" +
154 Twine(MFO->getHeader().cpusubtype) +
155 ") (all members must match) " + MFO->getFileName())
160 ChildOrErr.
get().release();
163 }
else if (
Bin->isIR()) {
164 IRObjectFile *
O = cast<IRObjectFile>(Bin);
167 "archive member '%s' is an LLVM IR object, "
168 "while previous archive member "
170 O->getFileName().str().c_str(),
171 MFO->getFileName().str().c_str());
181 if (*CPUO != *CPUFO) {
183 std::errc::invalid_argument,
184 (
"archive member " +
O->getFileName() +
" cputype (" +
185 Twine(CPUO->first) +
") and cpusubtype(" +
Twine(CPUO->second) +
186 ") does not match previous archive members cputype (" +
187 Twine(CPUFO->first) +
") and cpusubtype(" +
188 Twine(CPUFO->second) +
") (all members must match) " +
194 ChildOrErr.
get().release();
199 (
"archive member " +
Bin->getFileName() +
200 " is neither a MachO file or an LLVM IR file "
201 "(not allowed in an archive)")
209 std::errc::invalid_argument,
210 (
"empty archive with no architecture specification: " +
211 A.getFileName() +
" (can't determine architecture for it)")
216 Slice ArchiveSlice(*(MFO), MFO->is64Bit() ? 3 : 2);
223 if (!ArchiveSliceOrErr)
225 auto &ArchiveSlice = ArchiveSliceOrErr.
get();
234 unsigned CPUType, CPUSubType;
235 std::tie(CPUType, CPUSubType) = CPUOrErr.
get();
238 std::string ArchName(
249 for (
const auto &
S : Slices) {
250 Offset =
alignTo(Offset, 1ull <<
S.getP2Alignment());
251 if (Offset > UINT32_MAX)
253 std::errc::invalid_argument,
254 (
"fat file too large to be created because the offset "
255 "field in struct fat_arch is only 32-bits and the offset " +
256 Twine(Offset) +
" for " +
S.getBinary()->getFileName() +
257 " for architecture " +
S.getArchString() +
"exceeds that.")
265 FatArch.
size =
S.getBinary()->getMemoryBufferRef().getBufferSize();
266 FatArch.
align =
S.getP2Alignment();
267 Offset += FatArch.
size;
268 FatArchList.push_back(FatArch);
281 if (!FatArchListOrErr)
287 Out.
write(
reinterpret_cast<const char *
>(&FatHeader),
293 Out.
write(
reinterpret_cast<const char *
>(FatArchList.data()),
304 assert((Offset <= FatArchList[
Index].offset) &&
"Incorrect slice offset");
323 OutputFileName +
".temp-universal-%%%%%%",
Mode);
328 if (
Error DiscardError = Temp->discard())
332 return Temp->keep(OutputFileName);
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
const char * getBufferStart() const
This is an optimization pass for GlobalISel generic memory operations.
StringRef getArchName(ArchKind AK)
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
static uint32_t calculateFileAlignment(const MachOObjectFile &O)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static ErrorSuccess success()
Create a success value.
Triple - Helper class for working with autoconf configuration names.
static Expected< Slice > create(const Archive &A, LLVMContext *LLVMCtx=nullptr)
size_t getBufferSize() const
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Tagged union holding either a T or a Error.
Expected< uint32_t > getCPUType(const Triple &T)
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
StringRef getTargetTriple() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
raw_ostream & write(unsigned char C)
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned countTrailingZeros(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Expected< uint32_t > getCPUSubType(const Triple &T)
This struct is a compact representation of a valid (non-zero power of two) alignment.
static Expected< MachoCPUTy > getMachoCPUFromTriple(Triple TT)
bar al al movzbl eax ret Missed when stored in a memory object
std::pair< unsigned, unsigned > MachoCPUTy
static Expected< SmallVector< MachO::fat_arch, 2 > > buildFatArchList(ArrayRef< Slice > Slices)
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
This is an important class for using LLVM in a threaded context.
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Triple getArchTriple(const char **McpuDefault=nullptr) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static constexpr uint32_t MaxSectionAlignment
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
StringRef - Represent a constant reference to a string, i.e.
reference get()
Returns a reference to the stored T value.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
A raw_ostream that writes to a file descriptor.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Error writeUniversalBinaryToStream(ArrayRef< Slice > Slices, raw_ostream &Out)
Lightweight error class with error context and mandatory checking.
Error takeError()
Take ownership of the stored error.
static const bool IsLittleEndianHost
size_t size() const
size - Get the array size.
Error writeUniversalBinary(ArrayRef< Slice > Slices, StringRef OutputFileName)
static uint32_t calculateAlignment(const MachOObjectFile &ObjectFile)
static Expected< TempFile > create(const Twine &Model, unsigned Mode=all_read|all_write, OpenFlags ExtraFlags=OF_None)
This creates a temporary file with createUniqueFile and schedules it for deletion with sys::RemoveFil...
void swapStruct(fat_header &mh)
bool can_execute(const Twine &Path)
Can we execute this file?