From 7ac8d214b5040201215426967a2cf2bbc4888de3 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 13 Apr 2015 16:05:49 +0000 Subject: [PATCH] llvm-readobj: teach it to handle MachO Universal Archive correctly Patch by Chilledheart (rwindz0@gmail.com). Reviewed By: rafael Differential Revision: http://reviews.llvm.org/D8773 llvm-svn: 234758 --- .../macho-universal-archive.x86_64.i386 | Bin 0 -> 1656 bytes .../macho-universal-x86_64.i386.test | 156 ++++++++++++++++++ tools/llvm-readobj/llvm-readobj.cpp | 13 +- 3 files changed, 162 insertions(+), 7 deletions(-) create mode 100644 test/tools/llvm-readobj/Inputs/macho-universal-archive.x86_64.i386 diff --git a/test/tools/llvm-readobj/Inputs/macho-universal-archive.x86_64.i386 b/test/tools/llvm-readobj/Inputs/macho-universal-archive.x86_64.i386 new file mode 100644 index 0000000000000000000000000000000000000000..1660714c68ea8e4a638889b1a061153393b376a2 GIT binary patch literal 1656 zcmbVM&1(};5TDf8me`LRJSZrxDCj}cY+9QHMOsW`!HT6#p&rU>Y*SNclM+)J1fft6 z_aOKuc=YH|J%~`D#e@1sSm;5aM-i$1e*50brrL@+FgxEfZ|BXMce}4%i%45UqyzL2 zFewu4qz-6w(G0{P$Ze;u6l*i(tFbd~Un=Q@;Pz*;m(rbNNz3L4Z&x&zr}9eoO0Co^bI zH61IL78a_BD$~k`Z(nxtGZFqE{x$f~9Wo9Oa2)uE@&WM7=;Q1Pz{+e8F-j#ssd}kV z*SwYs`N={kTkf)9n2)h9K!em#S+zc-O3mD>*XApCjZ&$-`D~tUW4~d}XGERT3ZTeW zU0f>8)YWojWxg`2)JV{O>*5*4F?167*t1Pg)1EyQlq!|gT&=iR(gDAouWa%R8QL)U zj3`G$tV^I`@?*e{U=D*iD1HGHeliLq(8nTs_lIkv`@S&Y`CH!FXUBWYDzcIPPU1iK z>iNq%oXJE+}*GBV{j%oJqpp>;V27<8dV+w7h+#W{dS=Xi_RSTo?}JPOyv}K@M9tv}%re v&dI3pDTDI7t#3(thVRMB|3WAHt*LbcAiZ#Idr_F@quiXq;O>H34Cd!2$5XhC literal 0 HcmV?d00001 diff --git a/test/tools/llvm-readobj/macho-universal-x86_64.i386.test b/test/tools/llvm-readobj/macho-universal-x86_64.i386.test index 502e0fb3980..2138bb70ad3 100644 --- a/test/tools/llvm-readobj/macho-universal-x86_64.i386.test +++ b/test/tools/llvm-readobj/macho-universal-x86_64.i386.test @@ -4,6 +4,12 @@ RUN: | FileCheck %s -check-prefix MULTIHEADER RUN: llvm-readobj -sections %p/Inputs/macho-universal.x86_64.i386 \ RUN: | FileCheck %s -check-prefix MULTISECTIONS +RUN: llvm-readobj -h %p/Inputs/macho-universal-archive.x86_64.i386 \ +RUN: | FileCheck %s -check-prefix MULTIHEADER-ARCHIVE + +RUN: llvm-readobj -sections %p/Inputs/macho-universal-archive.x86_64.i386 \ +RUN: | FileCheck %s -check-prefix MULTISECTIONS-ARCHIVE + MULTIHEADER: Format: Mach-O 64-bit x86-64 MULTIHEADER: Arch: x86_64 MULTIHEADER: AddressSize: 64bit @@ -139,3 +145,153 @@ MULTISECTIONS: Reserved1: 0x0 MULTISECTIONS: Reserved2: 0x0 MULTISECTIONS: } MULTISECTIONS: ] + +MULTIHEADER-ARCHIVE: File: hello.o +MULTIHEADER-ARCHIVE: Format: Mach-O 64-bit x86-64 +MULTIHEADER-ARCHIVE: Arch: x86_64 +MULTIHEADER-ARCHIVE: AddressSize: 64bit +MULTIHEADER-ARCHIVE: MachHeader { +MULTIHEADER-ARCHIVE: Magic: Magic64 (0xFEEDFACF) +MULTIHEADER-ARCHIVE: CpuType: X86-64 (0x1000007) +MULTIHEADER-ARCHIVE: CpuSubType: CPU_SUBTYPE_X86_64_ALL (0x3) +MULTIHEADER-ARCHIVE: FileType: Relocatable (0x1) +MULTIHEADER-ARCHIVE: NumOfLoadCommands: 3 +MULTIHEADER-ARCHIVE: SizeOfLoadCommands: 496 +MULTIHEADER-ARCHIVE: Flags [ (0x2000) +MULTIHEADER-ARCHIVE: MH_SUBSECTIONS_VIA_SYMBOLS (0x2000) +MULTIHEADER-ARCHIVE: ] +MULTIHEADER-ARCHIVE: Reserved: 0x0 +MULTIHEADER-ARCHIVE: } +MULTIHEADER-ARCHIVE: File: foo.o +MULTIHEADER-ARCHIVE: Format: Mach-O 32-bit i386 +MULTIHEADER-ARCHIVE: Arch: i386 +MULTIHEADER-ARCHIVE: AddressSize: 32bit +MULTIHEADER-ARCHIVE: MachHeader { +MULTIHEADER-ARCHIVE: Magic: Magic (0xFEEDFACE) +MULTIHEADER-ARCHIVE: CpuType: X86 (0x7) +MULTIHEADER-ARCHIVE: CpuSubType: CPU_SUBTYPE_I386_ALL (0x3) +MULTIHEADER-ARCHIVE: FileType: Relocatable (0x1) +MULTIHEADER-ARCHIVE: NumOfLoadCommands: 3 +MULTIHEADER-ARCHIVE: SizeOfLoadCommands: 296 +MULTIHEADER-ARCHIVE: Flags [ (0x2000) +MULTIHEADER-ARCHIVE: MH_SUBSECTIONS_VIA_SYMBOLS (0x2000) +MULTIHEADER-ARCHIVE: ] +MULTIHEADER-ARCHIVE: } + +MULTISECTIONS-ARCHIVE: File: hello.o +MULTISECTIONS-ARCHIVE: Format: Mach-O 64-bit x86-64 +MULTISECTIONS-ARCHIVE: Arch: x86_64 +MULTISECTIONS-ARCHIVE: AddressSize: 64bit +MULTISECTIONS-ARCHIVE: Sections [ +MULTISECTIONS-ARCHIVE: Section { +MULTISECTIONS-ARCHIVE: Index: 0 +MULTISECTIONS-ARCHIVE: Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00) +MULTISECTIONS-ARCHIVE: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00) +MULTISECTIONS-ARCHIVE: Address: 0x0 +MULTISECTIONS-ARCHIVE: Size: 0x3B +MULTISECTIONS-ARCHIVE: Offset: 528 +MULTISECTIONS-ARCHIVE: Alignment: 4 +MULTISECTIONS-ARCHIVE: RelocationOffset: 0x2B8 +MULTISECTIONS-ARCHIVE: RelocationCount: 2 +MULTISECTIONS-ARCHIVE: Type: 0x0 +MULTISECTIONS-ARCHIVE: Attributes [ (0x800004) +MULTISECTIONS-ARCHIVE: PureInstructions (0x800000) +MULTISECTIONS-ARCHIVE: SomeInstructions (0x4) +MULTISECTIONS-ARCHIVE: ] +MULTISECTIONS-ARCHIVE: Reserved1: 0x0 +MULTISECTIONS-ARCHIVE: Reserved2: 0x0 +MULTISECTIONS-ARCHIVE: } +MULTISECTIONS-ARCHIVE: Section { +MULTISECTIONS-ARCHIVE: Index: 1 +MULTISECTIONS-ARCHIVE: Name: __cstring (5F 5F 63 73 74 72 69 6E 67 00 00 00 00 00 00 00) +MULTISECTIONS-ARCHIVE: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00) +MULTISECTIONS-ARCHIVE: Address: 0x3B +MULTISECTIONS-ARCHIVE: Size: 0xD +MULTISECTIONS-ARCHIVE: Offset: 587 +MULTISECTIONS-ARCHIVE: Alignment: 0 +MULTISECTIONS-ARCHIVE: RelocationOffset: 0x0 +MULTISECTIONS-ARCHIVE: RelocationCount: 0 +MULTISECTIONS-ARCHIVE: Type: ExtReloc (0x2) +MULTISECTIONS-ARCHIVE: Attributes [ (0x0) +MULTISECTIONS-ARCHIVE: ] +MULTISECTIONS-ARCHIVE: Reserved1: 0x0 +MULTISECTIONS-ARCHIVE: Reserved2: 0x0 +MULTISECTIONS-ARCHIVE: } +MULTISECTIONS-ARCHIVE: Section { +MULTISECTIONS-ARCHIVE: Index: 2 +MULTISECTIONS-ARCHIVE: Name: __compact_unwind (5F 5F 63 6F 6D 70 61 63 74 5F 75 6E 77 69 6E 64) +MULTISECTIONS-ARCHIVE: Segment: __LD (5F 5F 4C 44 00 00 00 00 00 00 00 00 00 00 00 00) +MULTISECTIONS-ARCHIVE: Address: 0x48 +MULTISECTIONS-ARCHIVE: Size: 0x20 +MULTISECTIONS-ARCHIVE: Offset: 600 +MULTISECTIONS-ARCHIVE: Alignment: 3 +MULTISECTIONS-ARCHIVE: RelocationOffset: 0x2C8 +MULTISECTIONS-ARCHIVE: RelocationCount: 1 +MULTISECTIONS-ARCHIVE: Type: 0x0 +MULTISECTIONS-ARCHIVE: Attributes [ (0x20000) +MULTISECTIONS-ARCHIVE: Debug (0x20000) +MULTISECTIONS-ARCHIVE: ] +MULTISECTIONS-ARCHIVE: Reserved1: 0x0 +MULTISECTIONS-ARCHIVE: Reserved2: 0x0 +MULTISECTIONS-ARCHIVE: } +MULTISECTIONS-ARCHIVE: Section { +MULTISECTIONS-ARCHIVE: Index: 3 +MULTISECTIONS-ARCHIVE: Name: __eh_frame (5F 5F 65 68 5F 66 72 61 6D 65 00 00 00 00 00 00) +MULTISECTIONS-ARCHIVE: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00) +MULTISECTIONS-ARCHIVE: Address: 0x68 +MULTISECTIONS-ARCHIVE: Size: 0x40 +MULTISECTIONS-ARCHIVE: Offset: 632 +MULTISECTIONS-ARCHIVE: Alignment: 3 +MULTISECTIONS-ARCHIVE: RelocationOffset: 0x0 +MULTISECTIONS-ARCHIVE: RelocationCount: 0 +MULTISECTIONS-ARCHIVE: Type: 0xB +MULTISECTIONS-ARCHIVE: Attributes [ (0x680000) +MULTISECTIONS-ARCHIVE: LiveSupport (0x80000) +MULTISECTIONS-ARCHIVE: NoTOC (0x400000) +MULTISECTIONS-ARCHIVE: StripStaticSyms (0x200000) +MULTISECTIONS-ARCHIVE: ] +MULTISECTIONS-ARCHIVE: Reserved1: 0x0 +MULTISECTIONS-ARCHIVE: Reserved2: 0x0 +MULTISECTIONS-ARCHIVE: } +MULTISECTIONS-ARCHIVE: ] +MULTISECTIONS-ARCHIVE: File: foo.o +MULTISECTIONS-ARCHIVE: Format: Mach-O 32-bit i386 +MULTISECTIONS-ARCHIVE: Arch: i386 +MULTISECTIONS-ARCHIVE: AddressSize: 32bit +MULTISECTIONS-ARCHIVE: Sections [ +MULTISECTIONS-ARCHIVE: Section { +MULTISECTIONS-ARCHIVE: Index: 0 +MULTISECTIONS-ARCHIVE: Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00) +MULTISECTIONS-ARCHIVE: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00) +MULTISECTIONS-ARCHIVE: Address: 0x0 +MULTISECTIONS-ARCHIVE: Size: 0x5 +MULTISECTIONS-ARCHIVE: Offset: 324 +MULTISECTIONS-ARCHIVE: Alignment: 4 +MULTISECTIONS-ARCHIVE: RelocationOffset: 0x0 +MULTISECTIONS-ARCHIVE: RelocationCount: 0 +MULTISECTIONS-ARCHIVE: Type: 0x0 +MULTISECTIONS-ARCHIVE: Attributes [ (0x800004) +MULTISECTIONS-ARCHIVE: PureInstructions (0x800000) +MULTISECTIONS-ARCHIVE: SomeInstructions (0x4) +MULTISECTIONS-ARCHIVE: ] +MULTISECTIONS-ARCHIVE: Reserved1: 0x0 +MULTISECTIONS-ARCHIVE: Reserved2: 0x0 +MULTISECTIONS-ARCHIVE: } +MULTISECTIONS-ARCHIVE: Section { +MULTISECTIONS-ARCHIVE: Index: 1 +MULTISECTIONS-ARCHIVE: Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00) +MULTISECTIONS-ARCHIVE: Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00) +MULTISECTIONS-ARCHIVE: Address: 0x8 +MULTISECTIONS-ARCHIVE: Size: 0x4 +MULTISECTIONS-ARCHIVE: Offset: 332 +MULTISECTIONS-ARCHIVE: Alignment: 2 +MULTISECTIONS-ARCHIVE: RelocationOffset: 0x0 +MULTISECTIONS-ARCHIVE: RelocationCount: 0 +MULTISECTIONS-ARCHIVE: Type: 0x0 +MULTISECTIONS-ARCHIVE: Attributes [ (0x0) +MULTISECTIONS-ARCHIVE: ] +MULTISECTIONS-ARCHIVE: Reserved1: 0x0 +MULTISECTIONS-ARCHIVE: Reserved2: 0x0 +MULTISECTIONS-ARCHIVE: } +MULTISECTIONS-ARCHIVE: ] + diff --git a/tools/llvm-readobj/llvm-readobj.cpp b/tools/llvm-readobj/llvm-readobj.cpp index 32db723fa6f..7e6ce496723 100644 --- a/tools/llvm-readobj/llvm-readobj.cpp +++ b/tools/llvm-readobj/llvm-readobj.cpp @@ -325,13 +325,12 @@ static void dumpArchive(const Archive *Arc) { static void dumpMachOUniversalBinary(const MachOUniversalBinary *UBinary) { for (const MachOUniversalBinary::ObjectForArch &Obj : UBinary->objects()) { ErrorOr> ObjOrErr = Obj.getAsObjectFile(); - if (std::error_code EC = ObjOrErr.getError()) { - reportError(UBinary->getFileName(), EC.message()); - continue; - } - - if (MachOObjectFile *MachOObj = ObjOrErr.get().get()) - dumpObject(MachOObj); + if (ObjOrErr) + dumpObject(&*ObjOrErr.get()); + else if (ErrorOr> AOrErr = Obj.getAsArchive()) + dumpArchive(&*AOrErr.get()); + else + reportError(UBinary->getFileName(), ObjOrErr.getError().message()); } }