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