LLVM 24.0.0git
MCSymbolELF.cpp
Go to the documentation of this file.
1//===- lib/MC/MCSymbolELF.cpp ---------------------------------------------===//
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
11
12namespace llvm {
13
14namespace {
15enum {
16 // Shift value for STT_* flags. 7 possible values. 3 bits.
17 ELF_STT_Shift = 0,
18
19 // Shift value for STB_* flags. 4 possible values, 2 bits.
20 ELF_STB_Shift = 3,
21
22 // Shift value for STV_* flags. 4 possible values, 2 bits.
23 ELF_STV_Shift = 5,
24
25 // Shift value for the target-specific high four bits of st_other.
26 ELF_STO_Shift = 7,
27
28 // One bit.
29 ELF_IsSignature_Shift = 11,
30
31 // One bit.
32 ELF_Weakref_Shift = 12,
33
34 // One bit.
35 ELF_BindingSet_Shift = 13,
36
37 // One bit.
38 ELF_IsMemoryTagged_Shift = 14,
39};
40}
41
42void MCSymbolELF::setBinding(unsigned Binding) const {
43 setIsBindingSet();
44 unsigned Val;
45 switch (Binding) {
46 default:
47 llvm_unreachable("Unsupported Binding");
48 case ELF::STB_LOCAL:
49 Val = 0;
50 break;
51 case ELF::STB_GLOBAL:
52 Val = 1;
53 break;
54 case ELF::STB_WEAK:
55 Val = 2;
56 break;
58 Val = 3;
59 break;
60 }
61 uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STB_Shift);
62 setFlags(OtherFlags | (Val << ELF_STB_Shift));
63}
64
65unsigned MCSymbolELF::getBinding() const {
66 if (isBindingSet()) {
67 uint32_t Val = (Flags >> ELF_STB_Shift) & 3;
68 switch (Val) {
69 default:
70 llvm_unreachable("Invalid value");
71 case 0:
72 return ELF::STB_LOCAL;
73 case 1:
74 return ELF::STB_GLOBAL;
75 case 2:
76 return ELF::STB_WEAK;
77 case 3:
79 }
80 }
81
82 if (isDefined())
83 return ELF::STB_LOCAL;
84 if (isUsedInReloc())
85 return ELF::STB_GLOBAL;
86 if (isSignature())
87 return ELF::STB_LOCAL;
88 return ELF::STB_GLOBAL;
89}
90
91void MCSymbolELF::setType(unsigned Type) const {
92 unsigned Val;
93 switch (Type) {
94 default:
95 llvm_unreachable("Unsupported Binding");
96 case ELF::STT_NOTYPE:
97 Val = 0;
98 break;
99 case ELF::STT_OBJECT:
100 Val = 1;
101 break;
102 case ELF::STT_FUNC:
103 Val = 2;
104 break;
105 case ELF::STT_SECTION:
106 Val = 3;
107 break;
108 case ELF::STT_COMMON:
109 Val = 4;
110 break;
111 case ELF::STT_TLS:
112 Val = 5;
113 break;
115 Val = 6;
116 break;
117 }
118 uint32_t OtherFlags = getFlags() & ~(0x7 << ELF_STT_Shift);
119 setFlags(OtherFlags | (Val << ELF_STT_Shift));
120}
121
122unsigned MCSymbolELF::getType() const {
123 uint32_t Val = (Flags >> ELF_STT_Shift) & 7;
124 switch (Val) {
125 default:
126 llvm_unreachable("Invalid value");
127 case 0:
128 return ELF::STT_NOTYPE;
129 case 1:
130 return ELF::STT_OBJECT;
131 case 2:
132 return ELF::STT_FUNC;
133 case 3:
134 return ELF::STT_SECTION;
135 case 4:
136 return ELF::STT_COMMON;
137 case 5:
138 return ELF::STT_TLS;
139 case 6:
140 return ELF::STT_GNU_IFUNC;
141 }
142}
143
144void MCSymbolELF::setVisibility(unsigned Visibility) {
145 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
146 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
147
148 uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STV_Shift);
149 setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
150}
151
153 unsigned Visibility = (Flags >> ELF_STV_Shift) & 3;
154 return Visibility;
155}
156
158 assert((Other & 0xf) == 0);
159 Other >>= 4;
160 assert(Other <= 0xf);
161 uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STO_Shift);
162 setFlags(OtherFlags | (Other << ELF_STO_Shift));
163}
164
165unsigned MCSymbolELF::getOther() const {
166 unsigned Other = (Flags >> ELF_STO_Shift) & 0xf;
167 return Other << 4;
168}
169
171 uint32_t OtherFlags = getFlags() & ~(0x1 << ELF_Weakref_Shift);
172 setFlags(OtherFlags | (1 << ELF_Weakref_Shift));
173}
174
176 return getFlags() & (0x1 << ELF_Weakref_Shift);
177}
178
180 uint32_t OtherFlags = getFlags() & ~(0x1 << ELF_IsSignature_Shift);
181 setFlags(OtherFlags | (1 << ELF_IsSignature_Shift));
182}
183
185 return getFlags() & (0x1 << ELF_IsSignature_Shift);
186}
187
188void MCSymbolELF::setIsBindingSet() const {
189 uint32_t OtherFlags = getFlags() & ~(0x1 << ELF_BindingSet_Shift);
190 setFlags(OtherFlags | (1 << ELF_BindingSet_Shift));
191}
192
194 return getFlags() & (0x1 << ELF_BindingSet_Shift);
195}
196
198 return getFlags() & (0x1 << ELF_IsMemoryTagged_Shift);
199}
200
201void MCSymbolELF::setMemtag(bool Tagged) {
202 uint32_t OtherFlags = getFlags() & ~(1 << ELF_IsMemoryTagged_Shift);
203 if (Tagged)
204 setFlags(OtherFlags | (1 << ELF_IsMemoryTagged_Shift));
205 else
206 setFlags(OtherFlags);
207}
208}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
DXIL Resource Implicit Binding
LLVM_ABI bool isMemtag() const
LLVM_ABI void setIsWeakref() const
LLVM_ABI unsigned getOther() const
LLVM_ABI unsigned getType() const
LLVM_ABI void setVisibility(unsigned Visibility)
LLVM_ABI void setMemtag(bool Tagged)
LLVM_ABI bool isBindingSet() const
LLVM_ABI void setIsSignature() const
LLVM_ABI void setBinding(unsigned Binding) const
LLVM_ABI bool isSignature() const
LLVM_ABI unsigned getVisibility() const
LLVM_ABI unsigned getBinding() const
LLVM_ABI void setType(unsigned Type) const
LLVM_ABI void setOther(unsigned Other)
LLVM_ABI bool isWeakref() const
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition MCSymbol.h:233
uint32_t Flags
Definition MCSymbol.h:117
void setFlags(uint32_t Value) const
Set the (implementation defined) symbol flags.
Definition MCSymbol.h:369
uint32_t getFlags() const
Get the (implementation defined) symbol flags.
Definition MCSymbol.h:366
bool isUsedInReloc() const
Definition MCSymbol.h:199
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ STB_GLOBAL
Definition ELF.h:1422
@ STB_LOCAL
Definition ELF.h:1421
@ STB_GNU_UNIQUE
Definition ELF.h:1424
@ STB_WEAK
Definition ELF.h:1423
@ STT_FUNC
Definition ELF.h:1435
@ STT_NOTYPE
Definition ELF.h:1433
@ STT_SECTION
Definition ELF.h:1436
@ STT_COMMON
Definition ELF.h:1438
@ STT_GNU_IFUNC
Definition ELF.h:1440
@ STT_OBJECT
Definition ELF.h:1434
@ STT_TLS
Definition ELF.h:1439
@ STV_INTERNAL
Definition ELF.h:1452
@ STV_HIDDEN
Definition ELF.h:1453
@ STV_PROTECTED
Definition ELF.h:1454
@ STV_DEFAULT
Definition ELF.h:1451
This is an optimization pass for GlobalISel generic memory operations.
@ Other
Any other memory.
Definition ModRef.h:68