This is an archive of the discontinued LLVM Phabricator instance.

Emit the CodeView `S_ARMSWITCHTABLE` debug symbol for jump tables
ClosedPublic

Authored by dpaoliello on Apr 27 2023, 11:22 AM.

Details

Summary

The CodeView S_ARMSWITCHTABLE debug symbol is used to describe the layout of a jump table, it contains the following information:

  • The address of the branch instruction that uses the jump table.
  • The address of the jump table.
  • The "base" address that the values in the jump table are relative to.
  • The type of each entry (absolute pointer, a relative integer, a relative integer that is shifted).

Together this information can be used by debuggers and binary analysis tools to understand what an jump table indirect branch is doing and where it might jump to.

Documentation for the symbol can be found in the Microsoft PDB library dumper: https://github.com/microsoft/microsoft-pdb/blob/0fe89a942f9a0f8e061213313e438884f4c9b876/cvdump/dumpsym7.cpp#L5518

This change adds support to LLVM to emit the S_ARMSWITCHTABLE debug symbol as well as to dump it out (for testing purposes).

Diff Detail

Event Timeline

dpaoliello created this revision.Apr 27 2023, 11:22 AM
dpaoliello requested review of this revision.Apr 27 2023, 11:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2023, 11:22 AM
dpaoliello edited the summary of this revision. (Show Details)Apr 27 2023, 11:23 AM
dpaoliello added reviewers: echristo, asl, akhuang, dblaikie.

Can you give an example of an existing tool which parses these for some useful purpose?

llvm/include/llvm/DebugInfo/CodeView/CodeView.h
631

Maybe worth explaining what these values actually mean? I assume "Int" is a signed offset, "Uint" is a signed offset, and ShiftLeft involves some sort of multiply. (The code you linked implies that it's a shift by 1, but maybe the interpretation is different for aarch64?)

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
3481

If a basic block is empty, this crashes, I think.

3486

This isn't obviously true; 32-bit x86 can do a table lookup and jump in one instruction.

3506

LLVM can target 32-bit ARM Windows.

llvm/test/DebugInfo/COFF/jump-table.ll
44

Why are all the section indexes "0"?

dpaoliello marked 5 inline comments as done.Apr 28 2023, 5:53 PM

Can you give an example of an existing tool which parses these for some useful purpose?

Unfortunately, I can't share specifics since the tools that I am focusing on are Microsoft-internal.

llvm/include/llvm/DebugInfo/CodeView/CodeView.h
631

I've added a comment to explain this enum. For the ShiftLeft values, the amount to shift by is implementation specific.

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
3486

I wasn't aware of that, thanks!

3506

I wasn't seeing ARM32 hit this code before, but it looks like it was because of the assumption that the branch instruction wasn't the one to use the jump table value.

I've fixed the code to handle ARM32 and added it to the tests, but there seems to be some bug where the offsets are always 0? If I run the test via llc then the correct labels appear in the debug info, but somewhere between llc -filetype=obj and llvm-readobj the offsets are lost...

llvm/test/DebugInfo/COFF/jump-table.ll
44

Looking at the other uses of emitCOFFSectionIndex (e.g., for S_THUNK32 and S_GPROC32_ID), I think this is called a "segment" not "section" in LLVM's vocabulary - I've updated the code and this test.

dpaoliello marked 4 inline comments as done.
dpaoliello edited the summary of this revision. (Show Details)

Address PR comments:

  • Don't assume branch can use the jump table address.
  • Implement ARM32 support and add tests.
efriedma added inline comments.May 1 2023, 2:22 PM
llvm/include/llvm/DebugInfo/CodeView/SymbolRecord.h
163

It looks like the other classes initialize all the fields to zero.

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
3506

In general, .secrel32 emits a relocation; llvm-readobj --codeview won't dump it, I think, but it should still be there. What's the relocation pointing to?

dpaoliello added inline comments.May 1 2023, 2:48 PM
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
3506

The "Branch" and "Base" are pointing to a label for the ADD instruction, and "Table" is pointing to the Jump Table itself:

If I run llc -mtriple=thumbv7a-windows < llvm\test\DebugInfo\COFF\jump-table.ll" I get:

        .text
        .syntax unified
        .file   "jump-table.cpp"
'x86-64' is not a recognized processor for this target (ignoring processor)
'+cx8' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'+mmx' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'+x87' is not a recognized feature for this target (ignoring feature)
'x86-64' is not a recognized processor for this target (ignoring processor)
'x86-64' is not a recognized processor for this target (ignoring processor)
'+cx8' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'+mmx' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'+x87' is not a recognized feature for this target (ignoring feature)
'x86-64' is not a recognized processor for this target (ignoring processor)
'x86-64' is not a recognized processor for this target (ignoring processor)
'x86-64' is not a recognized processor for this target (ignoring processor)
        .def    func;
        .scl    2;
        .type   32;
        .endef
        .globl  func                            @ -- Begin function func
        .p2align        2
        .code16                                 @ @func
        .thumb_func
func:
$Mfunc_begin0:
        .cv_func_id 0
        .cv_file        1 "C:\\llvm\\jump-table.cpp" "35610C7104C8080F83E2BF6A02DABFC9" 1
        .cv_loc 0 1 6 0                         @ .\jump-table.cpp:6:0
@ %bb.0:
        push    {r7, lr}
        sub     sp, #8
        str     r0, [sp, #4]
$Mtmp0:
        .cv_loc 0 1 7 0                         @ .\jump-table.cpp:7:0
        ldr     r0, [sp, #4]
        cmp     r0, #3
        bhi     ($MBB0_7)
@ %bb.1:
$Mtmp1:
        .p2align        2
        add     r0, pc
        ldrb    r0, [r0, #4]
        lsls    r0, r0, #1
.LCPI0_0:
        add     pc, r0
@ %bb.2:
        .p2align        2
.LJTI0_0:
        .byte   (($MBB0_3)-(.LCPI0_0+4))/2
        .byte   (($MBB0_4)-(.LCPI0_0+4))/2
        .byte   (($MBB0_5)-(.LCPI0_0+4))/2
        .byte   (($MBB0_6)-(.LCPI0_0+4))/2
        .p2align        1
$MBB0_3:
$Mtmp2:
        .cv_loc 0 1 8 0                         @ .\jump-table.cpp:8:0
        bl      f1
        b       ($MBB0_7)
$MBB0_4:
        .cv_loc 0 1 9 0                         @ .\jump-table.cpp:9:0
        bl      f2
        b       ($MBB0_7)
$MBB0_5:
        .cv_loc 0 1 10 0                        @ .\jump-table.cpp:10:0
        bl      f3
        b       ($MBB0_7)
$MBB0_6:
        .cv_loc 0 1 11 0                        @ .\jump-table.cpp:11:0
        bl      f4
        b       ($MBB0_7)
$Mtmp3:
$MBB0_7:
        .cv_loc 0 1 13 0                        @ .\jump-table.cpp:13:0
        ldr     r0, [sp, #4]
        subs    r0, r0, #1
        cmp     r0, #4
        bhi     ($MBB0_15)
@ %bb.8:
$Mtmp4:
        .p2align        2
        add     r0, pc
        ldrb    r0, [r0, #4]
        lsls    r0, r0, #1
.LCPI0_1:
        add     pc, r0
@ %bb.9:
        .p2align        2
.LJTI0_1:
        .byte   (($MBB0_10)-(.LCPI0_1+4))/2
        .byte   (($MBB0_11)-(.LCPI0_1+4))/2
        .byte   (($MBB0_12)-(.LCPI0_1+4))/2
        .byte   (($MBB0_13)-(.LCPI0_1+4))/2
        .byte   (($MBB0_14)-(.LCPI0_1+4))/2
        .p2align        1
$MBB0_10:
$Mtmp5:
        .cv_loc 0 1 14 0                        @ .\jump-table.cpp:14:0
        bl      f2
        b       ($MBB0_15)
$MBB0_11:
        .cv_loc 0 1 15 0                        @ .\jump-table.cpp:15:0
        bl      f3
        b       ($MBB0_15)
$MBB0_12:
        .cv_loc 0 1 16 0                        @ .\jump-table.cpp:16:0
        bl      f4
        b       ($MBB0_15)
$MBB0_13:
        .cv_loc 0 1 17 0                        @ .\jump-table.cpp:17:0
        bl      f5
        b       ($MBB0_15)
$MBB0_14:
        .cv_loc 0 1 18 0                        @ .\jump-table.cpp:18:0
        bl      f1
        b       ($MBB0_15)
$Mtmp6:
$MBB0_15:
        .cv_loc 0 1 20 0                        @ .\jump-table.cpp:20:0
        add     sp, #8
        pop     {r7}
        pop     {r0}
        mov     lr, r0
        bx      lr
$Mtmp7:
$Mfunc_end0:
                                        @ -- End function
        .section        .debug$S,"dr"
        .p2align        2, 0x0
        .long   4                               @ Debug section magic
        .long   241
        .long   ($Mtmp9)-($Mtmp8)               @ Subsection size
$Mtmp8:
        .short  ($Mtmp11)-($Mtmp10)             @ Record length
$Mtmp10:
        .short  4353                            @ Record kind: S_OBJNAME
        .long   0                               @ Signature
        .byte   0                               @ Object name
        .p2align        2, 0x0
$Mtmp11:
        .short  ($Mtmp13)-($Mtmp12)             @ Record length
$Mtmp12:
        .short  4412                            @ Record kind: S_COMPILE3
        .long   16385                           @ Flags and language
        .short  244                             @ CPUType
        .short  15                              @ Frontend version
        .short  0
        .short  1
        .short  0
        .short  17000                           @ Backend version
        .short  0
        .short  0
        .short  0
        .asciz  "clang version 15.0.1"          @ Null-terminated compiler version string
        .p2align        2, 0x0
$Mtmp13:
$Mtmp9:
        .p2align        2, 0x0
        .long   241                             @ Symbol subsection for func
        .long   ($Mtmp15)-($Mtmp14)             @ Subsection size
$Mtmp14:
        .short  ($Mtmp17)-($Mtmp16)             @ Record length
$Mtmp16:
        .short  4423                            @ Record kind: S_GPROC32_ID
        .long   0                               @ PtrParent
        .long   0                               @ PtrEnd
        .long   0                               @ PtrNext
        .long   ($Mfunc_end0)-func              @ Code size
        .long   0                               @ Offset after prologue
        .long   0                               @ Offset before epilogue
        .long   4098                            @ Function type index
        .secrel32       func                    @ Function section relative address
        .secidx func                            @ Function section index
        .byte   0                               @ Flags
        .asciz  "func"                          @ Function name
        .p2align        2, 0x0
$Mtmp17:
        .short  ($Mtmp19)-($Mtmp18)             @ Record length
$Mtmp18:
        .short  4114                            @ Record kind: S_FRAMEPROC
        .long   16                              @ FrameSize
        .long   0                               @ Padding
        .long   0                               @ Offset of padding
        .long   0                               @ Bytes of callee saved registers
        .long   0                               @ Exception handler offset
        .short  0                               @ Exception handler section
        .long   90112                           @ Flags (defines frame register)
        .p2align        2, 0x0
$Mtmp19:
        .short  ($Mtmp21)-($Mtmp20)             @ Record length
$Mtmp20:
        .short  4414                            @ Record kind: S_LOCAL
        .long   116                             @ TypeIndex
        .short  1                               @ Flags
        .asciz  "i"
        .p2align        2, 0x0
$Mtmp21:
        .cv_def_range    $Mtmp0 $Mtmp7, reg_rel, 23, 0, 4
        .short  ($Mtmp23)-($Mtmp22)             @ Record length
$Mtmp22:
        .short  4441                            @ Record kind: S_ARMSWITCHTABLE
        .secrel32       .LCPI0_0                @ Base offset
        .secidx .LCPI0_0                        @ Base section index
        .short  7                               @ Switch type
        .secrel32       .LCPI0_0                @ Branch offset
        .secrel32       .LJTI0_0                @ Table offset
        .secidx .LCPI0_0                        @ Branch section index
        .secidx .LJTI0_0                        @ Table section index
        .long   4                               @ Entries count
        .p2align        2, 0x0
$Mtmp23:
        .short  ($Mtmp25)-($Mtmp24)             @ Record length
$Mtmp24:
        .short  4441                            @ Record kind: S_ARMSWITCHTABLE
        .secrel32       .LCPI0_1                @ Base offset
        .secidx .LCPI0_1                        @ Base section index
        .short  7                               @ Switch type
        .secrel32       .LCPI0_1                @ Branch offset
        .secrel32       .LJTI0_1                @ Table offset
        .secidx .LCPI0_1                        @ Branch section index
        .secidx .LJTI0_1                        @ Table section index
        .long   5                               @ Entries count
        .p2align        2, 0x0
$Mtmp25:
        .short  2                               @ Record length
        .short  4431                            @ Record kind: S_PROC_ID_END
$Mtmp15:
        .p2align        2, 0x0
        .cv_linetable   0, func, $Mfunc_end0
        .cv_filechecksums                       @ File index to string table offset subsection
        .cv_stringtable                         @ String table
        .long   241
        .long   ($Mtmp27)-($Mtmp26)             @ Subsection size
$Mtmp26:
        .short  ($Mtmp29)-($Mtmp28)             @ Record length
$Mtmp28:
        .short  4428                            @ Record kind: S_BUILDINFO
        .long   4102                            @ LF_BUILDINFO index
        .p2align        2, 0x0
$Mtmp29:
$Mtmp27:
        .p2align        2, 0x0
        .section        .debug$T,"dr"
        .p2align        2, 0x0
        .long   4                               @ Debug section magic
        @ ArgList (0x1000)
        .short  0xa                             @ Record length
        .short  0x1201                          @ Record kind: LF_ARGLIST
        .long   0x1                             @ NumArgs
        .long   0x74                            @ Argument: int
        @ Procedure (0x1001)
        .short  0xe                             @ Record length
        .short  0x1008                          @ Record kind: LF_PROCEDURE
        .long   0x3                             @ ReturnType: void
        .byte   0x0                             @ CallingConvention: NearC
        .byte   0x0                             @ FunctionOptions
        .short  0x1                             @ NumParameters
        .long   0x1000                          @ ArgListType: (int)
        @ FuncId (0x1002)
        .short  0x12                            @ Record length
        .short  0x1601                          @ Record kind: LF_FUNC_ID
        .long   0x0                             @ ParentScope
        .long   0x1001                          @ FunctionType: void (int)
        .asciz  "func"                          @ Name
        .byte   243
        .byte   242
        .byte   241
        @ StringId (0x1003)
        .short  0xe                             @ Record length
        .short  0x1605                          @ Record kind: LF_STRING_ID
        .long   0x0                             @ Id
        .asciz  "C:\\llvm"                      @ StringData
        @ StringId (0x1004)
        .short  0x16                            @ Record length
        .short  0x1605                          @ Record kind: LF_STRING_ID
        .long   0x0                             @ Id
        .asciz  "jump-table.cpp"                @ StringData
        .byte   241
        @ StringId (0x1005)
        .short  0xa                             @ Record length
        .short  0x1605                          @ Record kind: LF_STRING_ID
        .long   0x0                             @ Id
        .byte   0                               @ StringData
        .byte   243
        .byte   242
        .byte   241
        @ BuildInfo (0x1006)
        .short  0x1a                            @ Record length
        .short  0x1603                          @ Record kind: LF_BUILDINFO
        .short  0x5                             @ NumArgs
        .long   0x1003                          @ Argument: C:\llvm
        .long   0x0                             @ Argument
        .long   0x1004                          @ Argument: jump-table.cpp
        .long   0x1005                          @ Argument
        .long   0x0                             @ Argument
        .byte   242
        .byte   241
efriedma added inline comments.May 1 2023, 3:05 PM
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
3506

That makes sense... I think it's pointing to the right location, there just isn't any offset because there's a symbol at that address. (Arguably there shouldn't be such a symbol, but that's not really related to your patch.) On other targets, the closest symbol is probably the function entry point.

Maybe we could teach llvm-readobj to dump this in a more useful way; instead of just dumping the offset, it could also dump any related relocations. But it doesn't look like the compiler is doing anything wrong.

dpaoliello updated this revision to Diff 518585.May 1 2023, 3:45 PM
  • Initialize JumpTableSym integer fields.
  • Fix ARM32 to use a base address *after* the branch instructions.
dpaoliello marked an inline comment as done.May 1 2023, 3:49 PM
dpaoliello added inline comments.May 2 2023, 10:27 AM
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
3506

@efriedma I'd prefer if we didn't block this change because of the ARM32 issue: LLVM has never fully supported ARM32 Windows (for example exception unwinding isn't implemented) and from a Microsoft perspective we haven't shipped an ARM32 OS since Windows 10 IoT Core in 2018 and ARM32 support is being removed from Windows 11 (https://learn.microsoft.com/en-us/windows/arm/arm32-to-arm64)

efriedma added inline comments.May 9 2023, 2:05 PM
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
3498

I'm concerned this could fail to find the jump table, or find the wrong jump table. It is possible to hoist some jump-table-related operations into an earlier block. For example:

extern "C" void f1();
extern "C" void f2();
extern "C" void f3();
extern "C" void f4();
extern "C" void f5();
extern "C" void func(int i, int j){
  for (int k = 0; k < j; ++k) {
    switch (i) {
        case 0: f1(); break;
        case 1: f2(); break;
        case 2: f3(); break;
        case 3: f4(); break;
    }
  }
}

On AArch64, we produce:

// %bb.1:
        mov     w19, w1
        mov     w20, w0
        mov     w21, w0
        adrp    x22, .LJTI0_0
        add     x22, x22, :lo12:.LJTI0_0
        b       .LBB0_4
.LBB0_2:                                // %sw.bb3
                                        //   in Loop: Header=BB0_4 Depth=1
        bl      f4
.LBB0_3:                                // %for.inc
                                        //   in Loop: Header=BB0_4 Depth=1
        subs    w19, w19, #1
        b.eq    .LBB0_9
.LBB0_4:                                // %for.body
                                        // =>This Inner Loop Header: Depth=1
        cmp     w20, #3
        b.hi    .LBB0_3
// %bb.5:                               // %for.body
                                        //   in Loop: Header=BB0_4 Depth=1
        adr     x8, .LBB0_2
        ldrb    w9, [x22, x21]
        add     x8, x8, x9, lsl #2
        br      x8

Off the top of my head, I'm not sure how to write a testcase where it actually finds the wrong table, but I suspect it's possible.

We might need to encode the associated jump table into the MachineInstrs some other way. I'm not sure what that looks like, exactly; maybe a pseudo-instruction just before the jump?

3506

My point was, if I'm understanding correctly, we're actually generating the correct code; it just looks weird in the dumps. So I don't think we need to do anything... except maybe add a few CHECK lines for the relocations in the regression tests. Teaching the dumping tools to make the dumps look less weird was just a "would be nice" thought.

efriedma added inline comments.May 9 2023, 2:49 PM
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
3498

Err, I guess on aarch64, you can pull the table out of the JumpTableDest32 instruction, which we currently don't hoist. But on x86, we don't do jump table compression, so there's no such operand.

dpaoliello added inline comments.May 17 2023, 2:05 PM
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
3498

I've been trying to figure out how to do this, and I'm lost: I can see where the branch instructions are added, but I don't know how to create a pseudo-instruction just before them. There also seems to be DbgValues, which seems like it may be useful but I also don't understand how to create those either.

Don't suppose someone can point me to an example where someone else has done something similar?

efriedma added inline comments.May 17 2023, 2:26 PM
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
3498

Not sure exactly where you're trying to add code to insert the pseudo-instructions, but maybe https://reviews.llvm.org/D125648 is helpful as reference?

dpaoliello updated this revision to Diff 529053.Jun 6 2023, 2:52 PM

Remove the "scan back" for a jump table operand and replaced it with an explicit pseudo instruction

dpaoliello marked 3 inline comments as done.Jun 6 2023, 2:53 PM

Fix pseudo instruction getting dropped when building with all optimizations enabled

efriedma added inline comments.Jun 19 2023, 3:40 PM
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
1587

Just to be on the safe side, I'd prefer to check for any arm/thumb target; I'm not sure we consistently end up with a "thumb" triple building for Thumb2. (You can assume any 32-bit ARM code on Windows is Thumb2; we don't support any targets other than windows 8/10.)

llvm/lib/Target/X86/X86ISelLowering.cpp
35744

Leftover debug code?

dpaoliello marked 2 inline comments as done.Jun 20 2023, 5:47 PM
dpaoliello added inline comments.
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
1587

Per mapArchToCVCPUType (line 116 of this file), we only support thumb for ARM32 and any other value would result in a fatal error.

llvm/lib/Target/X86/X86ISelLowering.cpp
35744

Yep, will remove.

dpaoliello marked 2 inline comments as done.

Removed JUMP_TABLE_DEBUG_INFO from IsDebugInstr, this was causing the instruction to be moved or dropped incorrectly.

dpaoliello edited the summary of this revision. (Show Details)

Fix MIPS tests

efriedma added inline comments.Jul 2 2023, 11:41 PM
llvm/test/CodeGen/Mips/jumptable_labels.ll
1 ↗(On Diff #534091)

What exactly was going wrong here? I guess we somehow assume we're emitting CodeView debug info, and then things explode?

Can we make the relevant codepaths check getCodeViewFlag() (which is apparently the canonical way to check according to AsmPrinter::doInitialization())?

dpaoliello edited the summary of this revision. (Show Details)
  • Use getCodeViewFlag instead of isOSWindows to gate adding a jump table debug info node.
  • Improve tests to workaround llvm-readobj not working for ARM32 correctly.
dpaoliello marked 4 inline comments as done.Jul 5 2023, 12:18 PM
dpaoliello added inline comments.
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
3506

I've modified the test to check the assembly directly instead of using llvm-readobj: this also allows me to verify that the CodeView has the correct labels instead of verifying meaningless offsets.
I added another test case using llvm-readobj to make sure that the new symbol can be dumped correctly.

llvm/test/CodeGen/Mips/jumptable_labels.ll
1 ↗(On Diff #534091)

Ah, ok, adding the jump table debug info node in TargetLowering::expandIndirectJTBranch was gated on isOSWindows which caused it to still be added for these tests. Changing it to getCodeViewFlag fixed the issue without having to change these tests.

efriedma added inline comments.Jul 6 2023, 2:00 PM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
481

I apologize for the run-around on this, but I just realized we shouldn't use getCodeViewFlag() here because it'll cause codegen to change based on whether debug info is enabled, which we try to avoid.

Maybe just check isOSBinFormatCOFF().

dpaoliello updated this revision to Diff 537901.Jul 6 2023, 3:25 PM
dpaoliello marked 2 inline comments as done.

Change check in TargetLowering::expandIndirectJTBranch to isOSBinFormatCOFF

dpaoliello marked an inline comment as done.Jul 6 2023, 3:25 PM
dpaoliello added inline comments.
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
481

No worries: done.

dpaoliello marked an inline comment as done.Aug 1 2023, 4:27 PM
dpaoliello updated this revision to Diff 547924.Aug 7 2023, 1:19 PM

Sync to HEAD

This revision is now accepted and ready to land.Aug 23 2023, 3:46 PM
erikdesjardins added inline comments.
llvm/test/DebugInfo/COFF/jump-table.ll
4

This test is failing on the bots: https://lab.llvm.org/buildbot/#/builders/139/builds/48355

******************** TEST 'LLVM :: DebugInfo/COFF/jump-table.ll' FAILED ********************

<snip>

Exit Code: 2
Command Output (stderr):
--
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc: error: unable to get target for 'aarch64-unknown-windows-msvc', see --version and --triple.

Please fix or revert.

this is causing crashes:

$ cat /tmp/a.ll
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.34.0"

define i32 @f() !dbg !5 {
entry:
  indirectbr ptr null, [label %BC_SUCCEED]

BC_SUCCEED:                                       ; preds = %entry
  %0 = lshr i64 0, 0
  switch i64 %0, label %sw.default.i.i2445 [
    i64 3, label %sw.bb15.i.i
    i64 1, label %sw.bb7.i.i
    i64 2, label %sw.bb11.i.i2444
    i64 0, label %sw.bb3.i.i
  ]

sw.bb3.i.i:                                       ; preds = %BC_SUCCEED
  ret i32 0

sw.bb7.i.i:                                       ; preds = %BC_SUCCEED
  ret i32 0

sw.bb11.i.i2444:                                  ; preds = %BC_SUCCEED
  ret i32 0

sw.bb15.i.i:                                      ; preds = %BC_SUCCEED
  ret i32 0

sw.default.i.i2445:                               ; preds = %BC_SUCCEED
  ret i32 0
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "../../v8/src/regexp\\regexp-interpreter.cc", directory: ".", checksumkind: CSK_MD5, checksum: "ddba353f72137fb1d64b5fc8ee071a9c")
!2 = !{}
!3 = !{i32 2, !"CodeView", i32 1}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = distinct !DISubprogram(name: "f", linkageName: "f", scope: !7, file: !6, line: 386, type: !10, scopeLine: 391, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, templateParams: !2, retainedNodes: !2)
!6 = !DIFile(filename: "../../v8/src/regexp/regexp-interpreter.cc", directory: ".", checksumkind: CSK_MD5, checksum: "ddba353f72137fb1d64b5fc8ee071a9c")
!7 = !DINamespace(scope: !8)
!8 = !DINamespace(name: "internal", scope: !9)
!9 = !DINamespace(name: "v8", scope: null)
!10 = distinct !DISubroutineType(types: !2)
$ llc -o /dev/null /tmp/a.ll
llc: ../../llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:3495: void forEachJumpTableBranch(const MachineFunction *, bool, const std::function<void (const MachineJumpTableInfo &, const MachineInstr &, int64_t)> &): Assertion `foundJTI' failed.

reverted in https://reviews.llvm.org/rG0a4fc4ac1c6e74eba7eb184d3da11772a06df65f, when relanding make sure to reland with the fixes mentioned in the revert description

aeubanks reopened this revision.Aug 25 2023, 6:42 PM
This revision is now accepted and ready to land.Aug 25 2023, 6:42 PM
  • Merged in test and build fixes.
  • Changed assert to validate that all jump tables had an associated info instruction, rather than checking that all indirect branches have an JT info instruction
dpaoliello marked an inline comment as done.Aug 30 2023, 3:38 PM

should be good to reland if you've fixed the crash

Update to HEAD to fix build issue