ELFStub.h 1.7 KB

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