1//===------- LoadLinkableFile.cpp -- Load relocatables and archives -------===// 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 7//===----------------------------------------------------------------------===// 16#define DEBUG_TYPE "orc" 21static Expected<std::unique_ptr<MemoryBuffer>>
24// TODO: Actually check the architecture of the file. 30// TODO: Actually check the architecture of the file. 36 std::optional<StringRef> IdentifierOverride) {
37if (!IdentifierOverride)
38 IdentifierOverride = Path;
50return make_error<StringError>(
51StringRef(
"Could not load object at path ") + Path, Buf.getError());
53 std::optional<Triple::ObjectFormatType> RequireFormat;
55 RequireFormat = TT.getObjectFormat();
61return make_error<StringError>(
62 Path +
" does not contain a relocatable object file",
66return make_error<StringError>(Path +
" does not contain an archive",
72return CheckedBuf.takeError();
73return std::make_pair(std::move(*CheckedBuf),
79return make_error<StringError>(Path +
" does not contain an archive",
82if (!RequireFormat || *RequireFormat ==
Triple::ELF) {
85return CheckedBuf.takeError();
86return std::make_pair(std::move(*CheckedBuf),
92return make_error<StringError>(Path +
" does not contain an archive",
98return CheckedBuf.takeError();
99return std::make_pair(std::move(*CheckedBuf),
106 FD, std::move(*Buf), TT, LA, Path, *IdentifierOverride);
112return make_error<StringError>(
114" does not contain a relocatable object file or archive compatible " 120}
// End namespace orc. 121}
// End namespace llvm. This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Given an already-open file descriptor, read the file and return a MemoryBuffer.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
Expected< std::pair< std::unique_ptr< MemoryBuffer >, LinkableFileKind > > loadLinkableFile(StringRef Path, const Triple &TT, LoadArchives LA, std::optional< StringRef > IdentifierOverride=std::nullopt)
Create a MemoryBuffer covering the "linkable" part of the given path.
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.
static Expected< std::unique_ptr< MemoryBuffer > > checkCOFFRelocatableObject(std::unique_ptr< MemoryBuffer > Obj, const Triple &TT)
Error checkMachORelocatableObject(MemoryBufferRef Obj, const Triple &TT, bool ObjIsSlice)
Check that the given buffer contains a MachO object file compatible with the given triple.
static Expected< std::unique_ptr< MemoryBuffer > > checkELFRelocatableObject(std::unique_ptr< MemoryBuffer > Obj, const Triple &TT)
std::error_code closeFile(file_t &F)
Close the file object.
Expected< file_t > openNativeFileForRead(const Twine &Name, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
This is an optimization pass for GlobalISel generic memory operations.
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
@ elf_relocatable
ELF Relocatable object file.
@ archive
ar style archive file
@ macho_universal_binary
Mach-O universal binary.
@ macho_object
Mach-O Object file.
@ coff_object
COFF object file.