forked from OSchip/llvm-project
Fix MachOObjectFile::getSymbolSection() to not call report_fatal_error()
but to return object_error::parse_failed. Then made the code in llvm-nm do for Mach-O files what is done in the darwin native tools which is to print "(?,?)" or just "s" for bad section indexes. Also added a test to show it prints the bad section index of "42" when printing the fields as raw hex. llvm-svn: 258434
This commit is contained in:
parent
f0a275e035
commit
1f472eace5
|
@ -458,7 +458,7 @@ MachOObjectFile::getSymbolSection(DataRefImpl Symb) const {
|
|||
DataRefImpl DRI;
|
||||
DRI.d.a = index - 1;
|
||||
if (DRI.d.a >= Sections.size())
|
||||
report_fatal_error("getSymbolSection: Invalid section index.");
|
||||
return object_error::parse_failed;
|
||||
return section_iterator(SectionRef(DRI, this));
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,15 @@ RUN: not llvm-objdump -t %p/Inputs/macho-invalid-symbol-name-past-eof 2>&1 \
|
|||
RUN: | FileCheck -check-prefix NAME-PAST-EOF %s
|
||||
NAME-PAST-EOF: Symbol name entry points before beginning or past end of file
|
||||
|
||||
RUN: not llvm-nm %p/Inputs/macho-invalid-section-index-getSectionRawName 2>&1 \
|
||||
RUN: llvm-nm %p/Inputs/macho-invalid-section-index-getSectionRawName 2>&1 \
|
||||
RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SYMBOL-SEC %s
|
||||
INVALID-SECTION-IDX-SYMBOL-SEC: getSymbolSection: Invalid section index
|
||||
INVALID-SECTION-IDX-SYMBOL-SEC: 0000000100000000 S __mh_execute_header
|
||||
RUN: llvm-nm -m %p/Inputs/macho-invalid-section-index-getSectionRawName 2>&1 \
|
||||
RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SYMBOL-SEC-m %s
|
||||
INVALID-SECTION-IDX-SYMBOL-SEC-m: 0000000100000000 (?,?) [referenced dynamically] external __mh_execute_header
|
||||
RUN: llvm-nm -pax %p/Inputs/macho-invalid-section-index-getSectionRawName 2>&1 \
|
||||
RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SYMBOL-SEC-pax %s
|
||||
INVALID-SECTION-IDX-SYMBOL-SEC-pax: 0000000100000000 0f 42 0010 00000065 __mh_execute_header
|
||||
|
||||
RUN: not llvm-objdump -private-headers %p/Inputs/macho-invalid-header 2>&1 | FileCheck -check-prefix INVALID-HEADER %s
|
||||
INVALID-HEADER: Invalid data was encountered while parsing the file
|
||||
|
|
|
@ -367,7 +367,13 @@ static void darwinPrintSymbol(SymbolicFile &Obj, SymbolListT::iterator I,
|
|||
outs() << "(?,?) ";
|
||||
break;
|
||||
}
|
||||
section_iterator Sec = *MachO->getSymbolSection(I->Sym.getRawDataRefImpl());
|
||||
ErrorOr<section_iterator> SecOrErr =
|
||||
MachO->getSymbolSection(I->Sym.getRawDataRefImpl());
|
||||
if (SecOrErr.getError()) {
|
||||
outs() << "(?,?) ";
|
||||
break;
|
||||
}
|
||||
section_iterator Sec = *SecOrErr;
|
||||
DataRefImpl Ref = Sec->getRawDataRefImpl();
|
||||
StringRef SectionName;
|
||||
MachO->getSectionName(Ref, SectionName);
|
||||
|
@ -772,7 +778,10 @@ static char getSymbolNMTypeChar(MachOObjectFile &Obj, basic_symbol_iterator I) {
|
|||
case MachO::N_INDR:
|
||||
return 'i';
|
||||
case MachO::N_SECT: {
|
||||
section_iterator Sec = *Obj.getSymbolSection(Symb);
|
||||
ErrorOr<section_iterator> SecOrErr = Obj.getSymbolSection(Symb);
|
||||
if (SecOrErr.getError())
|
||||
return 's';
|
||||
section_iterator Sec = *SecOrErr;
|
||||
DataRefImpl Ref = Sec->getRawDataRefImpl();
|
||||
StringRef SectionName;
|
||||
Obj.getSectionName(Ref, SectionName);
|
||||
|
|
Loading…
Reference in New Issue