1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

Object: Add SF_Executable symbol flag.

This allows us to remove a few uses of IRObjectFile::getSymbolGV() in
llvm-nm.

While here change host-dependent logic in llvm-nm to target-dependent
logic.

Differential Revision: https://reviews.llvm.org/D27075

llvm-svn: 288320
This commit is contained in:
Peter Collingbourne 2016-12-01 06:53:47 +00:00
parent cfd25fdfa1
commit 7f3cfca4ed
3 changed files with 20 additions and 18 deletions

View File

@ -88,7 +88,6 @@ class BasicSymbolRef {
const SymbolicFile *OwningObject;
public:
// FIXME: should we add a SF_Text?
enum Flags : unsigned {
SF_None = 0,
SF_Undefined = 1U << 0, // Symbol is defined in another object file
@ -103,6 +102,8 @@ public:
SF_Thumb = 1U << 8, // Thumb symbol in a 32-bit ARM binary
SF_Hidden = 1U << 9, // Symbol has hidden visibility
SF_Const = 1U << 10, // Symbol value is constant
SF_Executable = 1U << 11, // Symbol points to an executable section
// (IR only)
};
BasicSymbolRef() : OwningObject(nullptr) { }

View File

@ -109,7 +109,8 @@ void ModuleSymbolTable::CollectAsmSymbols(
for (auto &KV : Streamer) {
StringRef Key = KV.first();
RecordStreamer::State Value = KV.second;
uint32_t Res = BasicSymbolRef::SF_None;
// FIXME: For now we just assume that all asm symbols are executable.
uint32_t Res = BasicSymbolRef::SF_Executable;
switch (Value) {
case RecordStreamer::NeverSeen:
llvm_unreachable("NeverSeen should have been replaced earlier");
@ -163,6 +164,8 @@ uint32_t ModuleSymbolTable::getSymbolFlags(Symbol S) const {
if (GVar->isConstant())
Res |= BasicSymbolRef::SF_Const;
}
if (dyn_cast_or_null<Function>(GV->getBaseObject()))
Res |= BasicSymbolRef::SF_Executable;
if (GV->hasPrivateLinkage())
Res |= BasicSymbolRef::SF_FormatSpecific;
if (!GV->hasLocalLinkage())

View File

@ -313,10 +313,10 @@ static void darwinPrintSymbol(SymbolicFile &Obj, SymbolListT::iterator I,
NType |= MachO::N_SECT;
if (SymFlags & SymbolRef::SF_Const)
NSect = 3;
else {
IRObjectFile *IRobj = dyn_cast<IRObjectFile>(&Obj);
NSect = (getSymbolNMTypeChar(*IRobj, I->Sym) == 't') ? 1 : 2;
}
else if (SymFlags & SymbolRef::SF_Executable)
NSect = 1;
else
NSect = 2;
}
if (SymFlags & SymbolRef::SF_Weak)
NDesc |= MachO::N_WEAK_DEF;
@ -882,15 +882,17 @@ static char getSymbolNMTypeChar(MachOObjectFile &Obj, basic_symbol_iterator I) {
return '?';
}
static char getSymbolNMTypeChar(const GlobalValue &GV) {
static char getSymbolNMTypeChar(IRObjectFile &Obj, basic_symbol_iterator I) {
uint32_t Flags = I->getFlags();
// FIXME: should we print 'b'? At the IR level we cannot be sure if this
// will be in bss or not, but we could approximate.
return GV.getValueType()->isFunctionTy() ? 't' : 'd';
}
static char getSymbolNMTypeChar(IRObjectFile &Obj, basic_symbol_iterator I) {
const GlobalValue *GV = Obj.getSymbolGV(I->getRawDataRefImpl());
return !GV ? 't' : getSymbolNMTypeChar(*GV);
if (Flags & SymbolRef::SF_Executable)
return 't';
else if (Triple(Obj.getTargetTriple()).isOSDarwin() &&
(Flags & SymbolRef::SF_Const))
return 's';
else
return 'd';
}
static bool isObject(SymbolicFile &Obj, basic_symbol_iterator I) {
@ -915,12 +917,8 @@ static char getNMTypeChar(SymbolicFile &Obj, basic_symbol_iterator I) {
char Ret = '?';
if (Symflags & object::SymbolRef::SF_Absolute)
Ret = 'a';
else if (IRObjectFile *IR = dyn_cast<IRObjectFile>(&Obj)) {
else if (IRObjectFile *IR = dyn_cast<IRObjectFile>(&Obj))
Ret = getSymbolNMTypeChar(*IR, I);
Triple Host(sys::getDefaultTargetTriple());
if (Ret == 'd' && Host.isOSDarwin() && Symflags & SymbolRef::SF_Const)
Ret = 's';
}
else if (COFFObjectFile *COFF = dyn_cast<COFFObjectFile>(&Obj))
Ret = getSymbolNMTypeChar(*COFF, I);
else if (MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj))