2021-04-08 06:50:12 +08:00
|
|
|
//===- IFSStub.cpp --------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===-----------------------------------------------------------------------===/
|
|
|
|
|
|
|
|
#include "llvm/InterfaceStub/IFSStub.h"
|
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
2021-04-02 11:55:11 +08:00
|
|
|
using namespace llvm::ifs;
|
2021-04-08 06:50:12 +08:00
|
|
|
|
|
|
|
IFSStub::IFSStub(IFSStub const &Stub) {
|
|
|
|
IfsVersion = Stub.IfsVersion;
|
|
|
|
Target = Stub.Target;
|
|
|
|
SoName = Stub.SoName;
|
|
|
|
NeededLibs = Stub.NeededLibs;
|
|
|
|
Symbols = Stub.Symbols;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFSStub::IFSStub(IFSStub &&Stub) {
|
|
|
|
IfsVersion = std::move(Stub.IfsVersion);
|
|
|
|
Target = std::move(Stub.Target);
|
|
|
|
SoName = std::move(Stub.SoName);
|
|
|
|
NeededLibs = std::move(Stub.NeededLibs);
|
|
|
|
Symbols = std::move(Stub.Symbols);
|
|
|
|
}
|
|
|
|
|
2021-08-13 05:33:47 +08:00
|
|
|
IFSStubTriple::IFSStubTriple(IFSStubTriple const &Stub) : IFSStub() {
|
2021-04-08 06:50:12 +08:00
|
|
|
IfsVersion = Stub.IfsVersion;
|
|
|
|
Target = Stub.Target;
|
|
|
|
SoName = Stub.SoName;
|
|
|
|
NeededLibs = Stub.NeededLibs;
|
|
|
|
Symbols = Stub.Symbols;
|
|
|
|
}
|
|
|
|
|
2021-08-13 05:33:47 +08:00
|
|
|
IFSStubTriple::IFSStubTriple(IFSStub const &Stub) : IFSStub() {
|
2021-04-08 06:50:12 +08:00
|
|
|
IfsVersion = Stub.IfsVersion;
|
|
|
|
Target = Stub.Target;
|
|
|
|
SoName = Stub.SoName;
|
|
|
|
NeededLibs = Stub.NeededLibs;
|
|
|
|
Symbols = Stub.Symbols;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFSStubTriple::IFSStubTriple(IFSStubTriple &&Stub) {
|
|
|
|
IfsVersion = std::move(Stub.IfsVersion);
|
|
|
|
Target = std::move(Stub.Target);
|
|
|
|
SoName = std::move(Stub.SoName);
|
|
|
|
NeededLibs = std::move(Stub.NeededLibs);
|
|
|
|
Symbols = std::move(Stub.Symbols);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IFSTarget::empty() {
|
|
|
|
return !Triple && !ObjectFormat && !Arch && !ArchString && !Endianness &&
|
|
|
|
!BitWidth;
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
uint8_t ifs::convertIFSBitWidthToELF(IFSBitWidthType BitWidth) {
|
2021-04-08 06:50:12 +08:00
|
|
|
switch (BitWidth) {
|
|
|
|
case IFSBitWidthType::IFS32:
|
|
|
|
return ELF::ELFCLASS32;
|
|
|
|
case IFSBitWidthType::IFS64:
|
|
|
|
return ELF::ELFCLASS64;
|
2021-07-21 18:59:08 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("unknown bitwidth");
|
2021-04-08 06:50:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
uint8_t ifs::convertIFSEndiannessToELF(IFSEndiannessType Endianness) {
|
2021-04-08 06:50:12 +08:00
|
|
|
switch (Endianness) {
|
|
|
|
case IFSEndiannessType::Little:
|
|
|
|
return ELF::ELFDATA2LSB;
|
|
|
|
case IFSEndiannessType::Big:
|
|
|
|
return ELF::ELFDATA2MSB;
|
2021-07-21 18:59:08 +08:00
|
|
|
default:
|
2021-04-08 06:50:12 +08:00
|
|
|
llvm_unreachable("unknown endianness");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
uint8_t ifs::convertIFSSymbolTypeToELF(IFSSymbolType SymbolType) {
|
2021-04-08 06:50:12 +08:00
|
|
|
switch (SymbolType) {
|
|
|
|
case IFSSymbolType::Object:
|
|
|
|
return ELF::STT_OBJECT;
|
|
|
|
case IFSSymbolType::Func:
|
|
|
|
return ELF::STT_FUNC;
|
|
|
|
case IFSSymbolType::TLS:
|
|
|
|
return ELF::STT_TLS;
|
|
|
|
case IFSSymbolType::NoType:
|
|
|
|
default:
|
|
|
|
return ELF::STT_NOTYPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
IFSBitWidthType ifs::convertELFBitWidthToIFS(uint8_t BitWidth) {
|
2021-04-08 06:50:12 +08:00
|
|
|
switch (BitWidth) {
|
|
|
|
case ELF::ELFCLASS32:
|
|
|
|
return IFSBitWidthType::IFS32;
|
|
|
|
case ELF::ELFCLASS64:
|
|
|
|
return IFSBitWidthType::IFS64;
|
|
|
|
default:
|
|
|
|
return IFSBitWidthType::Unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
IFSEndiannessType ifs::convertELFEndiannessToIFS(uint8_t Endianness) {
|
2021-04-08 06:50:12 +08:00
|
|
|
switch (Endianness) {
|
|
|
|
case ELF::ELFDATA2LSB:
|
|
|
|
return IFSEndiannessType::Little;
|
|
|
|
case ELF::ELFDATA2MSB:
|
|
|
|
return IFSEndiannessType::Big;
|
|
|
|
default:
|
|
|
|
return IFSEndiannessType::Unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 11:55:11 +08:00
|
|
|
IFSSymbolType ifs::convertELFSymbolTypeToIFS(uint8_t SymbolType) {
|
2021-04-08 06:50:12 +08:00
|
|
|
SymbolType = SymbolType & 0xf;
|
|
|
|
switch (SymbolType) {
|
|
|
|
case ELF::STT_OBJECT:
|
|
|
|
return IFSSymbolType::Object;
|
|
|
|
case ELF::STT_FUNC:
|
|
|
|
return IFSSymbolType::Func;
|
|
|
|
case ELF::STT_TLS:
|
|
|
|
return IFSSymbolType::TLS;
|
|
|
|
case ELF::STT_NOTYPE:
|
|
|
|
return IFSSymbolType::NoType;
|
|
|
|
default:
|
|
|
|
return IFSSymbolType::Unknown;
|
|
|
|
}
|
|
|
|
}
|