Index: llvm/lib/MC/MCWin64EH.cpp =================================================================== --- llvm/lib/MC/MCWin64EH.cpp +++ llvm/lib/MC/MCWin64EH.cpp @@ -576,7 +576,13 @@ if (CodeWordsMod) CodeWords++; uint32_t EpilogCount = info->EpilogMap.size(); - bool ExtensionWord = EpilogCount > 31 || TotalCodeBytes > 124; + // If we need to signal a larger EpilogCount or TotalCodeBytes, we need to + // use the extension word, and leave those fields as zero in row1. + // If both EpilogCount and CodeWords actually are zero though (e.g. due to + // missing/incomplete .seh directives in assembly), we still need to include + // the extension word, as that is how the reader will interpret it. + bool ExtensionWord = EpilogCount > 31 || TotalCodeBytes > 124 || + (EpilogCount == 0 && CodeWords == 0); if (!ExtensionWord) { row1 |= (EpilogCount & 0x1F) << 22; row1 |= (CodeWords & 0x1F) << 27; Index: llvm/test/MC/AArch64/seh.s =================================================================== --- llvm/test/MC/AArch64/seh.s +++ llvm/test/MC/AArch64/seh.s @@ -1,6 +1,8 @@ // This test checks that the SEH directives don't cause the assembler to fail. +// Checking that llvm-readobj doesn't bail out on the unwind data, but not +// really checking the contents yet. -// RUN: llvm-mc -triple aarch64-pc-win32 -filetype=obj %s | llvm-readobj -S -r - | FileCheck %s +// RUN: llvm-mc -triple aarch64-pc-win32 -filetype=obj %s | llvm-readobj -S -r -u - | FileCheck %s // CHECK: Sections [ // CHECK: Section { @@ -15,7 +17,7 @@ // CHECK-NEXT: } // CHECK: Section { // CHECK: Name: .xdata -// CHECK: RawDataSize: 20 +// CHECK: RawDataSize: 24 // CHECK: RelocationCount: 1 // CHECK: Characteristics [ // CHECK-NEXT: ALIGN_4BYTES