Path: blob/main/contrib/llvm-project/llvm/include/llvm-c/Object.h
35234 views
/*===-- llvm-c/Object.h - Object Lib C Iface --------------------*- C++ -*-===*/1/* */2/* Part of the LLVM Project, under the Apache License v2.0 with LLVM */3/* 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/* This header declares the C interface to libLLVMObject.a, which */10/* implements object file reading and writing. */11/* */12/* Many exotic languages can interoperate with C code but have a harder time */13/* with C++ due to name mangling. So in addition to C, this interface enables */14/* tools written in such languages. */15/* */16/*===----------------------------------------------------------------------===*/1718#ifndef LLVM_C_OBJECT_H19#define LLVM_C_OBJECT_H2021#include "llvm-c/ExternC.h"22#include "llvm-c/Types.h"23#include "llvm/Config/llvm-config.h"2425LLVM_C_EXTERN_C_BEGIN2627/**28* @defgroup LLVMCObject Object file reading and writing29* @ingroup LLVMC30*31* @{32*/3334// Opaque type wrappers35typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef;36typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;37typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;3839typedef enum {40LLVMBinaryTypeArchive, /**< Archive file. */41LLVMBinaryTypeMachOUniversalBinary, /**< Mach-O Universal Binary file. */42LLVMBinaryTypeCOFFImportFile, /**< COFF Import file. */43LLVMBinaryTypeIR, /**< LLVM IR. */44LLVMBinaryTypeWinRes, /**< Windows resource (.res) file. */45LLVMBinaryTypeCOFF, /**< COFF Object file. */46LLVMBinaryTypeELF32L, /**< ELF 32-bit, little endian. */47LLVMBinaryTypeELF32B, /**< ELF 32-bit, big endian. */48LLVMBinaryTypeELF64L, /**< ELF 64-bit, little endian. */49LLVMBinaryTypeELF64B, /**< ELF 64-bit, big endian. */50LLVMBinaryTypeMachO32L, /**< MachO 32-bit, little endian. */51LLVMBinaryTypeMachO32B, /**< MachO 32-bit, big endian. */52LLVMBinaryTypeMachO64L, /**< MachO 64-bit, little endian. */53LLVMBinaryTypeMachO64B, /**< MachO 64-bit, big endian. */54LLVMBinaryTypeWasm, /**< Web Assembly. */55LLVMBinaryTypeOffload, /**< Offloading fatbinary. */5657} LLVMBinaryType;5859/**60* Create a binary file from the given memory buffer.61*62* The exact type of the binary file will be inferred automatically, and the63* appropriate implementation selected. The context may be NULL except if64* the resulting file is an LLVM IR file.65*66* The memory buffer is not consumed by this function. It is the responsibilty67* of the caller to free it with \c LLVMDisposeMemoryBuffer.68*69* If NULL is returned, the \p ErrorMessage parameter is populated with the70* error's description. It is then the caller's responsibility to free this71* message by calling \c LLVMDisposeMessage.72*73* @see llvm::object::createBinary74*/75LLVMBinaryRef LLVMCreateBinary(LLVMMemoryBufferRef MemBuf,76LLVMContextRef Context,77char **ErrorMessage);7879/**80* Dispose of a binary file.81*82* The binary file does not own its backing buffer. It is the responsibilty83* of the caller to free it with \c LLVMDisposeMemoryBuffer.84*/85void LLVMDisposeBinary(LLVMBinaryRef BR);8687/**88* Retrieves a copy of the memory buffer associated with this object file.89*90* The returned buffer is merely a shallow copy and does not own the actual91* backing buffer of the binary. Nevertheless, it is the responsibility of the92* caller to free it with \c LLVMDisposeMemoryBuffer.93*94* @see llvm::object::getMemoryBufferRef95*/96LLVMMemoryBufferRef LLVMBinaryCopyMemoryBuffer(LLVMBinaryRef BR);9798/**99* Retrieve the specific type of a binary.100*101* @see llvm::object::Binary::getType102*/103LLVMBinaryType LLVMBinaryGetType(LLVMBinaryRef BR);104105/*106* For a Mach-O universal binary file, retrieves the object file corresponding107* to the given architecture if it is present as a slice.108*109* If NULL is returned, the \p ErrorMessage parameter is populated with the110* error's description. It is then the caller's responsibility to free this111* message by calling \c LLVMDisposeMessage.112*113* It is the responsiblity of the caller to free the returned object file by114* calling \c LLVMDisposeBinary.115*/116LLVMBinaryRef LLVMMachOUniversalBinaryCopyObjectForArch(LLVMBinaryRef BR,117const char *Arch,118size_t ArchLen,119char **ErrorMessage);120121/**122* Retrieve a copy of the section iterator for this object file.123*124* If there are no sections, the result is NULL.125*126* The returned iterator is merely a shallow copy. Nevertheless, it is127* the responsibility of the caller to free it with128* \c LLVMDisposeSectionIterator.129*130* @see llvm::object::sections()131*/132LLVMSectionIteratorRef LLVMObjectFileCopySectionIterator(LLVMBinaryRef BR);133134/**135* Returns whether the given section iterator is at the end.136*137* @see llvm::object::section_end138*/139LLVMBool LLVMObjectFileIsSectionIteratorAtEnd(LLVMBinaryRef BR,140LLVMSectionIteratorRef SI);141142/**143* Retrieve a copy of the symbol iterator for this object file.144*145* If there are no symbols, the result is NULL.146*147* The returned iterator is merely a shallow copy. Nevertheless, it is148* the responsibility of the caller to free it with149* \c LLVMDisposeSymbolIterator.150*151* @see llvm::object::symbols()152*/153LLVMSymbolIteratorRef LLVMObjectFileCopySymbolIterator(LLVMBinaryRef BR);154155/**156* Returns whether the given symbol iterator is at the end.157*158* @see llvm::object::symbol_end159*/160LLVMBool LLVMObjectFileIsSymbolIteratorAtEnd(LLVMBinaryRef BR,161LLVMSymbolIteratorRef SI);162163void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI);164165void LLVMMoveToNextSection(LLVMSectionIteratorRef SI);166void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,167LLVMSymbolIteratorRef Sym);168169// ObjectFile Symbol iterators170void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI);171void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI);172173// SectionRef accessors174const char *LLVMGetSectionName(LLVMSectionIteratorRef SI);175uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI);176const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI);177uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);178LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,179LLVMSymbolIteratorRef Sym);180181// Section Relocation iterators182LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section);183void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI);184LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,185LLVMRelocationIteratorRef RI);186void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI);187188189// SymbolRef accessors190const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);191uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);192uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);193194// RelocationRef accessors195uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI);196LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI);197uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI);198// NOTE: Caller takes ownership of returned string of the two199// following functions.200const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI);201const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI);202203/** Deprecated: Use LLVMBinaryRef instead. */204typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef;205206/** Deprecated: Use LLVMCreateBinary instead. */207LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);208209/** Deprecated: Use LLVMDisposeBinary instead. */210void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile);211212/** Deprecated: Use LLVMObjectFileCopySectionIterator instead. */213LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile);214215/** Deprecated: Use LLVMObjectFileIsSectionIteratorAtEnd instead. */216LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,217LLVMSectionIteratorRef SI);218219/** Deprecated: Use LLVMObjectFileCopySymbolIterator instead. */220LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile);221222/** Deprecated: Use LLVMObjectFileIsSymbolIteratorAtEnd instead. */223LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,224LLVMSymbolIteratorRef SI);225/**226* @}227*/228229LLVM_C_EXTERN_C_END230231#endif232233234