IFSStub.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //===- IFSStub.cpp --------------------------------------------------------===//
  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. #include "llvm/InterfaceStub/IFSStub.h"
  9. #include "llvm/BinaryFormat/ELF.h"
  10. #include "llvm/Support/ErrorHandling.h"
  11. using namespace llvm;
  12. using namespace llvm::ifs;
  13. IFSStub::IFSStub(IFSStub const &Stub) {
  14. IfsVersion = Stub.IfsVersion;
  15. Target = Stub.Target;
  16. SoName = Stub.SoName;
  17. NeededLibs = Stub.NeededLibs;
  18. Symbols = Stub.Symbols;
  19. }
  20. IFSStub::IFSStub(IFSStub &&Stub) {
  21. IfsVersion = std::move(Stub.IfsVersion);
  22. Target = std::move(Stub.Target);
  23. SoName = std::move(Stub.SoName);
  24. NeededLibs = std::move(Stub.NeededLibs);
  25. Symbols = std::move(Stub.Symbols);
  26. }
  27. IFSStubTriple::IFSStubTriple(IFSStubTriple const &Stub) : IFSStub() {
  28. IfsVersion = Stub.IfsVersion;
  29. Target = Stub.Target;
  30. SoName = Stub.SoName;
  31. NeededLibs = Stub.NeededLibs;
  32. Symbols = Stub.Symbols;
  33. }
  34. IFSStubTriple::IFSStubTriple(IFSStub const &Stub) {
  35. IfsVersion = Stub.IfsVersion;
  36. Target = Stub.Target;
  37. SoName = Stub.SoName;
  38. NeededLibs = Stub.NeededLibs;
  39. Symbols = Stub.Symbols;
  40. }
  41. IFSStubTriple::IFSStubTriple(IFSStubTriple &&Stub) {
  42. IfsVersion = std::move(Stub.IfsVersion);
  43. Target = std::move(Stub.Target);
  44. SoName = std::move(Stub.SoName);
  45. NeededLibs = std::move(Stub.NeededLibs);
  46. Symbols = std::move(Stub.Symbols);
  47. }
  48. bool IFSTarget::empty() {
  49. return !Triple && !ObjectFormat && !Arch && !ArchString && !Endianness &&
  50. !BitWidth;
  51. }
  52. uint8_t ifs::convertIFSBitWidthToELF(IFSBitWidthType BitWidth) {
  53. switch (BitWidth) {
  54. case IFSBitWidthType::IFS32:
  55. return ELF::ELFCLASS32;
  56. case IFSBitWidthType::IFS64:
  57. return ELF::ELFCLASS64;
  58. default:
  59. llvm_unreachable("unknown bitwidth");
  60. }
  61. }
  62. uint8_t ifs::convertIFSEndiannessToELF(IFSEndiannessType Endianness) {
  63. switch (Endianness) {
  64. case IFSEndiannessType::Little:
  65. return ELF::ELFDATA2LSB;
  66. case IFSEndiannessType::Big:
  67. return ELF::ELFDATA2MSB;
  68. default:
  69. llvm_unreachable("unknown endianness");
  70. }
  71. }
  72. uint8_t ifs::convertIFSSymbolTypeToELF(IFSSymbolType SymbolType) {
  73. switch (SymbolType) {
  74. case IFSSymbolType::Object:
  75. return ELF::STT_OBJECT;
  76. case IFSSymbolType::Func:
  77. return ELF::STT_FUNC;
  78. case IFSSymbolType::TLS:
  79. return ELF::STT_TLS;
  80. case IFSSymbolType::NoType:
  81. default:
  82. return ELF::STT_NOTYPE;
  83. }
  84. }
  85. IFSBitWidthType ifs::convertELFBitWidthToIFS(uint8_t BitWidth) {
  86. switch (BitWidth) {
  87. case ELF::ELFCLASS32:
  88. return IFSBitWidthType::IFS32;
  89. case ELF::ELFCLASS64:
  90. return IFSBitWidthType::IFS64;
  91. default:
  92. return IFSBitWidthType::Unknown;
  93. }
  94. }
  95. IFSEndiannessType ifs::convertELFEndiannessToIFS(uint8_t Endianness) {
  96. switch (Endianness) {
  97. case ELF::ELFDATA2LSB:
  98. return IFSEndiannessType::Little;
  99. case ELF::ELFDATA2MSB:
  100. return IFSEndiannessType::Big;
  101. default:
  102. return IFSEndiannessType::Unknown;
  103. }
  104. }
  105. IFSSymbolType ifs::convertELFSymbolTypeToIFS(uint8_t SymbolType) {
  106. SymbolType = SymbolType & 0xf;
  107. switch (SymbolType) {
  108. case ELF::STT_OBJECT:
  109. return IFSSymbolType::Object;
  110. case ELF::STT_FUNC:
  111. return IFSSymbolType::Func;
  112. case ELF::STT_TLS:
  113. return IFSSymbolType::TLS;
  114. case ELF::STT_NOTYPE:
  115. return IFSSymbolType::NoType;
  116. default:
  117. return IFSSymbolType::Unknown;
  118. }
  119. }