On Thu, Sep 10, 2020 at 01:16:57PM +0200, Jakub Jelinek via Gcc-patches wrote:
> As for the test assembly, I'd say we should take
> #define F void foo (void) {}
> F
> compile it with
> gcc -S -O2 -g1 -dA -gno-as-loc-support -fno-merge-debug-strings
> remove .cfi_* directives, remove the ret instruction, change @function
> and @progbits to %function and %progbits, change .uleb128 to just .byte,
> I think all the values should be small enough, maybe change .value to
> .2byte and .long to .4byte (whatever is most portable across different
> arches and gas versions), simplify (shorten) strings and adjust
> sizes, and do something with the .quad directives, that is dependent on
> the address size, perhaps just take those attributes out and adjust
> .debug_abbrev?  Finally, remove all comments (emit them in the first case
> just to better understand the debug info).

I'm afraid it is hard to avoid the .quad or .8byte.
Here is a 64-bit address version that assembles fine by both x86_64 and
aarch64 as.
Unfortunately doesn't fail with broken gas versions with -gdwarf-2 without
the nop, so we'll need at least a nop in there.
Fortunately gcc/configure.ac already determines the right nop insn for the
target, in $insn.
So I guess what we want next is have the 32-bit version of this with .4byte
instead of .8byte and just let's try to assemble both versions, first
without -gdwarf-2 and the one that succeeds assemble again with -gdwarf-2
and check for the duplicate .debug_line sections error.
What do you think?

        .file   "a.c"
        .text
.Ltext0:
        .p2align 4
        .globl  foo
        .type   foo, %function
foo:
.LFB0:
.LM1:
        nop
.LM2:
.LFE0:
        .size   foo, .-foo
.Letext0:
        .section        .debug_info,"",%progbits
.Ldebug_info0:
        .4byte  0x46
        .2byte  0x4
        .4byte  .Ldebug_abbrev0
        .byte   0x8
        .byte   0x1
        .ascii "GNU C17\0"
        .byte   0xc
        .ascii "a.c\0"
        .ascii "/\0"
        .8byte  .Ltext0
        .8byte  .Letext0-.Ltext0
        .4byte  .Ldebug_line0
        .byte   0x2
        .ascii "foo\0"
        .byte   0x1
        .byte   0x2
        .byte   0x1
        .8byte  .LFB0
        .8byte  .LFE0-.LFB0
        .byte   0x1
        .byte   0x9c
        .byte   0
        .section        .debug_abbrev,"",%progbits
.Ldebug_abbrev0:
        .byte   0x1
        .byte   0x11
        .byte   0x1
        .byte   0x25
        .byte   0x8
        .byte   0x13
        .byte   0xb
        .byte   0x3
        .byte   0x8
        .byte   0x1b
        .byte   0x8
        .byte   0x11
        .byte   0x1
        .byte   0x12
        .byte   0x7
        .byte   0x10
        .byte   0x17
        .byte   0
        .byte   0
        .byte   0x2
        .byte   0x2e
        .byte   0
        .byte   0x3f
        .byte   0x19
        .byte   0x3
        .byte   0x8
        .byte   0x3a
        .byte   0xb
        .byte   0x3b
        .byte   0xb
        .byte   0x39
        .byte   0xb
        .byte   0x11
        .byte   0x1
        .byte   0x12
        .byte   0x7
        .byte   0x40
        .byte   0x18
        .byte   0
        .byte   0
        .byte   0
        .section        .debug_aranges,"",%progbits
        .4byte  0x2c
        .2byte  0x2
        .4byte  .Ldebug_info0
        .byte   0x8
        .byte   0
        .2byte  0
        .2byte  0
        .8byte  .Ltext0
        .8byte  .Letext0-.Ltext0
        .8byte  0
        .8byte  0
        .section        .debug_line,"",%progbits
.Ldebug_line0:
        .4byte  .LELT0-.LSLT0
.LSLT0:
        .2byte  0x4
        .4byte  .LELTP0-.LASLTP0
.LASLTP0:
        .byte   0x1
        .byte   0x1
        .byte   0x1
        .byte   0xf6
        .byte   0xf2
        .byte   0xd
        .byte   0
        .byte   0x1
        .byte   0x1
        .byte   0x1
        .byte   0x1
        .byte   0
        .byte   0
        .byte   0
        .byte   0x1
        .byte   0
        .byte   0
        .byte   0x1
        .byte   0
        .ascii "a.c\0"
        .byte   0
        .byte   0
        .byte   0
        .byte   0
.LELTP0:
        .byte   0
        .byte   0x9
        .byte   0x2
        .8byte  .LM1
        .byte   0x18
        .byte   0x5
        .byte   0x1
        .byte   0
        .byte   0x9
        .byte   0x2
        .8byte  .LM2
        .byte   0x1
        .byte   0x5
        .byte   0x1
        .byte   0
        .byte   0x9
        .byte   0x2
        .8byte  .Letext0
        .byte   0
        .byte   0x1
        .byte   0x1
.LELT0:
        .section        .debug_str,"",%progbits
        .ident  "GCC"


        Jakub

Reply via email to