Writing a LLVM backend pass to dump ASM indirect branch target labels

Hello,
I’m wondering how I could implement a LLVM backend pass to figure out the possible destination labels of each indirect jump, and dump that information out.

For example, if LLVM were to generate assembly

jmpq	*.LJTI0_0(,%rcx,8)

.LJTI0_0:
	.quad	.LBB0_4
	.quad	.LBB0_54
	.quad	.LBB0_48
	.quad	.LBB0_26

At LLVM backend level, LLVM clearly knows that the jump has 4 target labels (LBB0_4/54/48/26). So I’m wondering how I could dump that information out with a backend pass.

I have tried to follow the tutorial for LLVM backend pass months ago, but just couldn’t make that work. Maybe I should give it another try, but I’m wondering what is the easiest way to do this.

P.S. this is the follow up of a previous post. I am currently using the debug info hack as mentioned in that post, but have since then encountered more and more edge case bugs… So I’m wondering how I could do this in the proper way (a LLVM backend pass).

Thanks!

Look for how MO_JumpTableIndex works; that’s the operand type for jump tables.

1 Like

Thanks for your reply! Could you please give a bit more detail on how I should do it? Do I have to implement it as a new backend pass and figure out how to put the pass into LLVM’s existing pass manager? Or is there some easier ways to do it?