2015-06-03 04:38:46 +08:00
|
|
|
//===- lib/MC/MCSymbolELF.cpp ---------------------------------------------===//
|
2011-03-01 05:45:04 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCAssembler.h"
|
2015-06-03 04:38:46 +08:00
|
|
|
#include "llvm/MC/MCSymbolELF.h"
|
2011-03-01 05:45:04 +08:00
|
|
|
#include "llvm/MC/MCELFSymbolFlags.h"
|
|
|
|
#include "llvm/MC/MCFixupKindInfo.h"
|
|
|
|
#include "llvm/Support/ELF.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2015-06-03 04:38:46 +08:00
|
|
|
void MCSymbolELF::setBinding(unsigned Binding) const {
|
2015-06-04 05:18:03 +08:00
|
|
|
BindingSet = true;
|
2011-03-01 05:45:04 +08:00
|
|
|
assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
|
2015-01-23 12:44:35 +08:00
|
|
|
Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
|
2015-06-03 04:38:46 +08:00
|
|
|
uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STB_Shift);
|
|
|
|
setFlags(OtherFlags | (Binding << ELF_STB_Shift));
|
2011-03-01 05:45:04 +08:00
|
|
|
}
|
|
|
|
|
2015-06-03 04:38:46 +08:00
|
|
|
unsigned MCSymbolELF::getBinding() const {
|
2015-06-04 05:41:59 +08:00
|
|
|
if (isBindingSet()) {
|
|
|
|
uint32_t Binding = (getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
|
|
|
|
assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
|
|
|
|
Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
|
|
|
|
return Binding;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDefined())
|
|
|
|
return ELF::STB_LOCAL;
|
|
|
|
if (isUsedInReloc())
|
|
|
|
return ELF::STB_GLOBAL;
|
|
|
|
if (isSignature())
|
|
|
|
return ELF::STB_LOCAL;
|
|
|
|
return ELF::STB_GLOBAL;
|
2011-03-01 05:45:04 +08:00
|
|
|
}
|
|
|
|
|
2015-06-03 04:38:46 +08:00
|
|
|
void MCSymbolELF::setType(unsigned Type) const {
|
2011-03-01 05:45:04 +08:00
|
|
|
assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
|
|
|
|
Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
|
2013-10-29 09:06:17 +08:00
|
|
|
Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
|
|
|
|
Type == ELF::STT_GNU_IFUNC);
|
2011-03-01 05:45:04 +08:00
|
|
|
|
2015-06-03 04:38:46 +08:00
|
|
|
uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STT_Shift);
|
|
|
|
setFlags(OtherFlags | (Type << ELF_STT_Shift));
|
2011-03-01 05:45:04 +08:00
|
|
|
}
|
|
|
|
|
2015-06-03 04:38:46 +08:00
|
|
|
unsigned MCSymbolELF::getType() const {
|
|
|
|
uint32_t Type = (getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift;
|
2011-03-01 05:45:04 +08:00
|
|
|
assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
|
|
|
|
Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
|
2015-06-03 04:38:46 +08:00
|
|
|
Type == ELF::STT_COMMON || Type == ELF::STT_TLS ||
|
|
|
|
Type == ELF::STT_GNU_IFUNC);
|
2011-03-01 05:45:04 +08:00
|
|
|
return Type;
|
|
|
|
}
|
|
|
|
|
2013-02-20 05:57:35 +08:00
|
|
|
// Visibility is stored in the first two bits of st_other
|
|
|
|
// st_other values are stored in the second byte of get/setFlags
|
2015-06-03 04:38:46 +08:00
|
|
|
void MCSymbolELF::setVisibility(unsigned Visibility) {
|
2011-03-01 05:45:04 +08:00
|
|
|
assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
|
|
|
|
Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
|
|
|
|
|
2015-06-03 04:38:46 +08:00
|
|
|
uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STV_Shift);
|
|
|
|
setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
|
2011-03-01 05:45:04 +08:00
|
|
|
}
|
|
|
|
|
2015-06-03 04:38:46 +08:00
|
|
|
unsigned MCSymbolELF::getVisibility() const {
|
|
|
|
unsigned Visibility = (getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
|
2011-03-01 05:45:04 +08:00
|
|
|
assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
|
|
|
|
Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
|
|
|
|
return Visibility;
|
|
|
|
}
|
|
|
|
|
2013-02-20 05:57:35 +08:00
|
|
|
// Other is stored in the last six bits of st_other
|
|
|
|
// st_other values are stored in the second byte of get/setFlags
|
2015-06-03 04:38:46 +08:00
|
|
|
void MCSymbolELF::setOther(unsigned Other) {
|
|
|
|
uint32_t OtherFlags = getFlags() & ~(0x3f << ELF_STO_Shift);
|
|
|
|
setFlags(OtherFlags | (Other << ELF_STO_Shift));
|
2013-02-20 05:57:35 +08:00
|
|
|
}
|
|
|
|
|
2015-06-03 04:38:46 +08:00
|
|
|
unsigned MCSymbolELF::getOther() const {
|
|
|
|
unsigned Other = (getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;
|
2013-02-20 05:57:35 +08:00
|
|
|
return Other;
|
|
|
|
}
|
2015-06-04 05:30:10 +08:00
|
|
|
|
|
|
|
void MCSymbolELF::setUsedInReloc() const {
|
|
|
|
UsedInReloc = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MCSymbolELF::isUsedInReloc() const {
|
|
|
|
return UsedInReloc;
|
|
|
|
}
|
|
|
|
|
2015-06-04 05:41:59 +08:00
|
|
|
void MCSymbolELF::setIsSignature() const { IsSignature = true; }
|
|
|
|
|
|
|
|
bool MCSymbolELF::isSignature() const { return IsSignature; }
|
2011-03-01 05:45:04 +08:00
|
|
|
}
|