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
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 relocatable object compatible with TT from Path.
55/// If Path is a universal binary, this function will return a buffer for the
56/// slice compatible with Triple (if one is present).
57LLVM_ABI Expected<std::pair<std::unique_ptr<MemoryBuffer>, LinkableFileKind>>
59 StringRef Path, const Triple &TT, LoadArchives LA,
60 std::optional<StringRef> IdentifierOverride = std::nullopt);
61
62/// Load a compatible relocatable object (if available) from a MachO universal
63/// binary.
64/// Path is only used for error reporting. Identifier will be used to name the
65/// resulting buffer.
68 std::unique_ptr<MemoryBuffer> UBBuf,
69 const Triple &TT, LoadArchives LA,
70 StringRef UBPath,
71 StringRef Identifier);
72
73/// Utility for identifying the file-slice compatible with TT in a universal
74/// binary.
77
78/// Utility for identifying the file-slice compatible with TT in a universal
79/// binary.
82
83/// For use with StaticLibraryDefinitionGenerators.
85public:
87 : L(L), JD(JD), ObjCOnly(ObjCOnly) {}
88
90 MemoryBufferRef MemberBuf, size_t Index);
91
92private:
93 ObjectLayer &L;
94 JITDylib &JD;
95 bool ObjCOnly;
96};
97
100 uint32_t CPUType, uint32_t CPUSubType)>;
101
102/// Match the exact CPU type/subtype only.
104noFallbackArchs(uint32_t CPUType, uint32_t CPUSubType);
105
106/// Match standard dynamic loader fallback rules.
108standardMachOFallbackArchs(uint32_t CPUType, uint32_t CPUSubType);
109
110/// Returns a SymbolNameSet containing the exported symbols defined in the
111/// given dylib.
113 ExecutionSession &ES, Twine Path,
115
116/// Returns a SymbolNameSet containing the exported symbols defined in the
117/// relevant slice of the TapiUniversal file.
119 ExecutionSession &ES, Twine Path,
121
122/// Returns a SymbolNameSet containing the exported symbols defined in the
123/// relevant slice of the given file, which may be either a dylib or a tapi
124/// file.
126 ExecutionSession &ES, Twine Path,
128
129} // namespace orc
130} // namespace llvm
131
132#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
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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
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:1342
ForceLoadMachOArchiveMembers(ObjectLayer &L, JITDylib &JD, bool ObjCOnly)
Definition MachO.h:86
LLVM_ABI Expected< bool > operator()(object::Archive &A, MemoryBufferRef MemberBuf, size_t Index)
Definition MachO.cpp:235
Represents a JIT'd dynamic library.
Definition Core.h:906
Interface for Layers that accept object files.
Definition Layer.h:134
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:286
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:389
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:145
unique_function< SmallVector< std::pair< uint32_t, uint32_t > >( uint32_t CPUType, uint32_t CPUSubType)> GetFallbackArchsFn
Definition MachO.h:98
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:293
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:438
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:61
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:205
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.
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:318
This is an optimization pass for GlobalISel generic memory operations.