1 //===- lib/MC/MCSymbolELF.cpp ---------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCAssembler.h"
11 #include "llvm/MC/MCSymbolELF.h"
12 #include "llvm/MC/MCFixupKindInfo.h"
13 #include "llvm/Support/ELF.h"
19 // Shift value for STT_* flags. 7 possible values. 3 bits.
22 // Shift value for STB_* flags. 4 possible values, 2 bits.
25 // Shift value for STV_* flags. 4 possible values, 2 bits.
28 // Shift value for STO_* flags. 3 bits. All the values are between 0x20 and
29 // 0xe0, so we shift right by 5 before storing.
33 ELF_IsSignature_Shift = 10,
36 ELF_WeakrefUsedInReloc_Shift = 11,
39 ELF_BindingSet_Shift = 12
43 void MCSymbolELF::setBinding(unsigned Binding) const {
48 llvm_unreachable("Unsupported Binding");
58 case ELF::STB_GNU_UNIQUE:
62 uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STB_Shift);
63 setFlags(OtherFlags | (Val << ELF_STB_Shift));
66 unsigned MCSymbolELF::getBinding() const {
68 uint32_t Val = (getFlags() & (0x3 << ELF_STB_Shift)) >> ELF_STB_Shift;
71 llvm_unreachable("Invalid value");
73 return ELF::STB_LOCAL;
75 return ELF::STB_GLOBAL;
79 return ELF::STB_GNU_UNIQUE;
84 return ELF::STB_LOCAL;
86 return ELF::STB_GLOBAL;
87 if (isWeakrefUsedInReloc())
90 return ELF::STB_LOCAL;
91 return ELF::STB_GLOBAL;
94 void MCSymbolELF::setType(unsigned Type) const {
98 llvm_unreachable("Unsupported Binding");
102 case ELF::STT_OBJECT:
108 case ELF::STT_SECTION:
111 case ELF::STT_COMMON:
117 case ELF::STT_GNU_IFUNC:
121 uint32_t OtherFlags = getFlags() & ~(0x7 << ELF_STT_Shift);
122 setFlags(OtherFlags | (Val << ELF_STT_Shift));
125 unsigned MCSymbolELF::getType() const {
126 uint32_t Val = (getFlags() & (0x7 << ELF_STT_Shift)) >> ELF_STT_Shift;
129 llvm_unreachable("Invalid value");
131 return ELF::STT_NOTYPE;
133 return ELF::STT_OBJECT;
135 return ELF::STT_FUNC;
137 return ELF::STT_SECTION;
139 return ELF::STT_COMMON;
143 return ELF::STT_GNU_IFUNC;
147 void MCSymbolELF::setVisibility(unsigned Visibility) {
148 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
149 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
151 uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STV_Shift);
152 setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
155 unsigned MCSymbolELF::getVisibility() const {
156 unsigned Visibility = (getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
157 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
158 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
162 void MCSymbolELF::setOther(unsigned Other) {
163 assert((Other & 0x1f) == 0);
165 assert(Other <= 0x7);
166 uint32_t OtherFlags = getFlags() & ~(0x7 << ELF_STO_Shift);
167 setFlags(OtherFlags | (Other << ELF_STO_Shift));
170 unsigned MCSymbolELF::getOther() const {
171 unsigned Other = (getFlags() & (0x7 << ELF_STO_Shift)) >> ELF_STO_Shift;
175 void MCSymbolELF::setIsWeakrefUsedInReloc() const {
176 uint32_t OtherFlags = getFlags() & ~(0x1 << ELF_WeakrefUsedInReloc_Shift);
177 setFlags(OtherFlags | (1 << ELF_WeakrefUsedInReloc_Shift));
180 bool MCSymbolELF::isWeakrefUsedInReloc() const {
181 return getFlags() & (0x1 << ELF_WeakrefUsedInReloc_Shift);
184 void MCSymbolELF::setIsSignature() const {
185 uint32_t OtherFlags = getFlags() & ~(0x1 << ELF_IsSignature_Shift);
186 setFlags(OtherFlags | (1 << ELF_IsSignature_Shift));
189 bool MCSymbolELF::isSignature() const {
190 return getFlags() & (0x1 << ELF_IsSignature_Shift);
193 void MCSymbolELF::setIsBindingSet() const {
194 uint32_t OtherFlags = getFlags() & ~(0x1 << ELF_BindingSet_Shift);
195 setFlags(OtherFlags | (1 << ELF_BindingSet_Shift));
198 bool MCSymbolELF::isBindingSet() const {
199 return getFlags() & (0x1 << ELF_BindingSet_Shift);