Re: [RFC 6/8] x86_64/bug: Implement __WARN_printf()

Peter Zijlstra
2025-06-02T22:02:02Z

On Mon, Jun 02, 2025 at 11:57:25PM +0200, Peter Zijlstra wrote:
> On Mon, Jun 02, 2025 at 09:38:09AM -0700, Linus Torvalds wrote:
>
> > And no, I'm not ok with only using 'objdump' and friends to look at
> > assembly generation. I want to be able to do
> >
> > make xyz.s
> >
> > and look at code generation without throwing up.
>
> So if I stuff the asm macro in a global asm() block then GCC ends up
> looking like so:
>
> .set warn_imm, 0
> warn_add_reg var=warn_imm reg=%rcx # tmp215
> .set warn_imm, (warn_imm << 4)
> warn_add_reg var=warn_imm reg=%rdx # tmp212
> 1: ud1 warn_imm(%ecx),%rax # tmp210
> .pushsection .discard.annotate_insn,"M",@progbits,8
> .long 1b - .
> .long 8
> .popsection
> .pushsection __bug_table, "aw" ; 123: .long 1b - . ; .long .LC76 - . ; .long .LC0 - . ; .word 8710 ; .word 2321 ; .org 123b + 6 + 4 + 6 ; .popsection #,,,
>
> However, clangd is 'helpful' and fully expands the asm macro for the .s
> file :-(

It generates his horror show:

#APP
.set warn_imm, 0
.set .Lregnr, 0
.set .Lregnr, 1
.set .Lregnr, 2
.set warn_imm, 2
.set .Lregnr, 3
.set .Lregnr, 4
.set .Lregnr, 5
.set .Lregnr, 6
.set .Lregnr, 7
.set .Lregnr, 8
.set .Lregnr, 9
.set .Lregnr, 10
.set .Lregnr, 11
.set .Lregnr, 12
.set .Lregnr, 13
.set .Lregnr, 14
.set .Lregnr, 15
.set .Lregnr, 16
.set .Lregnr, 0
.set .Lregnr, 1
.set .Lregnr, 2
.set .Lregnr, 3
.set .Lregnr, 4
.set .Lregnr, 5
.set .Lregnr, 6
.set .Lregnr, 7
.set .Lregnr, 8
.set .Lregnr, 9
.set .Lregnr, 10
.set .Lregnr, 11
.set .Lregnr, 12
.set .Lregnr, 13
.set .Lregnr, 14
.set .Lregnr, 15
.set .Lregnr, 16
.set warn_imm, 32
.set .Lregnr, 0
.set .Lregnr, 1
.set warn_imm, 33
.set .Lregnr, 2
.set .Lregnr, 3
.set .Lregnr, 4
.set .Lregnr, 5
.set .Lregnr, 6
.set .Lregnr, 7
.set .Lregnr, 8
.set .Lregnr, 9
.set .Lregnr, 10
.set .Lregnr, 11
.set .Lregnr, 12
.set .Lregnr, 13
.set .Lregnr, 14
.set .Lregnr, 15
.set .Lregnr, 16
.set .Lregnr, 0
.set .Lregnr, 1
.set .Lregnr, 2
.set .Lregnr, 3
.set .Lregnr, 4
.set .Lregnr, 5
.set .Lregnr, 6
.set .Lregnr, 7
.set .Lregnr, 8
.set .Lregnr, 9
.set .Lregnr, 10
.set .Lregnr, 11
.set .Lregnr, 12
.set .Lregnr, 13
.set .Lregnr, 14
.set .Lregnr, 15
.set .Lregnr, 16
.Ltmp1656:
ud1q 33(%ecx), %rax
.section .discard.annotate_insn,"M",@progbits,8
.Ltmp1657:
.long .Ltmp1656-.Ltmp1657
.long 8
.section .init.text,"ax",@progbits

.section __bug_table,"aw",@progbits
.Ltmp1658:
.Ltmp1659:
.long .Ltmp1656-.Ltmp1659
.Ltmp1660:
.long .L.str.29-.Ltmp1660
.Ltmp1661:
.long .L.str-.Ltmp1661
.short 8710
.short 2321
.org ((.Ltmp1658+6)+4)+6, 0
.section .init.text,"ax",@progbits

#NO_APP