1 //===- lib/MC/MCELF.cpp - MC ELF ------------------------------------------===//
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 // This file implements ELF object file writer information.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/MC/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"
22 void MCELF::SetBinding(const MCSymbol &Sym, unsigned Binding) {
23 MCSymbolData &SD = Sym.getData();
24 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
25 Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
26 uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STB_Shift);
27 SD.setFlags(OtherFlags | (Binding << ELF_STB_Shift));
30 unsigned MCELF::GetBinding(const MCSymbol &Sym) {
31 MCSymbolData &SD = Sym.getData();
32 uint32_t Binding = (SD.getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
33 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
34 Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
38 void MCELF::SetType(const MCSymbol &Sym, unsigned Type) {
39 MCSymbolData &SD = Sym.getData();
40 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
41 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
42 Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
43 Type == ELF::STT_GNU_IFUNC);
45 uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STT_Shift);
46 SD.setFlags(OtherFlags | (Type << ELF_STT_Shift));
49 unsigned MCELF::GetType(const MCSymbol &Sym) {
50 MCSymbolData &SD = Sym.getData();
51 uint32_t Type = (SD.getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift;
52 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
53 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
54 Type == ELF::STT_COMMON || Type == ELF::STT_TLS || Type == ELF::STT_GNU_IFUNC);
58 // Visibility is stored in the first two bits of st_other
59 // st_other values are stored in the second byte of get/setFlags
60 void MCELF::SetVisibility(MCSymbol &Sym, unsigned Visibility) {
61 MCSymbolData &SD = Sym.getData();
62 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
63 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
65 uint32_t OtherFlags = SD.getFlags() & ~(0x3 << ELF_STV_Shift);
66 SD.setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
69 unsigned MCELF::GetVisibility(const MCSymbol &Sym) {
70 MCSymbolData &SD = Sym.getData();
72 (SD.getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
73 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
74 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
78 // Other is stored in the last six bits of st_other
79 // st_other values are stored in the second byte of get/setFlags
80 void MCELF::setOther(MCSymbol &Sym, unsigned Other) {
81 MCSymbolData &SD = Sym.getData();
82 uint32_t OtherFlags = SD.getFlags() & ~(0x3f << ELF_STO_Shift);
83 SD.setFlags(OtherFlags | (Other << ELF_STO_Shift));
86 unsigned MCELF::getOther(const MCSymbol &Sym) {
87 MCSymbolData &SD = Sym.getData();
89 (SD.getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;