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/MCSymbol.h"
17 #include "llvm/MC/MCELFSymbolFlags.h"
18 #include "llvm/MC/MCFixupKindInfo.h"
19 #include "llvm/Support/ELF.h"
23 void MCELF::SetBinding(const MCSymbol &Sym, unsigned Binding) {
24 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
25 Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
26 uint32_t OtherFlags = Sym.getFlags() & ~(0xf << ELF_STB_Shift);
27 Sym.setFlags(OtherFlags | (Binding << ELF_STB_Shift));
30 unsigned MCELF::GetBinding(const MCSymbol &Sym) {
31 uint32_t Binding = (Sym.getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
32 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
33 Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
37 void MCELF::SetType(const MCSymbol &Sym, unsigned Type) {
38 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
39 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
40 Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
41 Type == ELF::STT_GNU_IFUNC);
43 uint32_t OtherFlags = Sym.getFlags() & ~(0xf << ELF_STT_Shift);
44 Sym.setFlags(OtherFlags | (Type << ELF_STT_Shift));
47 unsigned MCELF::GetType(const MCSymbol &Sym) {
48 uint32_t Type = (Sym.getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift;
49 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
50 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
51 Type == ELF::STT_COMMON || Type == ELF::STT_TLS || Type == ELF::STT_GNU_IFUNC);
55 // Visibility is stored in the first two bits of st_other
56 // st_other values are stored in the second byte of get/setFlags
57 void MCELF::SetVisibility(MCSymbol &Sym, unsigned Visibility) {
58 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
59 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
61 uint32_t OtherFlags = Sym.getFlags() & ~(0x3 << ELF_STV_Shift);
62 Sym.setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
65 unsigned MCELF::GetVisibility(const MCSymbol &Sym) {
67 (Sym.getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
68 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
69 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
73 // Other is stored in the last six bits of st_other
74 // st_other values are stored in the second byte of get/setFlags
75 void MCELF::setOther(MCSymbol &Sym, unsigned Other) {
76 uint32_t OtherFlags = Sym.getFlags() & ~(0x3f << ELF_STO_Shift);
77 Sym.setFlags(OtherFlags | (Other << ELF_STO_Shift));
80 unsigned MCELF::getOther(const MCSymbol &Sym) {
81 unsigned Other = (Sym.getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;