blob: 4e6def0c2e14026f9e7993a84ad69f731de92277 [file] [log] [blame]
Rafael Espindola95fb9b92015-06-02 20:38:46 +00001//===- 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/MCELFSymbolFlags.h"
13#include "llvm/MC/MCFixupKindInfo.h"
14#include "llvm/Support/ELF.h"
15
16namespace llvm {
17
18void MCSymbolELF::setBinding(unsigned Binding) const {
Rafael Espindolaf6dcd2a2015-06-03 21:18:03 +000019 BindingSet = true;
Rafael Espindola95fb9b92015-06-02 20:38:46 +000020 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
21 Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
22 uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STB_Shift);
23 setFlags(OtherFlags | (Binding << ELF_STB_Shift));
24}
25
26unsigned MCSymbolELF::getBinding() const {
Rafael Espindola8c52a9b2015-06-03 21:41:59 +000027 if (isBindingSet()) {
28 uint32_t Binding = (getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
29 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
30 Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
31 return Binding;
32 }
33
34 if (isDefined())
35 return ELF::STB_LOCAL;
36 if (isUsedInReloc())
37 return ELF::STB_GLOBAL;
38 if (isSignature())
39 return ELF::STB_LOCAL;
40 return ELF::STB_GLOBAL;
Rafael Espindola95fb9b92015-06-02 20:38:46 +000041}
42
43void MCSymbolELF::setType(unsigned Type) const {
44 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
45 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
46 Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
47 Type == ELF::STT_GNU_IFUNC);
48
49 uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STT_Shift);
50 setFlags(OtherFlags | (Type << ELF_STT_Shift));
51}
52
53unsigned MCSymbolELF::getType() const {
54 uint32_t Type = (getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift;
55 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
56 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
57 Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
58 Type == ELF::STT_GNU_IFUNC);
59 return Type;
60}
61
62// Visibility is stored in the first two bits of st_other
63// st_other values are stored in the second byte of get/setFlags
64void MCSymbolELF::setVisibility(unsigned Visibility) {
65 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
66 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
67
68 uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STV_Shift);
69 setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
70}
71
72unsigned MCSymbolELF::getVisibility() const {
73 unsigned Visibility = (getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
74 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
75 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
76 return Visibility;
77}
78
79// Other is stored in the last six bits of st_other
80// st_other values are stored in the second byte of get/setFlags
81void MCSymbolELF::setOther(unsigned Other) {
82 uint32_t OtherFlags = getFlags() & ~(0x3f << ELF_STO_Shift);
83 setFlags(OtherFlags | (Other << ELF_STO_Shift));
84}
85
86unsigned MCSymbolELF::getOther() const {
87 unsigned Other = (getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;
88 return Other;
89}
Rafael Espindolaada43f62015-06-03 21:30:10 +000090
91void MCSymbolELF::setUsedInReloc() const {
92 UsedInReloc = true;
93}
94
95bool MCSymbolELF::isUsedInReloc() const {
96 return UsedInReloc;
97}
98
Rafael Espindola8c52a9b2015-06-03 21:41:59 +000099void MCSymbolELF::setIsSignature() const { IsSignature = true; }
100
101bool MCSymbolELF::isSignature() const { return IsSignature; }
Rafael Espindola95fb9b92015-06-02 20:38:46 +0000102}