LLVM 20.0.0git
MachO.h
Go to the documentation of this file.
1//===------------- MachO.h - MachO format utilities -------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Contains utilities for load MachO relocatable object files.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_MACHO_H
14#define LLVM_EXECUTIONENGINE_ORC_MACHO_H
15
17#include "llvm/Support/Error.h"
20
21namespace llvm {
22
23namespace object {
24
25class MachOUniversalBinary;
26
27} // namespace object
28
29namespace orc {
30
31class JITDylib;
32class ObjectLayer;
33
34/// Check that the given buffer contains a MachO object file compatible with the
35/// given triple.
36/// ObjIsSlice should be set to true if Obj is a slice of a universal binary
37/// (that fact will then be reported in the error messages).
38Error checkMachORelocatableObject(MemoryBufferRef Obj, const Triple &TT,
39 bool ObjIsSlice);
40
41/// Check that the given buffer contains a MachO object file compatible with the
42/// given triple.
43/// This convenience overload returns the buffer if it passes all checks,
44/// otherwise it returns an error.
45Expected<std::unique_ptr<MemoryBuffer>>
46checkMachORelocatableObject(std::unique_ptr<MemoryBuffer> Obj, const Triple &TT,
47 bool ObjIsSlice);
48
49/// Load a relocatable object compatible with TT from Path.
50/// If Path is a universal binary, this function will return a buffer for the
51/// slice compatible with Triple (if one is present).
52Expected<std::pair<std::unique_ptr<MemoryBuffer>, LinkableFileKind>>
54 StringRef Path, const Triple &TT, LoadArchives LA,
55 std::optional<StringRef> IdentifierOverride = std::nullopt);
56
57/// Load a compatible relocatable object (if available) from a MachO universal
58/// binary.
59/// Path is only used for error reporting. Identifier will be used to name the
60/// resulting buffer.
63 std::unique_ptr<MemoryBuffer> UBBuf,
64 const Triple &TT, LoadArchives LA,
65 StringRef UBPath,
66 StringRef Identifier);
67
68/// Utility for identifying the file-slice compatible with TT in a universal
69/// binary.
72
73/// Utility for identifying the file-slice compatible with TT in a universal
74/// binary.
77
78/// For use with StaticLibraryDefinitionGenerators.
80public:
82 : L(L), JD(JD), ObjCOnly(ObjCOnly) {}
83
85
86private:
87 ObjectLayer &L;
88 JITDylib &JD;
89 bool ObjCOnly;
90};
91
92} // namespace orc
93} // namespace llvm
94
95#endif // LLVM_EXECUTIONENGINE_ORC_MACHO_H
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
For use with StaticLibraryDefinitionGenerators.
Definition: MachO.h:79
ForceLoadMachOArchiveMembers(ObjectLayer &L, JITDylib &JD, bool ObjCOnly)
Definition: MachO.h:81
Error operator()(MemoryBufferRef MemberBuf)
Definition: MachO.cpp:232
Represents a JIT'd dynamic library.
Definition: Core.h:897
Interface for Layers that accept object files.
Definition: Layer.h:133
Expected< std::pair< std::unique_ptr< MemoryBuffer >, LinkableFileKind > > loadLinkableSliceFromMachOUniversalBinary(sys::fs::file_t FD, std::unique_ptr< MemoryBuffer > UBBuf, const Triple &TT, LoadArchives LA, StringRef UBPath, StringRef Identifier)
Load a compatible relocatable object (if available) from a MachO universal binary.
Definition: MachO.cpp:142
Expected< std::pair< std::unique_ptr< MemoryBuffer >, LinkableFileKind > > loadMachOLinkableFile(StringRef Path, const Triple &TT, LoadArchives LA, std::optional< StringRef > IdentifierOverride=std::nullopt)
Load a relocatable object compatible with TT from Path.
Error checkMachORelocatableObject(MemoryBufferRef Obj, const Triple &TT, bool ObjIsSlice)
Check that the given buffer contains a MachO object file compatible with the given triple.
Definition: MachO.cpp:58
Expected< std::pair< size_t, size_t > > getMachOSliceRangeForTriple(object::MachOUniversalBinary &UB, const Triple &TT)
Utility for identifying the file-slice compatible with TT in a universal binary.
Definition: MachO.cpp:202
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18