xref: /llvm-project/llvm/include/llvm/CodeGen/MachineModuleInfoImpls.h (revision f65a21a4ecc2e712c700c59842b6b9a1d2a9a060)
1 //===- llvm/CodeGen/MachineModuleInfoImpls.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 // This file defines object-file format specific implementations of
10 // MachineModuleInfoImpl.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_MACHINEMODULEINFOIMPLS_H
15 #define LLVM_CODEGEN_MACHINEMODULEINFOIMPLS_H
16 
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SetVector.h"
19 #include "llvm/CodeGen/MachineModuleInfo.h"
20 #include <cassert>
21 
22 namespace llvm {
23 
24 class MCSymbol;
25 
26 /// MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation
27 /// for MachO targets.
28 class MachineModuleInfoMachO : public MachineModuleInfoImpl {
29   /// GVStubs - Darwin '$non_lazy_ptr' stubs.  The key is something like
30   /// "Lfoo$non_lazy_ptr", the value is something like "_foo". The extra bit
31   /// is true if this GV is external.
32   DenseMap<MCSymbol *, StubValueTy> GVStubs;
33 
34   /// ThreadLocalGVStubs - Darwin '$non_lazy_ptr' stubs.  The key is something
35   /// like "Lfoo$non_lazy_ptr", the value is something like "_foo". The extra
36   /// bit is true if this GV is external.
37   DenseMap<MCSymbol *, StubValueTy> ThreadLocalGVStubs;
38 
39   /// Darwin '$auth_ptr' stubs.  The key is the stub symbol, like
40   /// "Lfoo$auth_ptr$ib$12".  The value is the MCExpr representing that
41   /// signed pointer, something like "_foo@AUTH(ib, 12)".
42   DenseMap<MCSymbol *, const MCExpr *> AuthPtrStubs;
43 
44   virtual void anchor(); // Out of line virtual method.
45 
46 public:
47   MachineModuleInfoMachO(const MachineModuleInfo &) {}
48 
49   StubValueTy &getGVStubEntry(MCSymbol *Sym) {
50     assert(Sym && "Key cannot be null");
51     return GVStubs[Sym];
52   }
53 
54   StubValueTy &getThreadLocalGVStubEntry(MCSymbol *Sym) {
55     assert(Sym && "Key cannot be null");
56     return ThreadLocalGVStubs[Sym];
57   }
58 
59   const MCExpr *&getAuthPtrStubEntry(MCSymbol *Sym) {
60     assert(Sym && "Key cannot be null");
61     return AuthPtrStubs[Sym];
62   }
63 
64   /// Accessor methods to return the set of stubs in sorted order.
65   SymbolListTy GetGVStubList() { return getSortedStubs(GVStubs); }
66   SymbolListTy GetThreadLocalGVStubList() {
67     return getSortedStubs(ThreadLocalGVStubs);
68   }
69 
70   ExprStubListTy getAuthGVStubList() {
71     return getSortedExprStubs(AuthPtrStubs);
72   }
73 };
74 
75 /// MachineModuleInfoELF - This is a MachineModuleInfoImpl implementation
76 /// for ELF targets.
77 class MachineModuleInfoELF : public MachineModuleInfoImpl {
78   /// GVStubs - These stubs are used to materialize global addresses in PIC
79   /// mode.
80   DenseMap<MCSymbol *, StubValueTy> GVStubs;
81 
82   /// AuthPtrStubs - These stubs are used to materialize signed addresses for
83   /// extern_weak symbols.
84   DenseMap<MCSymbol *, const MCExpr *> AuthPtrStubs;
85 
86   /// HasSignedPersonality is true if the corresponding IR module has the
87   /// "ptrauth-sign-personality" flag set to 1.
88   bool HasSignedPersonality = false;
89 
90   virtual void anchor(); // Out of line virtual method.
91 
92 public:
93   MachineModuleInfoELF(const MachineModuleInfo &);
94 
95   StubValueTy &getGVStubEntry(MCSymbol *Sym) {
96     assert(Sym && "Key cannot be null");
97     return GVStubs[Sym];
98   }
99 
100   const MCExpr *&getAuthPtrStubEntry(MCSymbol *Sym) {
101     assert(Sym && "Key cannot be null");
102     return AuthPtrStubs[Sym];
103   }
104 
105   /// Accessor methods to return the set of stubs in sorted order.
106 
107   SymbolListTy GetGVStubList() { return getSortedStubs(GVStubs); }
108 
109   ExprStubListTy getAuthGVStubList() {
110     return getSortedExprStubs(AuthPtrStubs);
111   }
112 
113   bool hasSignedPersonality() const { return HasSignedPersonality; }
114 };
115 
116 /// MachineModuleInfoCOFF - This is a MachineModuleInfoImpl implementation
117 /// for COFF targets.
118 class MachineModuleInfoCOFF : public MachineModuleInfoImpl {
119   /// GVStubs - These stubs are used to materialize global addresses in PIC
120   /// mode.
121   DenseMap<MCSymbol *, StubValueTy> GVStubs;
122 
123   virtual void anchor(); // Out of line virtual method.
124 
125 public:
126   MachineModuleInfoCOFF(const MachineModuleInfo &) {}
127 
128   StubValueTy &getGVStubEntry(MCSymbol *Sym) {
129     assert(Sym && "Key cannot be null");
130     return GVStubs[Sym];
131   }
132 
133   /// Accessor methods to return the set of stubs in sorted order.
134 
135   SymbolListTy GetGVStubList() { return getSortedStubs(GVStubs); }
136 };
137 
138 /// MachineModuleInfoWasm - This is a MachineModuleInfoImpl implementation
139 /// for Wasm targets.
140 class MachineModuleInfoWasm : public MachineModuleInfoImpl {
141   virtual void anchor(); // Out of line virtual method.
142 
143 public:
144   MachineModuleInfoWasm(const MachineModuleInfo &) {}
145 
146   SetVector<StringRef> MachineSymbolsUsed;
147 };
148 
149 } // end namespace llvm
150 
151 #endif // LLVM_CODEGEN_MACHINEMODULEINFOIMPLS_H
152