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