LLVM 22.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/Object/Archive.h"
19#include "llvm/Support/Error.h"
22
23namespace llvm {
24
25namespace object {
26
27class Archive;
29
30} // namespace object
31
32namespace orc {
33
34class JITDylib;
35class ObjectLayer;
36
37/// Check that the given buffer contains a MachO object file compatible with the
38/// given triple.
39/// ObjIsSlice should be set to true if Obj is a slice of a universal binary
40/// (that fact will then be reported in the error messages).
42 const Triple &TT, bool ObjIsSlice);
43
44/// Check that the given buffer contains a MachO object file compatible with the
45/// given triple.
46/// This convenience overload returns the buffer if it passes all checks,
47/// otherwise it returns an error.
48LLVM_ABI Expected<std::unique_ptr<MemoryBuffer>>
49checkMachORelocatableObject(std::unique_ptr<MemoryBuffer> Obj, const Triple &TT,
50 bool ObjIsSlice);
51
52/// Load a relocatable object compatible with TT from Path.
53/// If Path is a universal binary, this function will return a buffer for the
54/// slice compatible with Triple (if one is present).
55LLVM_ABI Expected<std::pair<std::unique_ptr<MemoryBuffer>, LinkableFileKind>>
57 StringRef Path, const Triple &TT, LoadArchives LA,
58 std::optional<StringRef> IdentifierOverride = std::nullopt);
59
60/// Load a compatible relocatable object (if available) from a MachO universal
61/// binary.
62/// Path is only used for error reporting. Identifier will be used to name the
63/// resulting buffer.
66 std::unique_ptr<MemoryBuffer> UBBuf,
67 const Triple &TT, LoadArchives LA,
68 StringRef UBPath,
69 StringRef Identifier);
70
71/// Utility for identifying the file-slice compatible with TT in a universal
72/// binary.
75
76/// Utility for identifying the file-slice compatible with TT in a universal
77/// binary.
80
81/// For use with StaticLibraryDefinitionGenerators.
83public:
85 : L(L), JD(JD), ObjCOnly(ObjCOnly) {}
86
88 MemoryBufferRef MemberBuf, size_t Index);
89
90private:
91 ObjectLayer &L;
92 JITDylib &JD;
93 bool ObjCOnly;
94};
95
96} // namespace orc
97} // namespace llvm
98
99#endif // LLVM_EXECUTIONENGINE_ORC_MACHO_H
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ABI
Definition Compiler.h:213
Tagged union holding either a T or a Error.
Definition Error.h:485
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
ForceLoadMachOArchiveMembers(ObjectLayer &L, JITDylib &JD, bool ObjCOnly)
Definition MachO.h:84
LLVM_ABI Expected< bool > operator()(object::Archive &A, MemoryBufferRef MemberBuf, size_t Index)
Definition MachO.cpp:233
Represents a JIT'd dynamic library.
Definition Core.h:902
Interface for Layers that accept object files.
Definition Layer.h:134
LLVM_ABI 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:143
LLVM_ABI 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:59
LLVM_ABI 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:203
LLVM_ABI 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.
This is an optimization pass for GlobalISel generic memory operations.