llvm.org GIT mirror llvm / 71fc8a3
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288320 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 4 years ago
3 changed file(s) with 20 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
8787 const SymbolicFile *OwningObject;
8888
8989 public:
90 // FIXME: should we add a SF_Text?
9190 enum Flags : unsigned {
9291 SF_None = 0,
9392 SF_Undefined = 1U << 0, // Symbol is defined in another object file
102101 SF_Thumb = 1U << 8, // Thumb symbol in a 32-bit ARM binary
103102 SF_Hidden = 1U << 9, // Symbol has hidden visibility
104103 SF_Const = 1U << 10, // Symbol value is constant
104 SF_Executable = 1U << 11, // Symbol points to an executable section
105 // (IR only)
105106 };
106107
107108 BasicSymbolRef() : OwningObject(nullptr) { }
108108 for (auto &KV : Streamer) {
109109 StringRef Key = KV.first();
110110 RecordStreamer::State Value = KV.second;
111 uint32_t Res = BasicSymbolRef::SF_None;
111 // FIXME: For now we just assume that all asm symbols are executable.
112 uint32_t Res = BasicSymbolRef::SF_Executable;
112113 switch (Value) {
113114 case RecordStreamer::NeverSeen:
114115 llvm_unreachable("NeverSeen should have been replaced earlier");
162163 if (GVar->isConstant())
163164 Res |= BasicSymbolRef::SF_Const;
164165 }
166 if (dyn_cast_or_null(GV->getBaseObject()))
167 Res |= BasicSymbolRef::SF_Executable;
165168 if (GV->hasPrivateLinkage())
166169 Res |= BasicSymbolRef::SF_FormatSpecific;
167170 if (!GV->hasLocalLinkage())
312312 NType |= MachO::N_SECT;
313313 if (SymFlags & SymbolRef::SF_Const)
314314 NSect = 3;
315 else {
316 IRObjectFile *IRobj = dyn_cast(&Obj);
317 NSect = (getSymbolNMTypeChar(*IRobj, I->Sym) == 't') ? 1 : 2;
318 }
315 else if (SymFlags & SymbolRef::SF_Executable)
316 NSect = 1;
317 else
318 NSect = 2;
319319 }
320320 if (SymFlags & SymbolRef::SF_Weak)
321321 NDesc |= MachO::N_WEAK_DEF;
881881 return '?';
882882 }
883883
884 static char getSymbolNMTypeChar(const GlobalValue &GV) {
884 static char getSymbolNMTypeChar(IRObjectFile &Obj, basic_symbol_iterator I) {
885 uint32_t Flags = I->getFlags();
885886 // FIXME: should we print 'b'? At the IR level we cannot be sure if this
886887 // will be in bss or not, but we could approximate.
887 return GV.getValueType()->isFunctionTy() ? 't' : 'd';
888 }
889
890 static char getSymbolNMTypeChar(IRObjectFile &Obj, basic_symbol_iterator I) {
891 const GlobalValue *GV = Obj.getSymbolGV(I->getRawDataRefImpl());
892 return !GV ? 't' : getSymbolNMTypeChar(*GV);
888 if (Flags & SymbolRef::SF_Executable)
889 return 't';
890 else if (Triple(Obj.getTargetTriple()).isOSDarwin() &&
891 (Flags & SymbolRef::SF_Const))
892 return 's';
893 else
894 return 'd';
893895 }
894896
895897 static bool isObject(SymbolicFile &Obj, basic_symbol_iterator I) {
914916 char Ret = '?';
915917 if (Symflags & object::SymbolRef::SF_Absolute)
916918 Ret = 'a';
917 else if (IRObjectFile *IR = dyn_cast(&Obj)) {
919 else if (IRObjectFile *IR = dyn_cast(&Obj))
918920 Ret = getSymbolNMTypeChar(*IR, I);
919 Triple Host(sys::getDefaultTargetTriple());
920 if (Ret == 'd' && Host.isOSDarwin() && Symflags & SymbolRef::SF_Const)
921 Ret = 's';
922 }
923921 else if (COFFObjectFile *COFF = dyn_cast(&Obj))
924922 Ret = getSymbolNMTypeChar(*COFF, I);
925923 else if (MachOObjectFile *MachO = dyn_cast(&Obj))