diff options
| author | Nick Kledzik <kledzik@apple.com> | 2014-05-22 20:05:43 +0000 |
|---|---|---|
| committer | Nick Kledzik <kledzik@apple.com> | 2014-05-22 20:05:43 +0000 |
| commit | 8a0bc44b712701af03f04d7afdc1a01731a53180 (patch) | |
| tree | c622b5e695631e89df569131dd928227638433d1 /lld/lib/ReaderWriter/MachO | |
| parent | d3b4e08960ad6618b4448fd2c0c38c8c4fa6d72b (diff) | |
| download | bcm5719-llvm-8a0bc44b712701af03f04d7afdc1a01731a53180.tar.gz bcm5719-llvm-8a0bc44b712701af03f04d7afdc1a01731a53180.zip | |
[mach-o] Fix so that mach-o semantic errors return an error rather than assert
llvm-svn: 209469
Diffstat (limited to 'lld/lib/ReaderWriter/MachO')
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp | 19 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp | 4 |
2 files changed, 15 insertions, 8 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp index d40321bb63e..769cb399862 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp @@ -107,8 +107,8 @@ static void processUndefindeSymbol(MachOFile &file, const Symbol &sym, } } -static void processSection(MachOFile &file, const Section §ion, - bool copyRefs) { +static error_code processSection(MachOFile &file, const Section §ion, + bool copyRefs) { unsigned offset = 0; switch (section.type) { case llvm::MachO::S_REGULAR: @@ -128,7 +128,8 @@ static void processSection(MachOFile &file, const Section §ion, } break; case llvm::MachO::S_4BYTE_LITERALS: - assert((section.content.size() % 4) == 0); + if ((section.content.size() % 4) != 0) + return llvm::make_error_code(llvm::errc::executable_format_error); for (size_t i = 0, e = section.content.size(); i != e; i += 4) { ArrayRef<uint8_t> byteContent = section.content.slice(offset, 4); file.addDefinedAtom(StringRef(), DefinedAtom::scopeLinkageUnit, @@ -137,7 +138,8 @@ static void processSection(MachOFile &file, const Section §ion, } break; case llvm::MachO::S_8BYTE_LITERALS: - assert((section.content.size() % 8) == 0); + if ((section.content.size() % 8) != 0) + return llvm::make_error_code(llvm::errc::executable_format_error); for (size_t i = 0, e = section.content.size(); i != e; i += 8) { ArrayRef<uint8_t> byteContent = section.content.slice(offset, 8); file.addDefinedAtom(StringRef(), DefinedAtom::scopeLinkageUnit, @@ -146,7 +148,8 @@ static void processSection(MachOFile &file, const Section §ion, } break; case llvm::MachO::S_16BYTE_LITERALS: - assert((section.content.size() % 16) == 0); + if ((section.content.size() % 16) != 0) + return llvm::make_error_code(llvm::errc::executable_format_error); for (size_t i = 0, e = section.content.size(); i != e; i += 16) { ArrayRef<uint8_t> byteContent = section.content.slice(offset, 16); file.addDefinedAtom(StringRef(), DefinedAtom::scopeLinkageUnit, @@ -155,9 +158,10 @@ static void processSection(MachOFile &file, const Section §ion, } break; default: - llvm_unreachable("mach-o section type not supported"); + llvm_unreachable("mach-o section type not supported yet"); break; } + return error_code::success(); } static ErrorOr<std::unique_ptr<lld::File>> @@ -179,7 +183,8 @@ normalizedObjectToAtoms(const NormalizedFile &normalizedFile, StringRef path, } // Create atoms from sections that don't have symbols. for (auto § : normalizedFile.sections) { - processSection(*file, sect, copyRefs); + if (error_code ec = processSection(*file, sect, copyRefs)) + return ec; } return std::unique_ptr<File>(std::move(file)); diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp index 691a1bc1eea..4ce61fc9cb9 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp @@ -659,8 +659,10 @@ bool MachOYamlIOTaggedDocumentHandler::handledDocTag(llvm::yaml::IO &io, std::unique_ptr<lld::File> f = std::move(foe.get()); file = f.release(); return true; + } else { + io.setError(foe.getError().message()); + return false; } - return false; } |

