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/ErrorHandling.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 | return ELF::STT_NOTYPE; |
93 | default: |
94 | llvm_unreachable("unknown symbol type"); |
95 | } |
96 | } |
97 | |
98 | IFSBitWidthType ifs::convertELFBitWidthToIFS(uint8_t BitWidth) { |
99 | switch (BitWidth) { |
100 | case ELF::ELFCLASS32: |
101 | return IFSBitWidthType::IFS32; |
102 | case ELF::ELFCLASS64: |
103 | return IFSBitWidthType::IFS64; |
104 | default: |
105 | return IFSBitWidthType::Unknown; |
106 | } |
107 | } |
108 | |
109 | IFSEndiannessType ifs::convertELFEndiannessToIFS(uint8_t Endianness) { |
110 | switch (Endianness) { |
111 | case ELF::ELFDATA2LSB: |
112 | return IFSEndiannessType::Little; |
113 | case ELF::ELFDATA2MSB: |
114 | return IFSEndiannessType::Big; |
115 | default: |
116 | return IFSEndiannessType::Unknown; |
117 | } |
118 | } |
119 | |
120 | IFSSymbolType ifs::convertELFSymbolTypeToIFS(uint8_t SymbolType) { |
121 | SymbolType = SymbolType & 0xf; |
122 | switch (SymbolType) { |
123 | case ELF::STT_OBJECT: |
124 | return IFSSymbolType::Object; |
125 | case ELF::STT_FUNC: |
126 | return IFSSymbolType::Func; |
127 | case ELF::STT_TLS: |
128 | return IFSSymbolType::TLS; |
129 | case ELF::STT_NOTYPE: |
130 | return IFSSymbolType::NoType; |
131 | default: |
132 | return IFSSymbolType::Unknown; |
133 | } |
134 | } |
135 |