The code in llvm-nm for Mach-O files to determine the section type for an
N_SECT type symbol it will call getSymbolSection() and check for the error,
but in the case the n_sect value is zero it will return section_end() (aka nullptr).
And the code was using that and crashing instead of just returning a āsā for a
section or printing (?,?) as it would if getSymbolSection() returned an error.
rdar://
33136604
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313193
91177308-0d34-0410-b5e6-
96231b3b80d8
--- /dev/null
+RUN: llvm-nm %p/Inputs/macho-bad-zero-nsect-for-N_SECT | FileCheck -check-prefix DEFAULT %s
+DEFAULT: 0000000000000000 S dyld_stub_binder
+
+RUN: llvm-nm -m %p/Inputs/macho-bad-zero-nsect-for-N_SECT | FileCheck -check-prefix MACHO %s
+MACHO: 0000000000000000 (?,?) private external dyld_stub_binder
+
+RUN: llvm-nm -x %p/Inputs/macho-bad-zero-nsect-for-N_SECT | FileCheck -check-prefix HEX %s
+HEX: 0000000000000000 1f 00 0000 00000024 dyld_stub_binder
break;
}
Sec = *SecOrErr;
+ if (Sec == MachO->section_end()) {
+ outs() << "(?,?) ";
+ break;
+ }
} else {
Sec = I->Section;
}
return 's';
}
section_iterator Sec = *SecOrErr;
+ if (Sec == Obj.section_end())
+ return 's';
DataRefImpl Ref = Sec->getRawDataRefImpl();
StringRef SectionName;
Obj.getSectionName(Ref, SectionName);