LLVM 22.0.0git
Object.h
Go to the documentation of this file.
1/*===-- llvm-c/Object.h - Object Lib C Iface --------------------*- C++ -*-===*/
2/* */
3/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */
4/* Exceptions. */
5/* See https://llvm.org/LICENSE.txt for license information. */
6/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
7/* */
8/*===----------------------------------------------------------------------===*/
9/* */
10/* This header declares the C interface to libLLVMObject.a, which */
11/* implements object file reading and writing. */
12/* */
13/* Many exotic languages can interoperate with C code but have a harder time */
14/* with C++ due to name mangling. So in addition to C, this interface enables */
15/* tools written in such languages. */
16/* */
17/*===----------------------------------------------------------------------===*/
18
19#ifndef LLVM_C_OBJECT_H
20#define LLVM_C_OBJECT_H
21
22#include "llvm-c/ExternC.h"
23#include "llvm-c/Types.h"
24#include "llvm-c/Visibility.h"
25#include "llvm/Config/llvm-config.h"
26
28
29/**
30 * @defgroup LLVMCObject Object file reading and writing
31 * @ingroup LLVMC
32 *
33 * @{
34 */
35
36// Opaque type wrappers
37typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef;
38typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;
39typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;
40
41typedef enum {
42 LLVMBinaryTypeArchive, /**< Archive file. */
43 LLVMBinaryTypeMachOUniversalBinary, /**< Mach-O Universal Binary file. */
44 LLVMBinaryTypeCOFFImportFile, /**< COFF Import file. */
45 LLVMBinaryTypeIR, /**< LLVM IR. */
46 LLVMBinaryTypeWinRes, /**< Windows resource (.res) file. */
47 LLVMBinaryTypeCOFF, /**< COFF Object file. */
48 LLVMBinaryTypeELF32L, /**< ELF 32-bit, little endian. */
49 LLVMBinaryTypeELF32B, /**< ELF 32-bit, big endian. */
50 LLVMBinaryTypeELF64L, /**< ELF 64-bit, little endian. */
51 LLVMBinaryTypeELF64B, /**< ELF 64-bit, big endian. */
52 LLVMBinaryTypeMachO32L, /**< MachO 32-bit, little endian. */
53 LLVMBinaryTypeMachO32B, /**< MachO 32-bit, big endian. */
54 LLVMBinaryTypeMachO64L, /**< MachO 64-bit, little endian. */
55 LLVMBinaryTypeMachO64B, /**< MachO 64-bit, big endian. */
56 LLVMBinaryTypeWasm, /**< Web Assembly. */
57 LLVMBinaryTypeOffload, /**< Offloading fatbinary. */
58 LLVMBinaryTypeDXcontainer, /**< DirectX Binary Container. */
59
61
62/**
63 * Create a binary file from the given memory buffer.
64 *
65 * The exact type of the binary file will be inferred automatically, and the
66 * appropriate implementation selected. The context may be NULL except if
67 * the resulting file is an LLVM IR file.
68 *
69 * The memory buffer is not consumed by this function. It is the responsibilty
70 * of the caller to free it with \c LLVMDisposeMemoryBuffer.
71 *
72 * If NULL is returned, the \p ErrorMessage parameter is populated with the
73 * error's description. It is then the caller's responsibility to free this
74 * message by calling \c LLVMDisposeMessage.
75 *
76 * @see llvm::object::createBinary
77 */
79 LLVMContextRef Context,
80 char **ErrorMessage);
81
82/**
83 * Dispose of a binary file.
84 *
85 * The binary file does not own its backing buffer. It is the responsibilty
86 * of the caller to free it with \c LLVMDisposeMemoryBuffer.
87 */
89
90/**
91 * Retrieves a copy of the memory buffer associated with this object file.
92 *
93 * The returned buffer is merely a shallow copy and does not own the actual
94 * backing buffer of the binary. Nevertheless, it is the responsibility of the
95 * caller to free it with \c LLVMDisposeMemoryBuffer.
96 *
97 * @see llvm::object::getMemoryBufferRef
98 */
100
101/**
102 * Retrieve the specific type of a binary.
103 *
104 * @see llvm::object::Binary::getType
105 */
107
108/*
109 * For a Mach-O universal binary file, retrieves the object file corresponding
110 * to the given architecture if it is present as a slice.
111 *
112 * If NULL is returned, the \p ErrorMessage parameter is populated with the
113 * error's description. It is then the caller's responsibility to free this
114 * message by calling \c LLVMDisposeMessage.
115 *
116 * It is the responsiblity of the caller to free the returned object file by
117 * calling \c LLVMDisposeBinary.
118 */
120 LLVMBinaryRef BR, const char *Arch, size_t ArchLen, char **ErrorMessage);
121
122/**
123 * Retrieve a copy of the section iterator for this object file.
124 *
125 * If there are no sections, the result is NULL.
126 *
127 * The returned iterator is merely a shallow copy. Nevertheless, it is
128 * the responsibility of the caller to free it with
129 * \c LLVMDisposeSectionIterator.
130 *
131 * @see llvm::object::sections()
132 */
135
136/**
137 * Returns whether the given section iterator is at the end.
138 *
139 * @see llvm::object::section_end
140 */
143
144/**
145 * Retrieve a copy of the symbol iterator for this object file.
146 *
147 * If there are no symbols, the result is NULL.
148 *
149 * The returned iterator is merely a shallow copy. Nevertheless, it is
150 * the responsibility of the caller to free it with
151 * \c LLVMDisposeSymbolIterator.
152 *
153 * @see llvm::object::symbols()
154 */
157
158/**
159 * Returns whether the given symbol iterator is at the end.
160 *
161 * @see llvm::object::symbol_end
162 */
165
167
171
172// ObjectFile Symbol iterators
175
176// SectionRef accessors
183
184// Section Relocation iterators
191
192// SymbolRef accessors
196
197// RelocationRef accessors
202// NOTE: Caller takes ownership of returned string of the two
203// following functions.
205LLVM_C_ABI const char *
207
208/** Deprecated: Use LLVMBinaryRef instead. */
209typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef;
210
211/** Deprecated: Use LLVMCreateBinary instead. */
213
214/** Deprecated: Use LLVMDisposeBinary instead. */
216
217/** Deprecated: Use LLVMObjectFileCopySectionIterator instead. */
219
220/** Deprecated: Use LLVMObjectFileIsSectionIteratorAtEnd instead. */
223
224/** Deprecated: Use LLVMObjectFileCopySymbolIterator instead. */
226
227/** Deprecated: Use LLVMObjectFileIsSymbolIteratorAtEnd instead. */
230/**
231 * @}
232 */
233
235
236#endif
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define LLVM_C_EXTERN_C_BEGIN
Definition: ExternC.h:35
#define LLVM_C_EXTERN_C_END
Definition: ExternC.h:36
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
#define LLVM_C_ABI
LLVM_C_ABI is the export/visibility macro used to mark symbols declared in llvm-c as exported when bu...
Definition: Visibility.h:40
LLVM_C_ABI void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI)
Definition: Object.cpp:298
LLVM_C_ABI void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI)
Definition: Object.cpp:208
LLVM_C_ABI uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI)
Definition: Object.cpp:326
LLVM_C_ABI LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile)
Deprecated: Use LLVMObjectFileCopySymbolIterator instead.
Definition: Object.cpp:235
LLVM_C_ABI uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI)
Definition: Object.cpp:274
LLVM_C_ABI LLVMBool LLVMObjectFileIsSymbolIteratorAtEnd(LLVMBinaryRef BR, LLVMSymbolIteratorRef SI)
Returns whether the given symbol iterator is at the end.
Definition: Object.cpp:176
struct LLVMOpaqueSymbolIterator * LLVMSymbolIteratorRef
Definition: Object.h:38
LLVM_C_ABI LLVMBinaryRef LLVMMachOUniversalBinaryCopyObjectForArch(LLVMBinaryRef BR, const char *Arch, size_t ArchLen, char **ErrorMessage)
Definition: Object.cpp:140
LLVM_C_ABI uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI)
Definition: Object.cpp:315
LLVM_C_ABI uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI)
Definition: Object.cpp:263
LLVM_C_ABI LLVMSymbolIteratorRef LLVMObjectFileCopySymbolIterator(LLVMBinaryRef BR)
Retrieve a copy of the symbol iterator for this object file.
Definition: Object.cpp:168
LLVM_C_ABI uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI)
Definition: Object.cpp:340
LLVM_C_ABI const char * LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI)
Definition: Object.cpp:354
LLVM_C_ABI void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, LLVMSymbolIteratorRef Sym)
Definition: Object.cpp:222
LLVM_C_ABI void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI)
Definition: Object.cpp:241
LLVM_C_ABI LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, LLVMSectionIteratorRef SI)
Deprecated: Use LLVMObjectFileIsSectionIteratorAtEnd instead.
Definition: Object.cpp:212
LLVM_C_ABI void LLVMMoveToNextSection(LLVMSectionIteratorRef SI)
Definition: Object.cpp:218
LLVM_C_ABI LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI)
Definition: Object.cpp:335
LLVM_C_ABI const char * LLVMGetSymbolName(LLVMSymbolIteratorRef SI)
Definition: Object.cpp:304
LLVM_C_ABI uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI)
Definition: Object.cpp:331
LLVM_C_ABI void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI)
Definition: Object.cpp:289
LLVM_C_ABI LLVMSectionIteratorRef LLVMObjectFileCopySectionIterator(LLVMBinaryRef BR)
Retrieve a copy of the section iterator for this object file.
Definition: Object.cpp:154
LLVM_C_ABI LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile)
Deprecated: Use LLVMObjectFileCopySectionIterator instead.
Definition: Object.cpp:202
LLVM_C_ABI LLVMBinaryType LLVMBinaryGetType(LLVMBinaryRef BR)
Retrieve the specific type of a binary.
Definition: Object.cpp:90
LLVM_C_ABI LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section)
Definition: Object.cpp:284
LLVM_C_ABI void LLVMDisposeBinary(LLVMBinaryRef BR)
Dispose of a binary file.
Definition: Object.cpp:86
struct LLVMOpaqueSectionIterator * LLVMSectionIteratorRef
Definition: Object.h:37
LLVMBinaryType
Definition: Object.h:41
LLVM_C_ABI const char * LLVMGetSectionName(LLVMSectionIteratorRef SI)
Definition: Object.cpp:256
LLVM_C_ABI LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section, LLVMRelocationIteratorRef RI)
Definition: Object.cpp:293
LLVM_C_ABI LLVMMemoryBufferRef LLVMBinaryCopyMemoryBuffer(LLVMBinaryRef BR)
Retrieves a copy of the memory buffer associated with this object file.
Definition: Object.cpp:79
struct LLVMOpaqueRelocationIterator * LLVMRelocationIteratorRef
Definition: Object.h:39
LLVM_C_ABI const char * LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI)
Definition: Object.cpp:345
struct LLVMOpaqueObjectFile * LLVMObjectFileRef
Deprecated: Use LLVMBinaryRef instead.
Definition: Object.h:209
LLVM_C_ABI LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile, LLVMSymbolIteratorRef SI)
Deprecated: Use LLVMObjectFileIsSymbolIteratorAtEnd instead.
Definition: Object.cpp:245
LLVM_C_ABI LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf)
Deprecated: Use LLVMCreateBinary instead.
Definition: Object.cpp:183
LLVM_C_ABI LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, LLVMSymbolIteratorRef Sym)
Definition: Object.cpp:278
LLVM_C_ABI void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile)
Deprecated: Use LLVMDisposeBinary instead.
Definition: Object.cpp:197
LLVM_C_ABI const char * LLVMGetSectionContents(LLVMSectionIteratorRef SI)
Definition: Object.cpp:267
LLVM_C_ABI LLVMBinaryRef LLVMCreateBinary(LLVMMemoryBufferRef MemBuf, LLVMContextRef Context, char **ErrorMessage)
Create a binary file from the given memory buffer.
Definition: Object.cpp:65
LLVM_C_ABI void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI)
Definition: Object.cpp:251
LLVM_C_ABI LLVMBool LLVMObjectFileIsSectionIteratorAtEnd(LLVMBinaryRef BR, LLVMSectionIteratorRef SI)
Returns whether the given section iterator is at the end.
Definition: Object.cpp:162
@ LLVMBinaryTypeIR
LLVM IR.
Definition: Object.h:45
@ LLVMBinaryTypeDXcontainer
DirectX Binary Container.
Definition: Object.h:58
@ LLVMBinaryTypeELF64B
ELF 64-bit, big endian.
Definition: Object.h:51
@ LLVMBinaryTypeArchive
Archive file.
Definition: Object.h:42
@ LLVMBinaryTypeMachO32B
MachO 32-bit, big endian.
Definition: Object.h:53
@ LLVMBinaryTypeWasm
Web Assembly.
Definition: Object.h:56
@ LLVMBinaryTypeELF64L
ELF 64-bit, little endian.
Definition: Object.h:50
@ LLVMBinaryTypeWinRes
Windows resource (.res) file.
Definition: Object.h:46
@ LLVMBinaryTypeMachOUniversalBinary
Mach-O Universal Binary file.
Definition: Object.h:43
@ LLVMBinaryTypeMachO64B
MachO 64-bit, big endian.
Definition: Object.h:55
@ LLVMBinaryTypeCOFF
COFF Object file.
Definition: Object.h:47
@ LLVMBinaryTypeCOFFImportFile
COFF Import file.
Definition: Object.h:44
@ LLVMBinaryTypeELF32B
ELF 32-bit, big endian.
Definition: Object.h:49
@ LLVMBinaryTypeELF32L
ELF 32-bit, little endian.
Definition: Object.h:48
@ LLVMBinaryTypeMachO32L
MachO 32-bit, little endian.
Definition: Object.h:52
@ LLVMBinaryTypeMachO64L
MachO 64-bit, little endian.
Definition: Object.h:54
@ LLVMBinaryTypeOffload
Offloading fatbinary.
Definition: Object.h:57
int LLVMBool
Definition: Types.h:28
struct LLVMOpaqueBinary * LLVMBinaryRef
Definition: Types.h:170
struct LLVMOpaqueMemoryBuffer * LLVMMemoryBufferRef
LLVM uses a polymorphic type hierarchy which C cannot represent, therefore parameters must be passed ...
Definition: Types.h:48
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
Definition: Types.h:53