ELFStub.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ELFStub.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. /// \file
  15. /// This file defines an internal representation of an ELF stub.
  16. ///
  17. //===-----------------------------------------------------------------------===/
  18. #ifndef LLVM_TEXTAPI_ELF_ELFSTUB_H
  19. #define LLVM_TEXTAPI_ELF_ELFSTUB_H
  20. #include "llvm/BinaryFormat/ELF.h"
  21. #include "llvm/Support/VersionTuple.h"
  22. #include <set>
  23. #include <vector>
  24. namespace llvm {
  25. namespace elfabi {
  26. typedef uint16_t ELFArch;
  27. enum class ELFSymbolType {
  28. NoType = ELF::STT_NOTYPE,
  29. Object = ELF::STT_OBJECT,
  30. Func = ELF::STT_FUNC,
  31. TLS = ELF::STT_TLS,
  32. // Type information is 4 bits, so 16 is safely out of range.
  33. Unknown = 16,
  34. };
  35. struct ELFSymbol {
  36. ELFSymbol(std::string SymbolName) : Name(SymbolName) {}
  37. std::string Name;
  38. uint64_t Size;
  39. ELFSymbolType Type;
  40. bool Undefined;
  41. bool Weak;
  42. Optional<std::string> Warning;
  43. bool operator<(const ELFSymbol &RHS) const { return Name < RHS.Name; }
  44. };
  45. // A cumulative representation of ELF stubs.
  46. // Both textual and binary stubs will read into and write from this object.
  47. class ELFStub {
  48. // TODO: Add support for symbol versioning.
  49. public:
  50. VersionTuple TbeVersion;
  51. Optional<std::string> SoName;
  52. ELFArch Arch;
  53. std::vector<std::string> NeededLibs;
  54. std::set<ELFSymbol> Symbols;
  55. ELFStub() {}
  56. ELFStub(const ELFStub &Stub);
  57. ELFStub(ELFStub &&Stub);
  58. };
  59. } // end namespace elfabi
  60. } // end namespace llvm
  61. #endif // LLVM_TEXTAPI_ELF_ELFSTUB_H
  62. #ifdef __GNUC__
  63. #pragma GCC diagnostic pop
  64. #endif