LLVM 24.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
18#include "llvm/Object/Archive.h"
20#include "llvm/Support/Error.h"
23
24namespace llvm {
25
26namespace object {
27
28class Archive;
30
31} // namespace object
32
33namespace orc {
34
36class JITDylib;
37class ObjectLayer;
38
39/// Check that the given buffer contains a MachO object file compatible with the
40/// given triple.
41/// ObjIsSlice should be set to true if Obj is a slice of a universal binary
42/// (that fact will then be reported in the error messages).
44 const Triple &TT, bool ObjIsSlice);
45
46/// Check that the given buffer contains a MachO object file compatible with the
47/// given triple.
48/// This convenience overload returns the buffer if it passes all checks,
49/// otherwise it returns an error.
50LLVM_ABI Expected<std::unique_ptr<MemoryBuffer>>
51checkMachORelocatableObject(std::unique_ptr<MemoryBuffer> Obj, const Triple &TT,
52 bool ObjIsSlice);
53
54/// Load a compatible relocatable object (if available) from a MachO universal
55/// binary.
56/// Path is only used for error reporting. Identifier will be used to name the
57/// resulting buffer.
58LLVM_ABI Expected<std::pair<std::unique_ptr<MemoryBuffer>, LinkableFileKind>>
60 std::unique_ptr<MemoryBuffer> UBBuf,
61 const Triple &TT, LoadArchives LA,
62 StringRef UBPath,
63 StringRef Identifier);
64
65/// Utility for identifying the file-slice compatible with TT in a universal
66/// binary.
67LLVM_ABI Expected<std::pair<size_t, size_t>>
68getMachOSliceRangeForTriple(object::MachOUniversalBinary &UB, const Triple &TT);
69
70/// Utility for identifying the file-slice compatible with TT in a universal
71/// binary.
72LLVM_ABI Expected<std::pair<size_t, size_t>>
73getMachOSliceRangeForTriple(MemoryBufferRef UBBuf, const Triple &TT);
74
75/// For use with StaticLibraryDefinitionGenerators.
77public:
79 : L(L), JD(JD), ObjCOnly(ObjCOnly) {}
80
82 MemoryBufferRef MemberBuf, size_t Index);
83
84private:
85 ObjectLayer &L;
86 JITDylib &JD;
87 bool ObjCOnly;
88};
89
92 uint32_t CPUType, uint32_t CPUSubType)>;
93
94/// Match the exact CPU type/subtype only.
96noFallbackArchs(uint32_t CPUType, uint32_t CPUSubType);
97
98/// Match standard dynamic loader fallback rules.
100standardMachOFallbackArchs(uint32_t CPUType, uint32_t CPUSubType);
101
102/// Returns a SymbolNameSet containing the exported symbols defined in the
103/// given dylib.
105 ExecutionSession &ES, Twine Path,
107
108/// Returns a SymbolNameSet containing the exported symbols defined in the
109/// relevant slice of the TapiUniversal file.
111 ExecutionSession &ES, Twine Path,
113
114/// Returns a SymbolNameSet containing the exported symbols defined in the
115/// relevant slice of the given file, which may be either a dylib or a tapi
116/// file.
118 ExecutionSession &ES, Twine Path,
120
121} // namespace orc
122} // namespace llvm
123
124#endif // LLVM_EXECUTIONENGINE_ORC_MACHO_H
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ABI
Definition Compiler.h:215
Tagged union holding either a T or a Error.
Definition Error.h:485
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
An ExecutionSession represents a running JIT program.
Definition Core.h:1111
ForceLoadMachOArchiveMembers(ObjectLayer &L, JITDylib &JD, bool ObjCOnly)
Definition MachO.h:78
LLVM_ABI Expected< bool > operator()(object::Archive &A, MemoryBufferRef MemberBuf, size_t Index)
Definition MachO.cpp:236
Represents a JIT'd dynamic library.
Definition Core.h:675
Interface for Layers that accept object files.
Definition Layer.h:131
unique_function is a type-erasing functor similar to std::function.
LLVM_ABI SmallVector< std::pair< uint32_t, uint32_t > > noFallbackArchs(uint32_t CPUType, uint32_t CPUSubType)
Match the exact CPU type/subtype only.
Definition MachO.cpp:287
LLVM_ABI Expected< SymbolNameSet > getDylibInterfaceFromTapiFile(ExecutionSession &ES, Twine Path, GetFallbackArchsFn GetFallbackArchs=standardMachOFallbackArchs)
Returns a SymbolNameSet containing the exported symbols defined in the relevant slice of the TapiUniv...
Definition MachO.cpp:390
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:146
unique_function< SmallVector< std::pair< uint32_t, uint32_t > >( uint32_t CPUType, uint32_t CPUSubType)> GetFallbackArchsFn
Definition MachO.h:90
LLVM_ABI SmallVector< std::pair< uint32_t, uint32_t > > standardMachOFallbackArchs(uint32_t CPUType, uint32_t CPUSubType)
Match standard dynamic loader fallback rules.
Definition MachO.cpp:294
LLVM_ABI Expected< SymbolNameSet > getDylibInterface(ExecutionSession &ES, Twine Path, GetFallbackArchsFn GetFallbackArchs=standardMachOFallbackArchs)
Returns a SymbolNameSet containing the exported symbols defined in the relevant slice of the given fi...
Definition MachO.cpp:439
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:62
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:206
LLVM_ABI Expected< SymbolNameSet > getDylibInterfaceFromDylib(ExecutionSession &ES, Twine Path, GetFallbackArchsFn GetFallbackArchs=standardMachOFallbackArchs)
Returns a SymbolNameSet containing the exported symbols defined in the given dylib.
Definition MachO.cpp:319
This is an optimization pass for GlobalISel generic memory operations.