1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00
llvm-mirror/tools/llvm-readobj
Kevin Enderby 1a15e5c9c5 Fix a crash in running llvm-objdump -t with an invalid Mach-O file already
in the test suite. While this is not really an interesting tool and option to run
on a Mach-O file to show the symbol table in a generic libObject format
it shouldn’t crash.

The reason for the crash was in MachOObjectFile::getSymbolType() when it was
calling MachOObjectFile::getSymbolSection() without checking its return value
for the error case.

What makes this fix require a fair bit of diffs is that the method getSymbolType() is
in the class ObjectFile defined without an ErrorOr<> so I needed to add that all
the sub classes.  And all of the uses needed to be updated and the return value
needed to be checked for the error case.

The MachOObjectFile version of getSymbolType() “can” get an error in trying to
come up with the libObject’s internal SymbolRef::Type when the Mach-O symbol
symbol type is an N_SECT type because the code is trying to select from the
SymbolRef::ST_Data or SymbolRef::ST_Function values for the SymbolRef::Type.
And it needs the Mach-O section to use isData() and isBSS to determine if
it will return SymbolRef::ST_Data.

One other possible fix I considered is to simply return SymbolRef::ST_Other
when MachOObjectFile::getSymbolSection() returned an error.  But since in
the past when I did such changes that “ate an error in the libObject code” I
was asked instead to push the error out of the libObject code I chose not
to implement the fix this way.

As currently written both the COFF and ELF versions of getSymbolType()
can’t get an error.  But if isReservedSectionNumber() wanted to check for
the two known negative values rather than allowing all negative values or
the code wanted to add the same check as in getSymbolAddress() to use
getSection() and check for the error then these versions of getSymbolType()
could return errors.

At the end of the day the error printed now is the generic “Invalid data was
encountered while parsing the file” for object_error::parse_failed.  In the
future when we thread Lang’s new TypedError for recoverable error handling
though libObject this will improve.  And where the added // Diagnostic(…
comment is, it would be changed to produce and error message
like “bad section index (42) for symbol at index 8” for this case.

llvm-svn: 264187
2016-03-23 20:27:00 +00:00
..
ARMAttributeParser.cpp [ARM] Add DSP build attribute and extension targeting 2016-01-25 11:26:11 +00:00
ARMAttributeParser.h [ARM] Add DSP build attribute and extension targeting 2016-01-25 11:26:11 +00:00
ARMEHABIPrinter.h One more batch of self-containing headers. 2016-01-27 19:29:56 +00:00
ARMWinEHPrinter.cpp Fix a crash in running llvm-objdump -t with an invalid Mach-O file already 2016-03-23 20:27:00 +00:00
ARMWinEHPrinter.h Support: Delete {aligned_,}{u,}{little,big}8_t 2014-09-11 21:46:33 +00:00
CMakeLists.txt llvm-readobj: Dump more info for COFF import libraries. 2015-08-28 10:27:50 +00:00
CodeView.h Silence gcc warning about ternary and enumerations 2016-01-28 23:59:35 +00:00
COFFDumper.cpp [codeview] Dump def range lengths in hex 2016-02-11 23:40:14 +00:00
COFFImportDumper.cpp llvm-readobj: Dump more info for COFF import libraries. 2015-08-28 10:27:50 +00:00
ELFDumper.cpp [llvm-readobj] Impl GNU style symbols printing 2016-03-21 17:18:23 +00:00
Error.cpp MSVC requires redeclarations to repeat noexcept 2014-11-03 20:35:30 +00:00
Error.h Canonicalize header guards into a common format. 2014-08-13 16:26:38 +00:00
llvm-readobj.cpp Fix typo. NFC. 2016-03-01 21:45:22 +00:00
llvm-readobj.h Fix typo. NFC. 2016-03-01 21:45:22 +00:00
LLVMBuild.txt Don't link with the archive library programs that don't use it. 2013-06-17 15:29:46 +00:00
MachODumper.cpp [MachO] Add MachO alt-entry directive support. 2016-03-15 01:43:05 +00:00
ObjDumper.cpp Re-sort #include lines again, prior to moving headers around. 2014-01-13 08:04:33 +00:00
ObjDumper.h [llvm-readobj] Add -elf-section-groups option 2016-01-26 19:46:39 +00:00
StackMapPrinter.h [StackMaps] Add a lightweight parser for stackmap version 1 sections. 2015-06-26 23:56:53 +00:00
StreamWriter.cpp [llvm-readobj] Impl GNU style printing of sections and relocations 2016-03-15 17:25:31 +00:00
StreamWriter.h [llvm-readobj] Impl GNU style printing of sections and relocations 2016-03-15 17:25:31 +00:00
Win64EHDumper.cpp Use makeArrayRef or None to avoid unnecessarily mentioning the ArrayRef type extra times. NFC 2015-09-21 05:32:41 +00:00
Win64EHDumper.h Canonicalize header guards into a common format. 2014-08-13 16:26:38 +00:00