blob: 1893bb0f8dcbff0716bdf85ed80cbbf8f38f11e1 [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 {
19 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
20 Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
21 uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STB_Shift);
22 setFlags(OtherFlags | (Binding << ELF_STB_Shift));
23}
24
25unsigned MCSymbolELF::getBinding() const {
26 uint32_t Binding = (getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
27 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
28 Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
29 return Binding;
30}
31
32void MCSymbolELF::setType(unsigned Type) const {
33 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
34 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
35 Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
36 Type == ELF::STT_GNU_IFUNC);
37
38 uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STT_Shift);
39 setFlags(OtherFlags | (Type << ELF_STT_Shift));
40}
41
42unsigned MCSymbolELF::getType() const {
43 uint32_t Type = (getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift;
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 return Type;
49}
50
51// Visibility is stored in the first two bits of st_other
52// st_other values are stored in the second byte of get/setFlags
53void MCSymbolELF::setVisibility(unsigned Visibility) {
54 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
55 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
56
57 uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STV_Shift);
58 setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
59}
60
61unsigned MCSymbolELF::getVisibility() const {
62 unsigned Visibility = (getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
63 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
64 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
65 return Visibility;
66}
67
68// Other is stored in the last six bits of st_other
69// st_other values are stored in the second byte of get/setFlags
70void MCSymbolELF::setOther(unsigned Other) {
71 uint32_t OtherFlags = getFlags() & ~(0x3f << ELF_STO_Shift);
72 setFlags(OtherFlags | (Other << ELF_STO_Shift));
73}
74
75unsigned MCSymbolELF::getOther() const {
76 unsigned Other = (getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;
77 return Other;
78}
79}