LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCELF.cpp
Go to the documentation of this file.
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 "llvm/MC/MCELF.h"
15 #include "llvm/MC/MCAssembler.h"
18 #include "llvm/Support/ELF.h"
19 
20 namespace llvm {
21 
22 void 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 
29 unsigned 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 
36 void 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_COMMON || Type == ELF::STT_TLS ||
40  Type == ELF::STT_GNU_IFUNC);
41 
42  uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STT_Shift);
43  SD.setFlags(OtherFlags | (Type << ELF_STT_Shift));
44 }
45 
46 unsigned 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_COMMON || Type == ELF::STT_TLS || Type == ELF::STT_GNU_IFUNC);
51  return Type;
52 }
53 
54 // Visibility is stored in the first two bits of st_other
55 // st_other values are stored in the second byte of get/setFlags
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 
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 // Other is stored in the last six bits of st_other
73 // st_other values are stored in the second byte of get/setFlags
74 void MCELF::setOther(MCSymbolData &SD, unsigned Other) {
75  uint32_t OtherFlags = SD.getFlags() & ~(0x3f << ELF_Other_Shift);
76  SD.setFlags(OtherFlags | (Other << ELF_Other_Shift));
77 }
78 
80  unsigned Other =
81  (SD.getFlags() & (0x3f << ELF_Other_Shift)) >> ELF_Other_Shift;
82  return Other;
83 }
84 
85 }
COFF::RelocationTypeX86 Type
Definition: COFFYAML.cpp:227
void setFlags(uint32_t Value)
setFlags - Set the (implementation defined) symbol flags.
Definition: MCAssembler.h:773
static unsigned getOther(MCSymbolData &SD)
Definition: MCELF.cpp:79
static void SetType(MCSymbolData &SD, unsigned Type)
Definition: MCELF.cpp:36
static void SetVisibility(MCSymbolData &SD, unsigned Visibility)
Definition: MCELF.cpp:56
static void setOther(MCSymbolData &SD, unsigned Other)
Definition: MCELF.cpp:74
static unsigned GetVisibility(MCSymbolData &SD)
Definition: MCELF.cpp:64
static unsigned GetType(const MCSymbolData &SD)
Definition: MCELF.cpp:46
static void SetBinding(MCSymbolData &SD, unsigned Binding)
Definition: MCELF.cpp:22
uint32_t getFlags() const
getFlags - Get the (implementation defined) symbol flags.
Definition: MCAssembler.h:770
static unsigned GetBinding(const MCSymbolData &SD)
Definition: MCELF.cpp:29