brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · dcfdb5b Raw
46 lines · c
1//===-- Utils/ELF.h - Common ELF functionality ------------------*- 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-exception6//7//===----------------------------------------------------------------------===//8//9// Common ELF functionality for target plugins.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLVM_OPENMP_LIBOMPTARGET_PLUGINS_ELF_UTILS_H14#define LLVM_OPENMP_LIBOMPTARGET_PLUGINS_ELF_UTILS_H15 16#include "llvm/Object/ELF.h"17#include "llvm/Object/ELFObjectFile.h"18 19namespace utils {20namespace elf {21 22/// Returns true or false if the \p Buffer is an ELF file.23bool isELF(llvm::StringRef Buffer);24 25/// Returns the ELF e_machine value of the current compilation target.26uint16_t getTargetMachine();27 28/// Checks if the given \p Object is a valid ELF matching the e_machine value.29llvm::Expected<bool> checkMachine(llvm::StringRef Object, uint16_t EMachine);30 31/// Returns a pointer to the given \p Symbol inside of an ELF object.32llvm::Expected<const void *>33getSymbolAddress(const llvm::object::ELFSymbolRef &Symbol);34 35/// Returns the symbol associated with the \p Name in the \p ELFObj. It will36/// first search for the hash sections to identify symbols from the hash table.37/// If that fails it will fall back to a linear search in the case of an38/// executable file without a hash table.39llvm::Expected<std::optional<llvm::object::ELFSymbolRef>>40getSymbol(const llvm::object::ObjectFile &ELFObj, llvm::StringRef Name);41 42} // namespace elf43} // namespace utils44 45#endif // LLVM_OPENMP_LIBOMPTARGET_PLUGINS_ELF_UTILS_H46