Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:53

0001 //===------------- MachO.h - MachO format utilities -------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Contains utilities for load MachO relocatable object files.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_EXECUTIONENGINE_ORC_MACHO_H
0014 #define LLVM_EXECUTIONENGINE_ORC_MACHO_H
0015 
0016 #include "llvm/ExecutionEngine/Orc/LoadLinkableFile.h"
0017 #include "llvm/Support/Error.h"
0018 #include "llvm/Support/MemoryBuffer.h"
0019 #include "llvm/TargetParser/Triple.h"
0020 
0021 namespace llvm {
0022 
0023 namespace object {
0024 
0025 class MachOUniversalBinary;
0026 
0027 } // namespace object
0028 
0029 namespace orc {
0030 
0031 class JITDylib;
0032 class ObjectLayer;
0033 
0034 /// Check that the given buffer contains a MachO object file compatible with the
0035 /// given triple.
0036 /// ObjIsSlice should be set to true if Obj is a slice of a universal binary
0037 /// (that fact will then be reported in the error messages).
0038 Error checkMachORelocatableObject(MemoryBufferRef Obj, const Triple &TT,
0039                                   bool ObjIsSlice);
0040 
0041 /// Check that the given buffer contains a MachO object file compatible with the
0042 /// given triple.
0043 /// This convenience overload returns the buffer if it passes all checks,
0044 /// otherwise it returns an error.
0045 Expected<std::unique_ptr<MemoryBuffer>>
0046 checkMachORelocatableObject(std::unique_ptr<MemoryBuffer> Obj, const Triple &TT,
0047                             bool ObjIsSlice);
0048 
0049 /// Load a relocatable object compatible with TT from Path.
0050 /// If Path is a universal binary, this function will return a buffer for the
0051 /// slice compatible with Triple (if one is present).
0052 Expected<std::pair<std::unique_ptr<MemoryBuffer>, LinkableFileKind>>
0053 loadMachOLinkableFile(
0054     StringRef Path, const Triple &TT, LoadArchives LA,
0055     std::optional<StringRef> IdentifierOverride = std::nullopt);
0056 
0057 /// Load a compatible relocatable object (if available) from a MachO universal
0058 /// binary.
0059 /// Path is only used for error reporting. Identifier will be used to name the
0060 /// resulting buffer.
0061 Expected<std::pair<std::unique_ptr<MemoryBuffer>, LinkableFileKind>>
0062 loadLinkableSliceFromMachOUniversalBinary(sys::fs::file_t FD,
0063                                           std::unique_ptr<MemoryBuffer> UBBuf,
0064                                           const Triple &TT, LoadArchives LA,
0065                                           StringRef UBPath,
0066                                           StringRef Identifier);
0067 
0068 /// Utility for identifying the file-slice compatible with TT in a universal
0069 /// binary.
0070 Expected<std::pair<size_t, size_t>>
0071 getMachOSliceRangeForTriple(object::MachOUniversalBinary &UB, const Triple &TT);
0072 
0073 /// Utility for identifying the file-slice compatible with TT in a universal
0074 /// binary.
0075 Expected<std::pair<size_t, size_t>>
0076 getMachOSliceRangeForTriple(MemoryBufferRef UBBuf, const Triple &TT);
0077 
0078 /// For use with StaticLibraryDefinitionGenerators.
0079 class ForceLoadMachOArchiveMembers {
0080 public:
0081   ForceLoadMachOArchiveMembers(ObjectLayer &L, JITDylib &JD, bool ObjCOnly)
0082       : L(L), JD(JD), ObjCOnly(ObjCOnly) {}
0083 
0084   Error operator()(MemoryBufferRef MemberBuf);
0085 
0086 private:
0087   ObjectLayer &L;
0088   JITDylib &JD;
0089   bool ObjCOnly;
0090 };
0091 
0092 } // namespace orc
0093 } // namespace llvm
0094 
0095 #endif // LLVM_EXECUTIONENGINE_ORC_MACHO_H