diff --git a/llvm/test/tools/llvm-objdump/MachO/Inputs/unwind-info-excess.macho-x86_64 b/llvm/test/tools/llvm-objdump/MachO/Inputs/unwind-info-excess.macho-x86_64 new file mode 100755 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@/dev/null | FileCheck %s + +# CHECK:Contents of __unwind_info section: +# CHECK-NEXT: Version: 0x1 +# CHECK-NEXT: Common encodings array section offset: 0x1c +# CHECK-NEXT: Number of common encodings in array: 0x7f + +# CHECK: Second level indices: +# CHECK: Second level index[0]: offset in section +# CHECK: Page encodings: (count = 17) +# CHECK: encoding[127]: 0x01010003 +# CHECK: encoding[128]: 0x01010002 +# CHECK: encoding[129]: 0x01010001 +# CHECK: encoding[130]: 0x0102001d +# CHECK: encoding[131]: 0x01020015 +# CHECK: encoding[132]: 0x0102000d +# CHECK: encoding[133]: 0x0102001c +# CHECK: encoding[134]: 0x01020014 +# CHECK: encoding[135]: 0x0102000c +# CHECK: encoding[136]: 0x01020013 +# CHECK: encoding[137]: 0x0102000b +# CHECK: encoding[138]: 0x01020022 +# CHECK: encoding[139]: 0x0102001a +# CHECK: encoding[140]: 0x0102000a +# CHECK: encoding[141]: 0x01020021 +# CHECK: encoding[142]: 0x01020019 +# CHECK: encoding[143]: 0x01020011 + +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[127]=0x01010003 +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[128]=0x01010002 +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[129]=0x01010001 +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[130]=0x0102001d +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[131]=0x01020015 +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[132]=0x0102000d +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[133]=0x0102001c +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[134]=0x01020014 +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[135]=0x0102000c +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[136]=0x01020013 +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[137]=0x0102000b +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[138]=0x01020022 +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[139]=0x0102001a +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[140]=0x0102000a +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[141]=0x01020021 +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[142]=0x01020019 +# CHECK: [{{[0-9]+}}]: function offset={{[x0-9a-f]+}}, encoding[143]=0x01020011 diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -8007,12 +8007,23 @@ (void)Kind; assert(Kind == 3 && "kind for a compressed 2nd level index should be 3"); + uint32_t NumCommonEncodings = CommonEncodings.size(); uint16_t EntriesStart = readNext(PageData, Pos); uint16_t NumEntries = readNext(PageData, Pos); - uint16_t EncodingsStart = readNext(PageData, Pos); - readNext(PageData, Pos); - StringRef PageEncodings = PageData.substr(EncodingsStart, StringRef::npos); + uint16_t PageEncodingsStart = readNext(PageData, Pos); + uint16_t NumPageEncodings = readNext(PageData, Pos); + SmallVector PageEncodings; + if (NumPageEncodings) { + outs() << " Page encodings: (count = " << NumPageEncodings << ")\n"; + Pos = PageEncodingsStart; + for (unsigned i = 0; i < NumPageEncodings; ++i) { + uint32_t Encoding = readNext(PageData, Pos); + PageEncodings.push_back(Encoding); + outs() << " encoding[" << (i + NumCommonEncodings) + << "]: " << format("0x%08" PRIx32, Encoding) << '\n'; + } + } Pos = EntriesStart; for (unsigned i = 0; i < NumEntries; ++i) { @@ -8021,12 +8032,10 @@ uint32_t EncodingIdx = Entry >> 24; uint32_t Encoding; - if (EncodingIdx < CommonEncodings.size()) + if (EncodingIdx < NumCommonEncodings) Encoding = CommonEncodings[EncodingIdx]; else - Encoding = read(PageEncodings, - sizeof(uint32_t) * - (EncodingIdx - CommonEncodings.size())); + Encoding = PageEncodings[EncodingIdx - NumCommonEncodings]; outs() << " [" << i << "]: " << "function offset=" << format("0x%08" PRIx32, FunctionOffset)