Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 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/MCELFSymbolFlags.h" |
| 13 | #include "llvm/MC/MCFixupKindInfo.h" |
| 14 | #include "llvm/Support/ELF.h" |
| 15 | |
| 16 | namespace llvm { |
| 17 | |
| 18 | void MCSymbolELF::setBinding(unsigned Binding) const { |
Rafael Espindola | f6dcd2a | 2015-06-03 21:18:03 +0000 | [diff] [blame] | 19 | BindingSet = true; |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 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)); |
| 24 | } |
| 25 | |
| 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); |
| 30 | return Binding; |
| 31 | } |
| 32 | |
| 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); |
| 38 | |
| 39 | uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STT_Shift); |
| 40 | setFlags(OtherFlags | (Type << ELF_STT_Shift)); |
| 41 | } |
| 42 | |
| 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); |
| 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 |
| 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); |
| 57 | |
| 58 | uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STV_Shift); |
| 59 | setFlags(OtherFlags | (Visibility << ELF_STV_Shift)); |
| 60 | } |
| 61 | |
| 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); |
| 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 |
| 71 | void MCSymbolELF::setOther(unsigned Other) { |
| 72 | uint32_t OtherFlags = getFlags() & ~(0x3f << ELF_STO_Shift); |
| 73 | setFlags(OtherFlags | (Other << ELF_STO_Shift)); |
| 74 | } |
| 75 | |
| 76 | unsigned MCSymbolELF::getOther() const { |
| 77 | unsigned Other = (getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift; |
| 78 | return Other; |
| 79 | } |
| 80 | } |