ELFObjHandler.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ELFObjHandler.h ------------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===-----------------------------------------------------------------------===/
  13. ///
  14. /// This supports reading and writing of elf dynamic shared objects.
  15. ///
  16. //===-----------------------------------------------------------------------===/
  17. #ifndef LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H
  18. #define LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H
  19. #include "llvm/InterfaceStub/ELFStub.h"
  20. #include "llvm/Object/ELFObjectFile.h"
  21. #include "llvm/Object/ELFTypes.h"
  22. #include "llvm/Support/FileSystem.h"
  23. namespace llvm {
  24. class MemoryBuffer;
  25. namespace elfabi {
  26. enum class ELFTarget { ELF32LE, ELF32BE, ELF64LE, ELF64BE };
  27. /// Attempt to read a binary ELF file from a MemoryBuffer.
  28. Expected<std::unique_ptr<ELFStub>> readELFFile(MemoryBufferRef Buf);
  29. /// Attempt to write a binary ELF stub.
  30. /// This function determines appropriate ELFType using the passed ELFTarget and
  31. /// then writes a binary ELF stub to a specified file path.
  32. ///
  33. /// @param FilePath File path for writing the ELF binary.
  34. /// @param Stub Source ELFStub to generate a binary ELF stub from.
  35. /// @param OutputFormat Target ELFType to write binary as.
  36. /// @param WriteIfChanged Whether or not to preserve timestamp if
  37. /// the output stays the same.
  38. Error writeBinaryStub(StringRef FilePath, const ELFStub &Stub,
  39. ELFTarget OutputFormat, bool WriteIfChanged = false);
  40. } // end namespace elfabi
  41. } // end namespace llvm
  42. #endif // LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H
  43. #ifdef __GNUC__
  44. #pragma GCC diagnostic pop
  45. #endif