xref: /freebsd/contrib/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/LoadLinkableFile.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===--- LoadLinkableFile.h -- Load relocatables and archives ---*- 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 // A wrapper for `MemoryBuffer::getFile` / `MemoryBuffer::getFileSlice` that:
10 //
11 //   1. Handles relocatable object files, archives, and macho universal
12 //      binaries.
13 //   2. Adds file paths to errors by default.
14 //   3. Checks architecture compatibility up-front.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_EXECUTIONENGINE_ORC_LOADLINKABLEFILE_H
19 #define LLVM_EXECUTIONENGINE_ORC_LOADLINKABLEFILE_H
20 
21 #include "llvm/Support/Compiler.h"
22 #include "llvm/Support/Error.h"
23 #include "llvm/Support/MemoryBuffer.h"
24 #include "llvm/TargetParser/Triple.h"
25 
26 namespace llvm {
27 namespace orc {
28 
29 enum class LinkableFileKind { Archive, RelocatableObject };
30 
31 enum class LoadArchives {
32   Never,   // Linkable file must not be an archive.
33   Allowed, // Linkable file is allowed to be an archive.
34   Required // Linkable file is required to be an archive.
35 };
36 
37 /// Create a MemoryBuffer covering the "linkable" part of the given path.
38 ///
39 /// The path must contain a relocatable object file or universal binary, or
40 /// (if AllowArchives is true) an archive.
41 ///
42 /// If the path is a universal binary then it must contain a slice whose
43 /// architecture matches the architecture in the triple (an error will be
44 /// returned if there is no such slice, or if the triple does not specify an
45 /// architectur).
46 ///
47 /// If the path (or universal binary slice) is a relocatable object file then
48 /// its architecture must match the architecture in the triple (if given).
49 ///
50 /// If the path (or universal binary slice) is a relocatable object file then
51 /// its format must match the format in the triple (if given).
52 ///
53 /// No verification (e.g. architecture or format) is performed on the contents
54 /// of archives.
55 ///
56 /// If IdentifierOverride is provided then it will be used as the name of the
57 /// resulting buffer, rather than Path.
58 LLVM_ABI Expected<std::pair<std::unique_ptr<MemoryBuffer>, LinkableFileKind>>
59 loadLinkableFile(StringRef Path, const Triple &TT, LoadArchives LA,
60                  std::optional<StringRef> IdentifierOverride = std::nullopt);
61 
62 } // End namespace orc
63 } // End namespace llvm
64 
65 #endif // LLVM_EXECUTIONENGINE_ORC_LOADLINKABLEFILE_H
66