Remove MCELFSymbolFlags.h. It is now internal to MCSymbolELF.
[oota-llvm.git] / lib / MC / MCSymbolELF.cpp
1 //===- lib/MC/MCSymbolELF.cpp ---------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/MC/MCAssembler.h"
11 #include "llvm/MC/MCSymbolELF.h"
12 #include "llvm/MC/MCFixupKindInfo.h"
13 #include "llvm/Support/ELF.h"
14
15 namespace llvm {
16
17 namespace {
18 enum {
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
23 };
24 }
25
26 void MCSymbolELF::setBinding(unsigned Binding) const {
27   BindingSet = true;
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));
32 }
33
34 unsigned MCSymbolELF::getBinding() const {
35   if (isBindingSet()) {
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);
39     return Binding;
40   }
41
42   if (isDefined())
43     return ELF::STB_LOCAL;
44   if (isUsedInReloc())
45     return ELF::STB_GLOBAL;
46   if (isWeakrefUsedInReloc())
47     return ELF::STB_WEAK;
48   if (isSignature())
49     return ELF::STB_LOCAL;
50   return ELF::STB_GLOBAL;
51 }
52
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);
58
59   uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STT_Shift);
60   setFlags(OtherFlags | (Type << ELF_STT_Shift));
61 }
62
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);
69   return Type;
70 }
71
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);
77
78   uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STV_Shift);
79   setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
80 }
81
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);
86   return Visibility;
87 }
88
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));
94 }
95
96 unsigned MCSymbolELF::getOther() const {
97   unsigned Other = (getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;
98   return Other;
99 }
100
101 void MCSymbolELF::setUsedInReloc() const {
102   UsedInReloc = true;
103 }
104
105 bool MCSymbolELF::isUsedInReloc() const {
106   return UsedInReloc;
107 }
108
109 void MCSymbolELF::setIsWeakrefUsedInReloc() const { WeakrefUsedInReloc = true; }
110
111 bool MCSymbolELF::isWeakrefUsedInReloc() const { return WeakrefUsedInReloc; }
112
113 void MCSymbolELF::setIsSignature() const { IsSignature = true; }
114
115 bool MCSymbolELF::isSignature() const { return IsSignature; }
116 }