diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -571,8 +571,10 @@ l2PagesOffset += SECOND_LEVEL_PAGE_BYTES; } // Level-1 sentinel - const CompactUnwindEntry &cuEnd = cuVector.back(); - iep->functionOffset = cuEnd.functionAddress + cuEnd.functionLength; + const CompactUnwindEntry &cuEnd = *cuPtrVector.back(); + assert(cuEnd.functionAddress != TombstoneValue); + 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 --- 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