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 ELF_STT_Shift = 0, // Shift value for STT_* flags
20 ELF_STB_Shift = 4, // Shift value for STB_* flags
21 ELF_STV_Shift = 8, // Shift value for STV_* flags
22 ELF_STO_Shift = 10 // Shift value for STO_* flags
26 void MCSymbolELF::setBinding(unsigned Binding) const {
28 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
29 Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
30 uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STB_Shift);
31 setFlags(OtherFlags | (Binding << ELF_STB_Shift));
34 unsigned MCSymbolELF::getBinding() const {
36 uint32_t Binding = (getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
37 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
38 Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
43 return ELF::STB_LOCAL;
45 return ELF::STB_GLOBAL;
46 if (isWeakrefUsedInReloc())
49 return ELF::STB_LOCAL;
50 return ELF::STB_GLOBAL;
53 void MCSymbolELF::setType(unsigned Type) const {
54 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
55 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
56 Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
57 Type == ELF::STT_GNU_IFUNC);
59 uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STT_Shift);
60 setFlags(OtherFlags | (Type << ELF_STT_Shift));
63 unsigned MCSymbolELF::getType() const {
64 uint32_t Type = (getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift;
65 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
66 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
67 Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
68 Type == ELF::STT_GNU_IFUNC);
72 // Visibility is stored in the first two bits of st_other
73 // st_other values are stored in the second byte of get/setFlags
74 void MCSymbolELF::setVisibility(unsigned Visibility) {
75 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
76 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
78 uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STV_Shift);
79 setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
82 unsigned MCSymbolELF::getVisibility() const {
83 unsigned Visibility = (getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
84 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
85 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
89 // Other is stored in the last six bits of st_other
90 // st_other values are stored in the second byte of get/setFlags
91 void MCSymbolELF::setOther(unsigned Other) {
92 uint32_t OtherFlags = getFlags() & ~(0x3f << ELF_STO_Shift);
93 setFlags(OtherFlags | (Other << ELF_STO_Shift));
96 unsigned MCSymbolELF::getOther() const {
97 unsigned Other = (getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;
101 void MCSymbolELF::setUsedInReloc() const {
105 bool MCSymbolELF::isUsedInReloc() const {
109 void MCSymbolELF::setIsWeakrefUsedInReloc() const { WeakrefUsedInReloc = true; }
111 bool MCSymbolELF::isWeakrefUsedInReloc() const { return WeakrefUsedInReloc; }
113 void MCSymbolELF::setIsSignature() const { IsSignature = true; }
115 bool MCSymbolELF::isSignature() const { return IsSignature; }