[llvm] 61a5502 - [llvm-objdump-macho] print per-second-level-page encodings for option --unwind-info
Greg McGary via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 29 21:28:44 PST 2021
Author: Greg McGary
Date: 2021-01-29T21:59:07-07:00
New Revision: 61a5502a93ab938edc66422e41ad98757a6f920b
URL: https://github.com/llvm/llvm-project/commit/61a5502a93ab938edc66422e41ad98757a6f920b
DIFF: https://github.com/llvm/llvm-project/commit/61a5502a93ab938edc66422e41ad98757a6f920b.diff
LOG: [llvm-objdump-macho] print per-second-level-page encodings for option --unwind-info
Compact unwind entries have 8 bits for the encoding-table offset:
* offsets 0..126 reference the global commmon-encodings table, while
* offsets 127..255 reference a per-second-level-page table.
This diff teaches `llvm-objdump` to print this per-page encodings table.
Differential Revision: https://reviews.llvm.org/D93265
Added:
llvm/test/tools/llvm-objdump/MachO/Inputs/unwind-info-excess.macho-x86_64
llvm/test/tools/llvm-objdump/MachO/unwind-info-excess-x86_64.test
Modified:
llvm/tools/llvm-objdump/MachODump.cpp
Removed:
################################################################################
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 000000000000..586f8db3ae1e
Binary files /dev/null and b/llvm/test/tools/llvm-objdump/MachO/Inputs/unwind-info-excess.macho-x86_64
diff er
diff --git a/llvm/test/tools/llvm-objdump/MachO/unwind-info-excess-x86_64.test b/llvm/test/tools/llvm-objdump/MachO/unwind-info-excess-x86_64.test
new file mode 100644
index 000000000000..af1523cfd2ce
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/MachO/unwind-info-excess-x86_64.test
@@ -0,0 +1,67 @@
+## Ensure that per-page compact encodings (indexes 127 and greater)
+## appear in the output of llvm-objdump --unwind-info
+## Verify that the common encodings table is full at 0x7f (127) entries.
+##
+## TODO(gkm): The input is a binary object file constructed from a
+## large generated assembler file. For sake of expediency and
+## test-time performance, I am following the unfortunate precedent
+## that MachO test inputs are binary.
+##
+## Non-MachO tests largely use YAML inputs. As I understand it, the
+## rationale is that these MachO tests were written prior to
+## availability of sufficiently-expressive YAML processors.
+##
+## I consider YAML a submoptimal input format. Better would be
+## assembler language inputs convertable to binary via llvm-mc. In
+## the case of this test however, the input is very large and the
+## overhead of llvm-mc is terrible (~10s) on a debug build. Overhead
+## for a release build of llvm-mc is acceptable at ~1s. It would be
+## good if there were a way to prefer an installed version of llvm-mc
+## to process tests in debug build trees when not testing llvm-mc
+## itself.
+
+# RUN: llvm-objdump --unwind-info %p/Inputs/unwind-info-excess.macho-x86_64 2>/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
index 41a7d07406ff..80886c8435ba 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -8007,12 +8007,23 @@ static void printCompressedSecondLevelUnwindPage(
(void)Kind;
assert(Kind == 3 && "kind for a compressed 2nd level index should be 3");
+ uint32_t NumCommonEncodings = CommonEncodings.size();
uint16_t EntriesStart = readNext<uint16_t>(PageData, Pos);
uint16_t NumEntries = readNext<uint16_t>(PageData, Pos);
- uint16_t EncodingsStart = readNext<uint16_t>(PageData, Pos);
- readNext<uint16_t>(PageData, Pos);
- StringRef PageEncodings = PageData.substr(EncodingsStart, StringRef::npos);
+ uint16_t PageEncodingsStart = readNext<uint16_t>(PageData, Pos);
+ uint16_t NumPageEncodings = readNext<uint16_t>(PageData, Pos);
+ SmallVector<uint32_t, 64> PageEncodings;
+ if (NumPageEncodings) {
+ outs() << " Page encodings: (count = " << NumPageEncodings << ")\n";
+ Pos = PageEncodingsStart;
+ for (unsigned i = 0; i < NumPageEncodings; ++i) {
+ uint32_t Encoding = readNext<uint32_t>(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 @@ static void printCompressedSecondLevelUnwindPage(
uint32_t EncodingIdx = Entry >> 24;
uint32_t Encoding;
- if (EncodingIdx < CommonEncodings.size())
+ if (EncodingIdx < NumCommonEncodings)
Encoding = CommonEncodings[EncodingIdx];
else
- Encoding = read<uint32_t>(PageEncodings,
- sizeof(uint32_t) *
- (EncodingIdx - CommonEncodings.size()));
+ Encoding = PageEncodings[EncodingIdx - NumCommonEncodings];
outs() << " [" << i << "]: "
<< "function offset=" << format("0x%08" PRIx32, FunctionOffset)
More information about the llvm-commits
mailing list