Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===------- MachO.h - Generic JIT link function for MachO ------*- 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 // Generic jit-link functions for MachO.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_EXECUTIONENGINE_JITLINK_MACHO_H
0014 #define LLVM_EXECUTIONENGINE_JITLINK_MACHO_H
0015 
0016 #include "llvm/ExecutionEngine/JITLink/JITLink.h"
0017 #include "llvm/ExecutionEngine/Orc/Shared/MachOObjectFormat.h"
0018 
0019 namespace llvm {
0020 namespace jitlink {
0021 
0022 /// Create a LinkGraph from a MachO relocatable object.
0023 ///
0024 /// Note: The graph does not take ownership of the underlying buffer, nor copy
0025 /// its contents. The caller is responsible for ensuring that the object buffer
0026 /// outlives the graph.
0027 Expected<std::unique_ptr<LinkGraph>>
0028 createLinkGraphFromMachOObject(MemoryBufferRef ObjectBuffer,
0029                                std::shared_ptr<orc::SymbolStringPool> SSP);
0030 
0031 /// jit-link the given ObjBuffer, which must be a MachO object file.
0032 ///
0033 /// Uses conservative defaults for GOT and stub handling based on the target
0034 /// platform.
0035 void link_MachO(std::unique_ptr<LinkGraph> G,
0036                 std::unique_ptr<JITLinkContext> Ctx);
0037 
0038 /// Get a pointer to the standard MachO data section (creates an empty
0039 /// section with RW- permissions and standard lifetime if one does not
0040 /// already exist).
0041 inline Section &getMachODefaultRWDataSection(LinkGraph &G) {
0042   if (auto *DataSec = G.findSectionByName(orc::MachODataDataSectionName))
0043     return *DataSec;
0044   return G.createSection(orc::MachODataDataSectionName,
0045                          orc::MemProt::Read | orc::MemProt::Write);
0046 }
0047 
0048 /// Get a pointer to the standard MachO text section (creates an empty
0049 /// section with R-X permissions and standard lifetime if one does not
0050 /// already exist).
0051 inline Section &getMachODefaultTextSection(LinkGraph &G) {
0052   if (auto *TextSec = G.findSectionByName(orc::MachOTextTextSectionName))
0053     return *TextSec;
0054   return G.createSection(orc::MachOTextTextSectionName,
0055                          orc::MemProt::Read | orc::MemProt::Exec);
0056 }
0057 
0058 /// Gets or creates a MachO header for the current LinkGraph.
0059 Expected<Symbol &> getOrCreateLocalMachOHeader(LinkGraph &G);
0060 
0061 } // end namespace jitlink
0062 } // end namespace llvm
0063 
0064 #endif // LLVM_EXECUTIONENGINE_JITLINK_MACHO_H