Index: lld/MachO/UnwindInfoSection.cpp =================================================================== --- lld/MachO/UnwindInfoSection.cpp +++ lld/MachO/UnwindInfoSection.cpp @@ -568,8 +568,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 != static_cast(UINT64_MAX)); + iep->functionOffset = + cuEnd.functionAddress - in.header->addr + cuEnd.functionLength; iep->secondLevelPagesSectionOffset = 0; iep->lsdaIndexArraySectionOffset = lsdaOffset + Index: lld/test/MachO/compact-unwind.s =================================================================== --- lld/test/MachO/compact-unwind.s +++ 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=[[#%x,PAGEOFF:]], LSDA offset= +# CHECK-DAG: [1]: function offset={{.*}}, 2nd level page offset=0x00000000, LSDA offset= # 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={{.*}}, base function offset=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