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/MCELFSymbolFlags.h"
13 #include "llvm/MC/MCFixupKindInfo.h"
14 #include "llvm/Support/ELF.h"
18 void MCSymbolELF::setBinding(unsigned Binding) const {
20 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));
26 unsigned 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);
33 void 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);
39 uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STT_Shift);
40 setFlags(OtherFlags | (Type << ELF_STT_Shift));
43 unsigned 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);
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
54 void MCSymbolELF::setVisibility(unsigned Visibility) {
55 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
56 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
58 uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STV_Shift);
59 setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
62 unsigned 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);
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
71 void MCSymbolELF::setOther(unsigned Other) {
72 uint32_t OtherFlags = getFlags() & ~(0x3f << ELF_STO_Shift);
73 setFlags(OtherFlags | (Other << ELF_STO_Shift));
76 unsigned MCSymbolELF::getOther() const {
77 unsigned Other = (getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;