1 //===- ELFStub.h ------------------------------------------------*- C++ -*-===//
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 /// \file
10 /// This file defines an internal representation of an ELF stub.
11 ///
12 //===-----------------------------------------------------------------------===/
13 
14 #ifndef LLVM_INTERFACESTUB_ELFSTUB_H
15 #define LLVM_INTERFACESTUB_ELFSTUB_H
16 
17 #include "llvm/BinaryFormat/ELF.h"
18 #include "llvm/Support/VersionTuple.h"
19 #include <set>
20 #include <vector>
21 
22 namespace llvm {
23 namespace elfabi {
24 
25 typedef uint16_t ELFArch;
26 
27 enum class ELFSymbolType {
28   NoType = ELF::STT_NOTYPE,
29   Object = ELF::STT_OBJECT,
30   Func = ELF::STT_FUNC,
31   TLS = ELF::STT_TLS,
32 
33   // Type information is 4 bits, so 16 is safely out of range.
34   Unknown = 16,
35 };
36 
37 struct ELFSymbol {
ELFSymbolELFSymbol38   ELFSymbol(std::string SymbolName) : Name(SymbolName) {}
39   std::string Name;
40   uint64_t Size;
41   ELFSymbolType Type;
42   bool Undefined;
43   bool Weak;
44   Optional<std::string> Warning;
45   bool operator<(const ELFSymbol &RHS) const { return Name < RHS.Name; }
46 };
47 
48 // A cumulative representation of ELF stubs.
49 // Both textual and binary stubs will read into and write from this object.
50 class ELFStub {
51   // TODO: Add support for symbol versioning.
52 public:
53   VersionTuple TbeVersion;
54   Optional<std::string> SoName;
55   ELFArch Arch;
56   std::vector<std::string> NeededLibs;
57   std::set<ELFSymbol> Symbols;
58 
ELFStub()59   ELFStub() {}
60   ELFStub(const ELFStub &Stub);
61   ELFStub(ELFStub &&Stub);
62 };
63 } // end namespace elfabi
64 } // end namespace llvm
65 
66 #endif // LLVM_INTERFACESTUB_ELFSTUB_H
67