]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/lib/MC/MCELF.cpp
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / lib / MC / MCELF.cpp
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 #include "llvm/Target/TargetAsmBackend.h"
20
21 namespace llvm {
22
23 void MCELF::SetBinding(MCSymbolData &SD, unsigned Binding) {
24   assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
25          Binding == ELF::STB_WEAK);
26   uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STB_Shift);
27   SD.setFlags(OtherFlags | (Binding << ELF_STB_Shift));
28 }
29
30 unsigned MCELF::GetBinding(const MCSymbolData &SD) {
31   uint32_t Binding = (SD.getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
32   assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
33          Binding == ELF::STB_WEAK);
34   return Binding;
35 }
36
37 void MCELF::SetType(MCSymbolData &SD, 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_FILE || Type == ELF::STT_COMMON ||
41          Type == ELF::STT_TLS);
42
43   uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STT_Shift);
44   SD.setFlags(OtherFlags | (Type << ELF_STT_Shift));
45 }
46
47 unsigned MCELF::GetType(const MCSymbolData &SD) {
48   uint32_t Type = (SD.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_FILE || Type == ELF::STT_COMMON ||
52          Type == ELF::STT_TLS);
53   return Type;
54 }
55
56 void MCELF::SetVisibility(MCSymbolData &SD, unsigned Visibility) {
57   assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
58          Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
59
60   uint32_t OtherFlags = SD.getFlags() & ~(0x3 << ELF_STV_Shift);
61   SD.setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
62 }
63
64 unsigned MCELF::GetVisibility(MCSymbolData &SD) {
65   unsigned Visibility =
66     (SD.getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
67   assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
68          Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
69   return Visibility;
70 }
71
72 }