• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "llvm/Support/Error.h"
17 #include "llvm/Support/MemoryBuffer.h"
18 #include "llvm/TargetParser/Triple.h"
19 
20 namespace llvm {
21 
22 namespace object {
23 
24 class MachOUniversalBinary;
25 
26 } // namespace object
27 
28 namespace orc {
29 
30 /// Check that the given buffer contains a MachO object file compatible with the
31 /// given triple.
32 /// ObjIsSlice should be set to true if Obj is a slice of a universal binary
33 /// (that fact will then be reported in the error messages).
34 Error checkMachORelocatableObject(MemoryBufferRef Obj, const Triple &TT,
35                                   bool ObjIsSlice);
36 
37 /// Check that the given buffer contains a MachO object file compatible with the
38 /// given triple.
39 /// This convenience overload returns the buffer if it passes all checks,
40 /// otherwise it returns an error.
41 Expected<std::unique_ptr<MemoryBuffer>>
42 checkMachORelocatableObject(std::unique_ptr<MemoryBuffer> Obj, const Triple &TT,
43                             bool ObjIsSlice);
44 
45 /// Load a relocatable object compatible with TT from Path.
46 /// If Path is a universal binary, this function will return a buffer for the
47 /// slice compatible with Triple (if one is present).
48 Expected<std::unique_ptr<MemoryBuffer>> loadMachORelocatableObject(
49     StringRef Path, const Triple &TT,
50     std::optional<StringRef> IdentifierOverride = std::nullopt);
51 
52 /// Load a compatible relocatable object (if available) from a MachO universal
53 /// binary.
54 Expected<std::unique_ptr<MemoryBuffer>>
55 loadMachORelocatableObjectFromUniversalBinary(
56     StringRef UBPath, std::unique_ptr<MemoryBuffer> UBBuf, const Triple &TT,
57     std::optional<StringRef> IdentifierOverride = std::nullopt);
58 
59 /// Utility for identifying the file-slice compatible with TT in a universal
60 /// binary.
61 Expected<std::pair<size_t, size_t>>
62 getMachOSliceRangeForTriple(object::MachOUniversalBinary &UB, const Triple &TT);
63 
64 /// Utility for identifying the file-slice compatible with TT in a universal
65 /// binary.
66 Expected<std::pair<size_t, size_t>>
67 getMachOSliceRangeForTriple(MemoryBufferRef UBBuf, const Triple &TT);
68 
69 } // namespace orc
70 } // namespace llvm
71 
72 #endif // LLVM_EXECUTIONENGINE_ORC_MACHO_H
73