• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TEXTAPI_ELF_ELFSTUB_H
15 #define LLVM_TEXTAPI_ELF_ELFSTUB_H
16 
17 #include "llvm/BinaryFormat/ELF.h"
18 #include "llvm/Support/VersionTuple.h"
19 #include <vector>
20 #include <set>
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 {
46     return Name < RHS.Name;
47   }
48 };
49 
50 // A cumulative representation of ELF stubs.
51 // Both textual and binary stubs will read into and write from this object.
52 class ELFStub {
53 // TODO: Add support for symbol versioning.
54 public:
55   VersionTuple TbeVersion;
56   Optional<std::string> SoName;
57   ELFArch Arch;
58   std::vector<std::string> NeededLibs;
59   std::set<ELFSymbol> Symbols;
60 
ELFStub()61   ELFStub() {}
62   ELFStub(const ELFStub &Stub);
63   ELFStub(ELFStub &&Stub);
64 };
65 } // end namespace elfabi
66 } // end namespace llvm
67 
68 #endif // LLVM_TEXTAPI_ELF_ELFSTUB_H
69