2011-02-28 22:45:04 +01:00
|
|
|
//===- lib/MC/MCELF.cpp - MC ELF ------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements ELF object file writer information.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-07 17:50:23 +01:00
|
|
|
#include "llvm/MC/MCELF.h"
|
2011-02-28 22:45:04 +01:00
|
|
|
#include "llvm/MC/MCAssembler.h"
|
|
|
|
#include "llvm/MC/MCELFSymbolFlags.h"
|
|
|
|
#include "llvm/MC/MCFixupKindInfo.h"
|
|
|
|
#include "llvm/Support/ELF.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
void MCELF::SetBinding(MCSymbolData &SD, unsigned Binding) {
|
|
|
|
assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
|
|
|
|
Binding == ELF::STB_WEAK);
|
|
|
|
uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STB_Shift);
|
|
|
|
SD.setFlags(OtherFlags | (Binding << ELF_STB_Shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MCELF::GetBinding(const MCSymbolData &SD) {
|
|
|
|
uint32_t Binding = (SD.getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
|
|
|
|
assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
|
|
|
|
Binding == ELF::STB_WEAK);
|
|
|
|
return Binding;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MCELF::SetType(MCSymbolData &SD, unsigned Type) {
|
|
|
|
assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
|
|
|
|
Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
|
|
|
|
Type == ELF::STT_FILE || Type == ELF::STT_COMMON ||
|
2011-12-12 18:34:04 +01:00
|
|
|
Type == ELF::STT_TLS || Type == ELF::STT_GNU_IFUNC);
|
2011-02-28 22:45:04 +01:00
|
|
|
|
|
|
|
uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STT_Shift);
|
|
|
|
SD.setFlags(OtherFlags | (Type << ELF_STT_Shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MCELF::GetType(const MCSymbolData &SD) {
|
|
|
|
uint32_t Type = (SD.getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift;
|
|
|
|
assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
|
|
|
|
Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
|
|
|
|
Type == ELF::STT_FILE || Type == ELF::STT_COMMON ||
|
2011-12-12 18:34:04 +01:00
|
|
|
Type == ELF::STT_TLS || Type == ELF::STT_GNU_IFUNC);
|
2011-02-28 22:45:04 +01:00
|
|
|
return Type;
|
|
|
|
}
|
|
|
|
|
2013-02-19 22:57:35 +01:00
|
|
|
// Visibility is stored in the first two bits of st_other
|
|
|
|
// st_other values are stored in the second byte of get/setFlags
|
2011-02-28 22:45:04 +01:00
|
|
|
void MCELF::SetVisibility(MCSymbolData &SD, unsigned Visibility) {
|
|
|
|
assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
|
|
|
|
Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
|
|
|
|
|
2011-05-16 18:17:21 +02:00
|
|
|
uint32_t OtherFlags = SD.getFlags() & ~(0x3 << ELF_STV_Shift);
|
2011-02-28 22:45:04 +01:00
|
|
|
SD.setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MCELF::GetVisibility(MCSymbolData &SD) {
|
|
|
|
unsigned Visibility =
|
2011-05-16 18:17:21 +02:00
|
|
|
(SD.getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
|
2011-02-28 22:45:04 +01:00
|
|
|
assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
|
|
|
|
Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
|
|
|
|
return Visibility;
|
|
|
|
}
|
|
|
|
|
2013-02-19 22:57:35 +01:00
|
|
|
// Other is stored in the last six bits of st_other
|
|
|
|
// st_other values are stored in the second byte of get/setFlags
|
|
|
|
void MCELF::setOther(MCSymbolData &SD, unsigned Other) {
|
|
|
|
uint32_t OtherFlags = SD.getFlags() & ~(0x3f << ELF_Other_Shift);
|
|
|
|
SD.setFlags(OtherFlags | (Other << ELF_Other_Shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned MCELF::getOther(MCSymbolData &SD) {
|
|
|
|
unsigned Other =
|
|
|
|
(SD.getFlags() & (0x3f << ELF_Other_Shift)) >> ELF_Other_Shift;
|
|
|
|
return Other;
|
|
|
|
}
|
|
|
|
|
2011-02-28 22:45:04 +01:00
|
|
|
}
|