blob: 560cdbc6abae750a5279173b84472a1981805014 [file] [log] [blame]
Jan Sjödin2ddfd952011-02-28 21:45:04 +00001//===- 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
Tim Northover6eb3e872012-12-07 16:50:23 +000014#include "llvm/MC/MCELF.h"
Jan Sjödin2ddfd952011-02-28 21:45:04 +000015#include "llvm/MC/MCAssembler.h"
16#include "llvm/MC/MCELFSymbolFlags.h"
17#include "llvm/MC/MCFixupKindInfo.h"
18#include "llvm/Support/ELF.h"
Jan Sjödin2ddfd952011-02-28 21:45:04 +000019
20namespace llvm {
21
22void 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
29unsigned 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
36void 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_FILE || Type == ELF::STT_COMMON ||
Roman Divackya0c17a42011-12-12 17:34:04 +000040 Type == ELF::STT_TLS || Type == ELF::STT_GNU_IFUNC);
Jan Sjödin2ddfd952011-02-28 21:45:04 +000041
42 uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STT_Shift);
43 SD.setFlags(OtherFlags | (Type << ELF_STT_Shift));
44}
45
46unsigned 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_FILE || Type == ELF::STT_COMMON ||
Roman Divackya0c17a42011-12-12 17:34:04 +000051 Type == ELF::STT_TLS || Type == ELF::STT_GNU_IFUNC);
Jan Sjödin2ddfd952011-02-28 21:45:04 +000052 return Type;
53}
54
Jack Carter77afbdc2013-02-19 21:57:35 +000055// Visibility is stored in the first two bits of st_other
56// st_other values are stored in the second byte of get/setFlags
Jan Sjödin2ddfd952011-02-28 21:45:04 +000057void MCELF::SetVisibility(MCSymbolData &SD, unsigned Visibility) {
58 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
59 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
60
Rafael Espindola64695402011-05-16 16:17:21 +000061 uint32_t OtherFlags = SD.getFlags() & ~(0x3 << ELF_STV_Shift);
Jan Sjödin2ddfd952011-02-28 21:45:04 +000062 SD.setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
63}
64
65unsigned MCELF::GetVisibility(MCSymbolData &SD) {
66 unsigned Visibility =
Rafael Espindola64695402011-05-16 16:17:21 +000067 (SD.getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
Jan Sjödin2ddfd952011-02-28 21:45:04 +000068 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
69 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
70 return Visibility;
71}
72
Jack Carter77afbdc2013-02-19 21:57:35 +000073// Other is stored in the last six bits of st_other
74// st_other values are stored in the second byte of get/setFlags
75void MCELF::setOther(MCSymbolData &SD, unsigned Other) {
76 uint32_t OtherFlags = SD.getFlags() & ~(0x3f << ELF_Other_Shift);
77 SD.setFlags(OtherFlags | (Other << ELF_Other_Shift));
78}
79
80unsigned MCELF::getOther(MCSymbolData &SD) {
81 unsigned Other =
82 (SD.getFlags() & (0x3f << ELF_Other_Shift)) >> ELF_Other_Shift;
83 return Other;
84}
85
Jan Sjödin2ddfd952011-02-28 21:45:04 +000086}