LLVM: lib/Object/ObjectFile.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

28#include

29#include

30#include <system_error>

31

32using namespace llvm;

33using namespace object;

34

41

42void ObjectFile::anchor() {}

43

46

49 if (!SymSec) {

50

52 return false;

53 }

54 return *this == **SymSec;

55}

56

60

61 return std::move(E);

62

64 return 0;

68}

69

72 if (!Name)

73 return Name.takeError();

74 OS << *Name;

76}

77

79

82 if (NameOrErr)

83 return *NameOrErr == ".llvm.lto";

85 return false;

86}

87

89

93

97

99

104

109

114

115 auto OS = getOS();

117 TheTriple.setOS(OS);

118

119

120

121

124

125

126

129 } else if (isCOFF()) {

132 TheTriple.setTriple("thumbv7-windows");

134

137 } else if (isGOFF()) {

140 } else if (TheTriple.isAMDGPU()) {

142 } else if (TheTriple.isNVPTX()) {

144 }

145

146 return TheTriple;

147}

148

151 bool InitContent) {

155

156 switch (Type) {

206 }

208}

209

214 if (std::error_code EC = FileOrErr.getError())

216 std::unique_ptr Buffer = std::move(FileOrErr.get());

217

221 return std::move(Err);

222 std::unique_ptr Obj = std::move(ObjOrErr.get());

223

225}

226

229 const {

231 return ReflectionSectionKind == Swift5ReflectionSectionKind::fieldmd ||

232 ReflectionSectionKind == Swift5ReflectionSectionKind::reflstr ||

233 ReflectionSectionKind == Swift5ReflectionSectionKind::assocty;

234}

Provides ErrorOr smart pointer.

Represents either an error or a value T.

std::error_code getError() const

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

Tagged union holding either a T or a Error.

Error takeError()

Take ownership of the stored error.

reference get()

Returns a reference to the stored T value.

static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)

Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...

StringRef - Represent a constant reference to a string, i.e.

Triple - Helper class for working with autoconf configuration names.

LLVM_ABI void setObjectFormat(ObjectFormatType Kind)

Set the object file format.

LLVM_ABI void setTriple(const Twine &Str)

Set all components to the new triple Str.

bool isNVPTX() const

Tests whether the target is NVPTX (32- or 64-bit).

LLVM_ABI void setOS(OSType Kind)

Set the operating system (third) component of the triple to a known type.

LLVM_ABI void setArch(ArchType Kind, SubArchType SubArch=NoSubArch)

Set the architecture (first) component of the triple to a known type.

LLVM_ABI void setVendor(VendorType Kind)

Set the vendor (second) component of the triple to a known type.

The instances of the Type class are immutable: once they are created, they are never changed.

virtual bool isBerkeleyText(DataRefImpl Sec) const

Definition ObjectFile.cpp:90

virtual Expected< section_iterator > getRelocatedSection(DataRefImpl Sec) const

Definition ObjectFile.cpp:106

uint64_t getCommonSymbolSize(DataRefImpl Symb) const

static Expected< std::unique_ptr< DXContainerObjectFile > > createDXContainerObjectFile(MemoryBufferRef Object)

virtual Expected< StringRef > getSectionName(DataRefImpl Sec) const =0

virtual bool isBerkeleyData(DataRefImpl Sec) const

Definition ObjectFile.cpp:94

virtual Expected< StringRef > getSymbolName(DataRefImpl Symb) const =0

static Expected< std::unique_ptr< MachOObjectFile > > createMachOObjectFile(MemoryBufferRef Object, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0, size_t MachOFilesetEntryOffset=0)

Create a MachOObjectFile instance from a given buffer.

static Expected< std::unique_ptr< COFFObjectFile > > createCOFFObjectFile(MemoryBufferRef Object)

Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override

Definition ObjectFile.cpp:70

static Expected< std::unique_ptr< ObjectFile > > createELFObjectFile(MemoryBufferRef Object, bool InitContent=true)

Triple makeTriple() const

Create a triple from the data in this object file.

Definition ObjectFile.cpp:110

virtual bool isSectionText(DataRefImpl Sec) const =0

section_iterator_range sections() const

virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const =0

virtual bool isDebugSection(DataRefImpl Sec) const

Definition ObjectFile.cpp:98

virtual void setARMSubArch(Triple &TheTriple) const

static Expected< std::unique_ptr< WasmObjectFile > > createWasmObjectFile(MemoryBufferRef Object)

static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)

Definition ObjectFile.cpp:211

virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const

Definition ObjectFile.cpp:78

virtual bool isSectionData(DataRefImpl Sec) const =0

Expected< uint64_t > getSymbolValue(DataRefImpl Symb) const

Definition ObjectFile.cpp:57

virtual Triple::OSType getOS() const

bool isReflectionSectionStrippable(llvm::binaryformat::Swift5ReflectionSectionKind ReflectionSectionKind) const

True if the reflection section can be stripped by the linker.

Definition ObjectFile.cpp:227

virtual bool hasDebugInfo() const

Definition ObjectFile.cpp:100

static Expected< std::unique_ptr< ObjectFile > > createXCOFFObjectFile(MemoryBufferRef Object, unsigned FileType)

virtual Triple::ArchType getArch() const =0

virtual bool isSectionStripped(DataRefImpl Sec) const

Definition ObjectFile.cpp:88

virtual bool isSectionBitcode(DataRefImpl Sec) const

Definition ObjectFile.cpp:80

bool isDebugSection() const

Whether this section is a debug section.

LLVM_ABI bool containsSymbol(SymbolRef S) const

Definition ObjectFile.cpp:47

Expected< section_iterator > getSection() const

Get section this symbol is defined in reference to.

SymbolicFile(unsigned int Type, MemoryBufferRef Source)

virtual Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const =0

This class implements an extremely fast bulk output stream that can only output to a stream.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

Swift5ReflectionSectionKind

content_iterator< SectionRef > section_iterator

LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const SectionedAddress &Addr)

Definition ObjectFile.cpp:35

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI file_magic identify_magic(StringRef magic)

Identify the type of a binary file based on how magical it is.

bool any_of(R &&range, UnaryPredicate P)

Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.

FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)

format_hex - Output N as a fixed width hexadecimal.

@ Ref

The access may reference the value stored in memory.

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

LLVM_ABI Error errorCodeToError(std::error_code EC)

Helper for converting an std::error_code to a Error.

void consumeError(Error Err)

Consume a Error without doing anything.

file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...

@ coff_import_library

COFF import library.

@ pdb

Windows PDB debug info file.

@ spirv_object

A binary SPIR-V file.

@ elf_relocatable

ELF Relocatable object file.

@ archive

ar style archive file

@ elf_shared_object

ELF dynamically linked shared lib.

@ goff_object

GOFF object file.

@ minidump

Windows minidump file.

@ macho_dynamically_linked_shared_lib

Mach-O dynlinked shared lib.

@ xcoff_object_64

64-bit XCOFF object file

@ elf_executable

ELF Executable image.

@ macho_dynamically_linked_shared_lib_stub

Mach-O Shared lib stub.

@ macho_preload_executable

Mach-O Preloaded Executable.

@ offload_bundle

Clang offload bundle file.

@ offload_bundle_compressed

Compressed clang offload bundle file.

@ macho_file_set

Mach-O file set binary.

@ dxcontainer_object

DirectX container file.

@ macho_kext_bundle

Mach-O kext bundle file.

@ pecoff_executable

PECOFF executable file.

@ offload_binary

LLVM offload object file.

@ macho_universal_binary

Mach-O universal binary.

@ macho_core

Mach-O Core File.

@ wasm_object

WebAssembly Object file.

@ xcoff_object_32

32-bit XCOFF object file

@ windows_resource

Windows compiled resource file (.res)

@ clang_ast

Clang PCH or PCM.

@ elf_core

ELF core image.

@ macho_object

Mach-O Object file.

@ coff_object

COFF object file.

@ macho_bundle

Mach-O Bundle file.

@ coff_cl_gl_object

Microsoft cl.exe's intermediate code file.

@ cuda_fatbinary

CUDA Fatbinary object file.

@ macho_executable

Mach-O Executable.

@ macho_dsym_companion

Mach-O dSYM companion file.

@ unknown

Unrecognized file.

@ macho_fixed_virtual_memory_shared_lib

Mach-O Shared Lib, FVM.

@ macho_dynamic_linker

The Mach-O dynamic linker.

@ tapi_file

Text-based Dynamic Library Stub file.

static const uint64_t UndefSection