blob: 4ec158c1405ffe23cca32a1493a21ec4b90b6cce [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001//===- ELFObjHandler.h ------------------------------------------*- 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-exception
6//
7//===-----------------------------------------------------------------------===/
8///
9/// This supports reading and writing of elf dynamic shared objects.
10///
11//===-----------------------------------------------------------------------===/
12
13#ifndef LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H
14#define LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H
15
16#include "llvm/InterfaceStub/ELFStub.h"
17#include "llvm/Object/ELFObjectFile.h"
18#include "llvm/Object/ELFTypes.h"
19#include "llvm/Support/FileSystem.h"
20
21namespace llvm {
22
23class MemoryBuffer;
24
25namespace elfabi {
26
27enum class ELFTarget { ELF32LE, ELF32BE, ELF64LE, ELF64BE };
28
29/// Attempt to read a binary ELF file from a MemoryBuffer.
30Expected<std::unique_ptr<ELFStub>> readELFFile(MemoryBufferRef Buf);
31
32/// Attempt to write a binary ELF stub.
33/// This function determines appropriate ELFType using the passed ELFTarget and
34/// then writes a binary ELF stub to a specified file path.
35///
36/// @param FilePath File path for writing the ELF binary.
37/// @param Stub Source ELFStub to generate a binary ELF stub from.
38/// @param OutputFormat Target ELFType to write binary as.
39/// @param WriteIfChanged Whether or not to preserve timestamp if
40/// the output stays the same.
41Error writeBinaryStub(StringRef FilePath, const ELFStub &Stub,
42 ELFTarget OutputFormat, bool WriteIfChanged = false);
43
44} // end namespace elfabi
45} // end namespace llvm
46
47#endif // LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H