LLVM API Documentation

MCELF.cpp
Go to the documentation of this file.
00001 //===- lib/MC/MCELF.cpp - MC ELF ------------------------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements ELF object file writer information.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/MC/MCELF.h"
00015 #include "llvm/MC/MCAssembler.h"
00016 #include "llvm/MC/MCELFSymbolFlags.h"
00017 #include "llvm/MC/MCFixupKindInfo.h"
00018 #include "llvm/Support/ELF.h"
00019 
00020 namespace llvm {
00021 
00022 void MCELF::SetBinding(MCSymbolData &SD, unsigned Binding) {
00023   assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
00024          Binding == ELF::STB_WEAK);
00025   uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STB_Shift);
00026   SD.setFlags(OtherFlags | (Binding << ELF_STB_Shift));
00027 }
00028 
00029 unsigned MCELF::GetBinding(const MCSymbolData &SD) {
00030   uint32_t Binding = (SD.getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
00031   assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
00032          Binding == ELF::STB_WEAK);
00033   return Binding;
00034 }
00035 
00036 void MCELF::SetType(MCSymbolData &SD, unsigned Type) {
00037   assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
00038          Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
00039          Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
00040          Type == ELF::STT_GNU_IFUNC);
00041 
00042   uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STT_Shift);
00043   SD.setFlags(OtherFlags | (Type << ELF_STT_Shift));
00044 }
00045 
00046 unsigned MCELF::GetType(const MCSymbolData &SD) {
00047   uint32_t Type = (SD.getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift;
00048   assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
00049          Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
00050          Type == ELF::STT_COMMON || Type == ELF::STT_TLS || Type == ELF::STT_GNU_IFUNC);
00051   return Type;
00052 }
00053 
00054 // Visibility is stored in the first two bits of st_other
00055 // st_other values are stored in the second byte of get/setFlags
00056 void MCELF::SetVisibility(MCSymbolData &SD, unsigned Visibility) {
00057   assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
00058          Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
00059 
00060   uint32_t OtherFlags = SD.getFlags() & ~(0x3 << ELF_STV_Shift);
00061   SD.setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
00062 }
00063 
00064 unsigned MCELF::GetVisibility(const MCSymbolData &SD) {
00065   unsigned Visibility =
00066     (SD.getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
00067   assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
00068          Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
00069   return Visibility;
00070 }
00071 
00072 // Other is stored in the last six bits of st_other
00073 // st_other values are stored in the second byte of get/setFlags
00074 void MCELF::setOther(MCSymbolData &SD, unsigned Other) {
00075   uint32_t OtherFlags = SD.getFlags() & ~(0x3f << ELF_STO_Shift);
00076   SD.setFlags(OtherFlags | (Other << ELF_STO_Shift));
00077 }
00078 
00079 unsigned MCELF::getOther(const MCSymbolData &SD) {
00080   unsigned Other =
00081     (SD.getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;
00082   return Other;
00083 }
00084 
00085 }