From f20c973bf81e953c2f29f007c77fb1b488907542 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Mon, 30 Jan 2017 20:53:17 +0000 Subject: [PATCH] Change the llvm-obdump(1) behavior with the -macho flag and inappropriate file types. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit To better match the old darwin otool(1) behavior, when llvm-obdump(1) is used with the -macho option and the input file is not an object file simply print the file name and this message: foo: is not an object file and continue on to process other input files. Also in this case don’t exit non-zero. This should help in some OSS projects' with autoconf scripts that are expecting the old darwin otool(1) behavior. rdar://26828015 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293547 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Object/macho-invalid.test | 4 ++-- test/tools/llvm-objdump/malformed-macho.test | 5 +++-- tools/llvm-objdump/MachODump.cpp | 9 +++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/Object/macho-invalid.test b/test/Object/macho-invalid.test index 4bacc55eb70..93feaa11eda 100644 --- a/test/Object/macho-invalid.test +++ b/test/Object/macho-invalid.test @@ -83,8 +83,8 @@ RUN: not llvm-objdump -t %p/Inputs/macho-invalid-section-index-getSectionRawName RUN: | FileCheck -check-prefix INVALID-SECTION-IDX-SYMBOL-SEC-objdump %s INVALID-SECTION-IDX-SYMBOL-SEC-objdump: truncated or malformed object (bad section index: 66 for symbol at index 8) -RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-header 2>&1 | FileCheck -check-prefix INVALID-HEADER %s -INVALID-HEADER: The file was not recognized as a valid object file +RUN: llvm-objdump -macho -private-headers %p/Inputs/macho-invalid-header 2>&1 | FileCheck -check-prefix INVALID-HEADER %s +INVALID-HEADER: is not an object file RUN: not llvm-objdump -macho -private-headers %p/Inputs/macho64-invalid-incomplete-segment-load-command 2>&1 | FileCheck -check-prefix INCOMPLETE-SEGMENT-LOADC %s INCOMPLETE-SEGMENT-LOADC: truncated or malformed object (load commands extend past the end of the file) diff --git a/test/tools/llvm-objdump/malformed-macho.test b/test/tools/llvm-objdump/malformed-macho.test index 0bc2ce8e898..924d58a1df2 100644 --- a/test/tools/llvm-objdump/malformed-macho.test +++ b/test/tools/llvm-objdump/malformed-macho.test @@ -1,2 +1,3 @@ -RUN: not llvm-objdump -macho -s %p/Inputs/malformed-macho.bin 2>&1 | FileCheck %s -check-prefix=MALFORMED -MALFORMED: The file was not recognized as a valid object file +RUN: llvm-objdump -macho -private-header %p/Inputs/malformed-macho.bin %p/Inputs/empty.macho-armv7 2>&1 | FileCheck %s -check-prefix=MALFORMED +MALFORMED: is not an object file +MALFORMED-NEXT: Mach header diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 53517c58cea..80cbe4bc657 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -1566,8 +1566,13 @@ void llvm::ParseInputMachO(StringRef Filename) { // Attempt to open the binary. Expected> BinaryOrErr = createBinary(Filename); - if (!BinaryOrErr) - report_error(Filename, BinaryOrErr.takeError()); + if (!BinaryOrErr) { + if (auto E = isNotObjectErrorInvalidFileType(BinaryOrErr.takeError())) + report_error(Filename, std::move(E)); + else + outs() << Filename << ": is not an object file\n"; + return; + } Binary &Bin = *BinaryOrErr.get().getBinary(); if (Archive *A = dyn_cast(&Bin)) { -- 2.40.0