Index: llvm/include/llvm/Object/SymbolicFile.h =================================================================== --- llvm/include/llvm/Object/SymbolicFile.h +++ llvm/include/llvm/Object/SymbolicFile.h @@ -88,7 +88,6 @@ 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 @@ 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) { } Index: llvm/lib/Object/ModuleSymbolTable.cpp =================================================================== --- llvm/lib/Object/ModuleSymbolTable.cpp +++ llvm/lib/Object/ModuleSymbolTable.cpp @@ -106,7 +106,8 @@ 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"); @@ -160,6 +161,8 @@ if (GVar->isConstant()) Res |= BasicSymbolRef::SF_Const; } + if (dyn_cast_or_null(GV->getBaseObject())) + Res |= BasicSymbolRef::SF_Executable; if (GV->hasPrivateLinkage()) Res |= BasicSymbolRef::SF_FormatSpecific; if (!GV->hasLocalLinkage()) Index: llvm/tools/llvm-nm/llvm-nm.cpp =================================================================== --- llvm/tools/llvm-nm/llvm-nm.cpp +++ llvm/tools/llvm-nm/llvm-nm.cpp @@ -318,10 +318,10 @@ NType |= MachO::N_SECT; if (SymFlags & SymbolRef::SF_Const) NSect = 3; - else { - IRObjectFile *IRobj = dyn_cast(&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; @@ -887,15 +887,17 @@ 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) { @@ -920,12 +922,8 @@ char Ret = '?'; if (Symflags & object::SymbolRef::SF_Absolute) Ret = 'a'; - else if (IRObjectFile *IR = dyn_cast(&Obj)) { + else if (IRObjectFile *IR = dyn_cast(&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(&Obj)) Ret = getSymbolNMTypeChar(*COFF, I); else if (MachOObjectFile *MachO = dyn_cast(&Obj))