From: Michael Trent Date: Thu, 30 May 2019 20:09:09 +0000 (+0000) Subject: Write new tests for r362121 X-Git-Tag: llvmorg-10-init~4163 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c58130bc8445edfa7438fe210da442b7019d0363;p=platform%2Fupstream%2Fllvm.git Write new tests for r362121 Summary: The tests for r362121 ran dsymutil against a test binary every time. This caused problems on lld-x86_64-ubuntu-fast as dsymutil required a lipo tool be available to process those binaries. This change rewrites the new test cases in macho-disassemble-g-dsym to use bespoke test binaries (exe and dwarf) simplifying the test's runtime dependencies. The changes to tools/llvm-objdump/MachODump.cpp are unchanged from r362121 Reviewers: pete, lhames, JDevlieghere Reviewed By: pete Subscribers: smeenai, aprantl, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62694 llvm-svn: 362141 --- diff --git a/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-fat b/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-fat new file mode 100755 index 0000000..bcfbeeb Binary files /dev/null and b/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-fat differ diff --git a/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-fat.dwarf b/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-fat.dwarf new file mode 100644 index 0000000..57855af Binary files /dev/null and b/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-fat.dwarf differ diff --git a/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-thin b/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-thin new file mode 100755 index 0000000..c7283b4 Binary files /dev/null and b/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-thin differ diff --git a/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-thin.dwarf b/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-thin.dwarf new file mode 100644 index 0000000..9bcd6e2 Binary files /dev/null and b/llvm/test/tools/llvm-objdump/X86/Inputs/hello-macho-thin.dwarf differ diff --git a/llvm/test/tools/llvm-objdump/X86/macho-disassemble-g-dsym.test b/llvm/test/tools/llvm-objdump/X86/macho-disassemble-g-dsym.test index f065677..c4841bb 100644 --- a/llvm/test/tools/llvm-objdump/X86/macho-disassemble-g-dsym.test +++ b/llvm/test/tools/llvm-objdump/X86/macho-disassemble-g-dsym.test @@ -5,3 +5,17 @@ // RUN: FileCheck --input-file %t0 %s CHECK: Disassembly of section __TEXT,__text: + +// RUN: llvm-objdump -m -d -g -dsym %p/Inputs/hello-macho-fat.dwarf %p/Inputs/hello-macho-fat | FileCheck -check-prefix MACHO_DSYM %s +// RUN: llvm-objdump -m -d -g -dsym %p/Inputs/hello-macho-fat.dwarf %p/Inputs/hello-macho-thin | FileCheck -check-prefix MACHO_DSYM %s +// RUN: llvm-objdump -m -d -g -dsym %p/Inputs/hello-macho-thin.dwarf %p/Inputs/hello-macho-thin | FileCheck -check-prefix MACHO_DSYM %s + +MACHO_DSYM: (__TEXT,__text) section + +// RUN: llvm-objdump -m -d -g -dsym %p/../Inputs/libbogus11.a %p/../../dsymutil/Inputs/basic.macho.x86_64 2>&1 | FileCheck -check-prefix BAD_INPUT %s + +BAD_INPUT: is not a Mach-O or Universal file type. + +// RUN: not llvm-objdump -m -d -g -dsym %p/Inputs %p/Inputs/hello-macho-thin 2>&1 | FileCheck -check-prefix DIRECTORY %s + +DIRECTORY: Is a directory diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp index ea92ef9..b684daa 100644 --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -7223,11 +7223,13 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, raw_ostream &DebugOut = nulls(); #endif + // Try to find debug info and set up the DIContext for it. std::unique_ptr diContext; - ObjectFile *DbgObj = MachOOF; + std::unique_ptr DSYMBinary; std::unique_ptr DSYMBuf; - // Try to find debug info and set up the DIContext for it. if (UseDbg) { + ObjectFile *DbgObj = MachOOF; + // A separate DSym file path was specified, parse it as a macho file, // get the sections and supply it to the section name parsing machinery. if (!DSYMFile.empty()) { @@ -7238,12 +7240,61 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, return; } - std::unique_ptr DbgObjCheck = unwrapOrError( - ObjectFile::createMachOObjectFile(BufOrErr.get()->getMemBufferRef()), - DSYMFile.getValue()); - DbgObj = DbgObjCheck.release(); // We need to keep the file alive, because we're replacing DbgObj with it. DSYMBuf = std::move(BufOrErr.get()); + + Expected> BinaryOrErr = + createBinary(DSYMBuf.get()->getMemBufferRef()); + if (!BinaryOrErr) { + report_error(BinaryOrErr.takeError(), DSYMFile); + return; + } + + // We need to keep the Binary elive with the buffer + DSYMBinary = std::move(BinaryOrErr.get()); + + if (ObjectFile *O = dyn_cast(DSYMBinary.get())) { + // this is a Mach-O object file, use it + if (MachOObjectFile *MachDSYM = dyn_cast(&*O)) { + DbgObj = MachDSYM; + } + else { + WithColor::error(errs(), "llvm-objdump") + << DSYMFile << " is not a Mach-O file type.\n"; + return; + } + } + else if (auto UB = dyn_cast(DSYMBinary.get())){ + // this is a Universal Binary, find a Mach-O for this architecture + uint32_t CPUType, CPUSubType; + const char *ArchFlag; + if (MachOOF->is64Bit()) { + const MachO::mach_header_64 H_64 = MachOOF->getHeader64(); + CPUType = H_64.cputype; + CPUSubType = H_64.cpusubtype; + } else { + const MachO::mach_header H = MachOOF->getHeader(); + CPUType = H.cputype; + CPUSubType = H.cpusubtype; + } + Triple T = MachOObjectFile::getArchTriple(CPUType, CPUSubType, nullptr, + &ArchFlag); + Expected> MachDSYM = + UB->getObjectForArch(ArchFlag); + if (!MachDSYM) { + report_error(MachDSYM.takeError(), DSYMFile); + return; + } + + // We need to keep the Binary elive with the buffer + DbgObj = &*MachDSYM.get(); + DSYMBinary = std::move(*MachDSYM); + } + else { + WithColor::error(errs(), "llvm-objdump") + << DSYMFile << " is not a Mach-O or Universal file type.\n"; + return; + } } // Setup the DIContext