Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:56

0001 //===- IFSStub.h ------------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===-----------------------------------------------------------------------===/
0008 ///
0009 /// \file
0010 /// This file defines an internal representation of an InterFace Stub.
0011 ///
0012 //===-----------------------------------------------------------------------===/
0013 
0014 #ifndef LLVM_INTERFACESTUB_IFSSTUB_H
0015 #define LLVM_INTERFACESTUB_IFSSTUB_H
0016 
0017 #include "llvm/Support/VersionTuple.h"
0018 #include <optional>
0019 #include <vector>
0020 
0021 namespace llvm {
0022 namespace ifs {
0023 
0024 typedef uint16_t IFSArch;
0025 
0026 enum class IFSSymbolType {
0027   NoType,
0028   Object,
0029   Func,
0030   TLS,
0031 
0032   // Type information is 4 bits, so 16 is safely out of range.
0033   Unknown = 16,
0034 };
0035 
0036 enum class IFSEndiannessType {
0037   Little,
0038   Big,
0039 
0040   // Endianness info is 1 bytes, 256 is safely out of range.
0041   Unknown = 256,
0042 };
0043 
0044 enum class IFSBitWidthType {
0045   IFS32,
0046   IFS64,
0047 
0048   // Bit width info is 1 bytes, 256 is safely out of range.
0049   Unknown = 256,
0050 };
0051 
0052 struct IFSSymbol {
0053   IFSSymbol() = default;
0054   explicit IFSSymbol(std::string SymbolName) : Name(std::move(SymbolName)) {}
0055   std::string Name;
0056   std::optional<uint64_t> Size;
0057   IFSSymbolType Type = IFSSymbolType::NoType;
0058   bool Undefined = false;
0059   bool Weak = false;
0060   std::optional<std::string> Warning;
0061   bool operator<(const IFSSymbol &RHS) const { return Name < RHS.Name; }
0062 };
0063 
0064 struct IFSTarget {
0065   std::optional<std::string> Triple;
0066   std::optional<std::string> ObjectFormat;
0067   std::optional<IFSArch> Arch;
0068   std::optional<std::string> ArchString;
0069   std::optional<IFSEndiannessType> Endianness;
0070   std::optional<IFSBitWidthType> BitWidth;
0071 
0072   bool empty();
0073 };
0074 
0075 inline bool operator==(const IFSTarget &Lhs, const IFSTarget &Rhs) {
0076   if (Lhs.Arch != Rhs.Arch || Lhs.BitWidth != Rhs.BitWidth ||
0077       Lhs.Endianness != Rhs.Endianness ||
0078       Lhs.ObjectFormat != Rhs.ObjectFormat || Lhs.Triple != Rhs.Triple)
0079     return false;
0080   return true;
0081 }
0082 
0083 inline bool operator!=(const IFSTarget &Lhs, const IFSTarget &Rhs) {
0084   return !(Lhs == Rhs);
0085 }
0086 
0087 // A cumulative representation of InterFace stubs.
0088 // Both textual and binary stubs will read into and write from this object.
0089 struct IFSStub {
0090   // TODO: Add support for symbol versioning.
0091   VersionTuple IfsVersion;
0092   std::optional<std::string> SoName;
0093   IFSTarget Target;
0094   std::vector<std::string> NeededLibs;
0095   std::vector<IFSSymbol> Symbols;
0096 
0097   IFSStub() = default;
0098   IFSStub(const IFSStub &Stub);
0099   IFSStub(IFSStub &&Stub);
0100   virtual ~IFSStub() = default;
0101 };
0102 
0103 // Create a alias class for IFSStub.
0104 // LLVM's YAML library does not allow mapping a class with 2 traits,
0105 // which prevents us using 'Target:' field with different definitions.
0106 // This class makes it possible to map a second traits so the same data
0107 // structure can be used for 2 different yaml schema.
0108 struct IFSStubTriple : IFSStub {
0109   IFSStubTriple() = default;
0110   IFSStubTriple(const IFSStub &Stub);
0111   IFSStubTriple(const IFSStubTriple &Stub);
0112   IFSStubTriple(IFSStubTriple &&Stub);
0113 };
0114 
0115 /// This function convert bit width type from IFS enum to ELF format
0116 /// Currently, ELFCLASS32 and ELFCLASS64 are supported.
0117 ///
0118 /// @param BitWidth IFS bit width type.
0119 uint8_t convertIFSBitWidthToELF(IFSBitWidthType BitWidth);
0120 
0121 /// This function convert endianness type from IFS enum to ELF format
0122 /// Currently, ELFDATA2LSB and ELFDATA2MSB are supported.
0123 ///
0124 /// @param Endianness IFS endianness type.
0125 uint8_t convertIFSEndiannessToELF(IFSEndiannessType Endianness);
0126 
0127 /// This function convert symbol type from IFS enum to ELF format
0128 /// Currently, STT_NOTYPE, STT_OBJECT, STT_FUNC, and STT_TLS are supported.
0129 ///
0130 /// @param SymbolType IFS symbol type.
0131 uint8_t convertIFSSymbolTypeToELF(IFSSymbolType SymbolType);
0132 
0133 /// This function extracts ELF bit width from e_ident[EI_CLASS] of an ELF file
0134 /// Currently, ELFCLASS32 and ELFCLASS64 are supported.
0135 /// Other endianness types are mapped to IFSBitWidthType::Unknown.
0136 ///
0137 /// @param BitWidth e_ident[EI_CLASS] value to extract bit width from.
0138 IFSBitWidthType convertELFBitWidthToIFS(uint8_t BitWidth);
0139 
0140 /// This function extracts ELF endianness from e_ident[EI_DATA] of an ELF file
0141 /// Currently, ELFDATA2LSB and ELFDATA2MSB are supported.
0142 /// Other endianness types are mapped to IFSEndiannessType::Unknown.
0143 ///
0144 /// @param Endianness e_ident[EI_DATA] value to extract endianness type from.
0145 IFSEndiannessType convertELFEndiannessToIFS(uint8_t Endianness);
0146 
0147 /// This function extracts symbol type from a symbol's st_info member and
0148 /// maps it to an IFSSymbolType enum.
0149 /// Currently, STT_NOTYPE, STT_OBJECT, STT_FUNC, and STT_TLS are supported.
0150 /// Other symbol types are mapped to IFSSymbolType::Unknown.
0151 ///
0152 /// @param SymbolType Binary symbol st_info to extract symbol type from.
0153 IFSSymbolType convertELFSymbolTypeToIFS(uint8_t SymbolType);
0154 } // namespace ifs
0155 } // end namespace llvm
0156 
0157 #endif // LLVM_INTERFACESTUB_IFSSTUB_H