[lld] 9e24979 - [lld/mac] Fix function offset on 1st-level unwind table sentinel
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 4 15:10:32 PDT 2021
Author: Nico Weber
Date: 2021-07-04T18:06:20-04:00
New Revision: 9e24979d73f172258aac704638501b63e39028c4
URL: https://github.com/llvm/llvm-project/commit/9e24979d73f172258aac704638501b63e39028c4
DIFF: https://github.com/llvm/llvm-project/commit/9e24979d73f172258aac704638501b63e39028c4.diff
LOG: [lld/mac] Fix function offset on 1st-level unwind table sentinel
Two bugs:
1. This tries to take the address of the last symbol plus the length
of the last symbol. However, the sorted vector is cuPtrVector,
not cuVector. Also, cuPtrVector has tombstone values removed
and cuVector doesn't. If there was a stripped value at the end,
the "last" element's value was UINT64_MAX, which meant the
sentinel value was one less than the length of that "last"
dead symbol.
2. We have to subtract in.header->addr. For 64-bit binaries that's
(1 << 32) and functionAddress is 32-bit so this is a no-op, but
for 32-bit binaries the sentinel's value was too large.
I believe this has no effect in practice since the first-level
binary search code in libunwind (in UnwindCursor.hpp) does:
uint32_t low = 0;
uint32_t high = sectionHeader.indexCount();
uint32_t last = high - 1;
while (low < high) {
uint32_t mid = (low + high) / 2;
if ((mid == last) ||
(topIndex.functionOffset(mid + 1) > targetFunctionOffset)) {
low = mid;
break;
} else {
low = mid + 1;
}
So the address of the last entry in the first-level table isn't really
checked -- except for the very end, but the check against `last` means
we just run the loop once more than necessary. But it makes `unwinddump` output
look less confusing, and it's what it looks was the intention here.
(No test since I can't think of a way to make FileCheck check that one
number is larger than another.)
Differential Revision: https://reviews.llvm.org/D105404
Added:
Modified:
lld/MachO/UnwindInfoSection.cpp
lld/test/MachO/compact-unwind.s
Removed:
################################################################################
diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp
index f78b9cefeb19..3bc1ec3445ff 100644
--- a/lld/MachO/UnwindInfoSection.cpp
+++ b/lld/MachO/UnwindInfoSection.cpp
@@ -571,8 +571,10 @@ void UnwindInfoSectionImpl<Ptr>::writeTo(uint8_t *buf) const {
l2PagesOffset += SECOND_LEVEL_PAGE_BYTES;
}
// Level-1 sentinel
- const CompactUnwindEntry<Ptr> &cuEnd = cuVector.back();
- iep->functionOffset = cuEnd.functionAddress + cuEnd.functionLength;
+ const CompactUnwindEntry<Ptr> &cuEnd = *cuPtrVector.back();
+ assert(cuEnd.functionAddress != TombstoneValue<Ptr>);
+ iep->functionOffset =
+ cuEnd.functionAddress - in.header->addr + cuEnd.functionLength;
iep->secondLevelPagesSectionOffset = 0;
iep->lsdaIndexArraySectionOffset =
lsdaOffset +
diff --git a/lld/test/MachO/compact-unwind.s b/lld/test/MachO/compact-unwind.s
index a1aa250f6c08..7aeae8923987 100644
--- a/lld/test/MachO/compact-unwind.s
+++ b/lld/test/MachO/compact-unwind.s
@@ -43,10 +43,14 @@
# CHECK: Personality functions: (count = 2)
# CHECK-DAG: personality[{{[0-9]+}}]: 0x{{0*}}[[#MY_PERSONALITY-BASE]]
# CHECK-DAG: personality[{{[0-9]+}}]: 0x{{0*}}[[#GXX_PERSONALITY-BASE]]
+# CHECK: Top level indices: (count = 2)
+# CHECK-DAG: [0]: function offset={{.*}}, 2nd level page offset=0x[[#%x,PAGEOFF:]],
+# CHECK-DAG: [1]: function offset={{.*}}, 2nd level page offset=0x00000000,
# CHECK: LSDA descriptors:
# CHECK-DAG: function offset=0x[[#%.8x,FOO-BASE]], LSDA offset=0x[[#%.8x,EXCEPTION0-BASE]]
# CHECK-DAG: function offset=0x[[#%.8x,MAIN-BASE]], LSDA offset=0x[[#%.8x,EXCEPTION1-BASE]]
# CHECK: Second level indices:
+# CHECK-NEXT: Second level index[0]: offset in section=0x[[#%.8x,PAGEOFF]]
# CHECK-DAG: function offset=0x[[#%.8x,MAIN-BASE]], encoding
# CHECK-DAG: function offset=0x[[#%.8x,FOO-BASE]], encoding
# CHECK-DAG: function offset=0x[[#%.8x,BAZ-BASE]], encoding
More information about the llvm-commits
mailing list