1 //===- IFSStub.cpp --------------------------------------------------------===//
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
7 //===-----------------------------------------------------------------------===/
9 #include "llvm/InterfaceStub/IFSStub.h"
10 #include "llvm/BinaryFormat/ELF.h"
11 #include "llvm/Support/Error.h"
14 using namespace llvm::ifs
;
16 IFSStub::IFSStub(IFSStub
const &Stub
) {
17 IfsVersion
= Stub
.IfsVersion
;
20 NeededLibs
= Stub
.NeededLibs
;
21 Symbols
= Stub
.Symbols
;
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
);
32 IFSStubTriple::IFSStubTriple(IFSStubTriple
const &Stub
) : IFSStub() {
33 IfsVersion
= Stub
.IfsVersion
;
36 NeededLibs
= Stub
.NeededLibs
;
37 Symbols
= Stub
.Symbols
;
40 IFSStubTriple::IFSStubTriple(IFSStub
const &Stub
) : IFSStub() {
41 IfsVersion
= Stub
.IfsVersion
;
44 NeededLibs
= Stub
.NeededLibs
;
45 Symbols
= Stub
.Symbols
;
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
);
56 bool IFSTarget::empty() {
57 return !Triple
&& !ObjectFormat
&& !Arch
&& !ArchString
&& !Endianness
&&
61 uint8_t ifs::convertIFSBitWidthToELF(IFSBitWidthType BitWidth
) {
63 case IFSBitWidthType::IFS32
:
64 return ELF::ELFCLASS32
;
65 case IFSBitWidthType::IFS64
:
66 return ELF::ELFCLASS64
;
68 llvm_unreachable("unknown bitwidth");
72 uint8_t ifs::convertIFSEndiannessToELF(IFSEndiannessType Endianness
) {
74 case IFSEndiannessType::Little
:
75 return ELF::ELFDATA2LSB
;
76 case IFSEndiannessType::Big
:
77 return ELF::ELFDATA2MSB
;
79 llvm_unreachable("unknown endianness");
83 uint8_t ifs::convertIFSSymbolTypeToELF(IFSSymbolType SymbolType
) {
85 case IFSSymbolType::Object
:
86 return ELF::STT_OBJECT
;
87 case IFSSymbolType::Func
:
89 case IFSSymbolType::TLS
:
91 case IFSSymbolType::NoType
:
93 return ELF::STT_NOTYPE
;
97 IFSBitWidthType
ifs::convertELFBitWidthToIFS(uint8_t BitWidth
) {
100 return IFSBitWidthType::IFS32
;
101 case ELF::ELFCLASS64
:
102 return IFSBitWidthType::IFS64
;
104 return IFSBitWidthType::Unknown
;
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
;
115 return IFSEndiannessType::Unknown
;
119 IFSSymbolType
ifs::convertELFSymbolTypeToIFS(uint8_t SymbolType
) {
120 SymbolType
= SymbolType
& 0xf;
121 switch (SymbolType
) {
122 case ELF::STT_OBJECT
:
123 return IFSSymbolType::Object
;
125 return IFSSymbolType::Func
;
127 return IFSSymbolType::TLS
;
128 case ELF::STT_NOTYPE
:
129 return IFSSymbolType::NoType
;
131 return IFSSymbolType::Unknown
;