1 //===- lib/MC/MCELF.cpp - MC ELF ------------------------------------------===// 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 // This file implements ELF object file writer information. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "MCELF.h" 15 #include "llvm/MC/MCAssembler.h" 16 #include "llvm/MC/MCELFSymbolFlags.h" 17 #include "llvm/MC/MCFixupKindInfo.h" 18 #include "llvm/Support/ELF.h" 19 20 namespace llvm { 21 SetBinding(MCSymbolData & SD,unsigned Binding)22void MCELF::SetBinding(MCSymbolData &SD, unsigned Binding) { 23 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL || 24 Binding == ELF::STB_WEAK); 25 uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STB_Shift); 26 SD.setFlags(OtherFlags | (Binding << ELF_STB_Shift)); 27 } 28 GetBinding(const MCSymbolData & SD)29unsigned MCELF::GetBinding(const MCSymbolData &SD) { 30 uint32_t Binding = (SD.getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift; 31 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL || 32 Binding == ELF::STB_WEAK); 33 return Binding; 34 } 35 SetType(MCSymbolData & SD,unsigned Type)36void MCELF::SetType(MCSymbolData &SD, unsigned Type) { 37 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT || 38 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION || 39 Type == ELF::STT_FILE || Type == ELF::STT_COMMON || 40 Type == ELF::STT_TLS); 41 42 uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STT_Shift); 43 SD.setFlags(OtherFlags | (Type << ELF_STT_Shift)); 44 } 45 GetType(const MCSymbolData & SD)46unsigned MCELF::GetType(const MCSymbolData &SD) { 47 uint32_t Type = (SD.getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift; 48 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT || 49 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION || 50 Type == ELF::STT_FILE || Type == ELF::STT_COMMON || 51 Type == ELF::STT_TLS); 52 return Type; 53 } 54 SetVisibility(MCSymbolData & SD,unsigned Visibility)55void MCELF::SetVisibility(MCSymbolData &SD, unsigned Visibility) { 56 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL || 57 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED); 58 59 uint32_t OtherFlags = SD.getFlags() & ~(0x3 << ELF_STV_Shift); 60 SD.setFlags(OtherFlags | (Visibility << ELF_STV_Shift)); 61 } 62 GetVisibility(MCSymbolData & SD)63unsigned MCELF::GetVisibility(MCSymbolData &SD) { 64 unsigned Visibility = 65 (SD.getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift; 66 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL || 67 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED); 68 return Visibility; 69 } 70 71 } 72