Re: [PATCH pahole 1/4] dwarves: revert semantics of member bit/byte hole

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Em Wed, Apr 03, 2019 at 04:05:06PM +0200, Mark Wielaard escreveu:
> Hi,
> 
> On Wed, 2019-04-03 at 10:19 -0300, Arnaldo Carvalho de Melo wrote:
> > Most are false positives, as DWARF (let alone BTF) has explicit ways
> > to tell that these are all __attribute__((aligned(something)) and
> > pahole still don't infer those by realizing that its not a natural
> > alignment, a heuristic that would catch most of these bigger holes,
> > such as:
> 
> DWARF does have DW_AT_alignment and GCC8 does output it.

Excellent! So it is GCC that first used it? I just checked with this
vmlinux:

 <0><2d>: Abbrev Number: 121 (DW_TAG_compile_unit)
    <2e>   DW_AT_producer    : (indirect string, offset: 0x5d0c): GNU C89 8.2.1 20181215 (Red Hat 8.2.1-6) -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -mno-80387 -mno-f
p-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -mindirect-branch=thunk-extern -mindirect-branch-register -mrecord-mcount
 -mfentry -march=x86-64 -g -O2 -std=gnu90 -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -falign-jumps=1 -falign-loops=1 -fno-asynchronous-unwind-tables -fno-delete-nul
l-pointer-checks -fstack-protector-strong -fno-var-tracking-assignments -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fstack-check=no -fconserve-stack --param
 allow-store-data-races=0

 And indeed:

[acme@quaco pahole]$ readelf -wi vmlinux  | grep DW_AT_alignment.*:*4096  | head
    <451d>   DW_AT_alignment   : 4096
    <453d>   DW_AT_alignment   : 4096
    <4583>   DW_AT_alignment   : 4096
    <d62d>   DW_AT_alignment   : 4096
    <d6c8>   DW_AT_alignment   : 4096
    <d715>   DW_AT_alignment   : 4096
    <d737>   DW_AT_alignment   : 4096
    <d748>   DW_AT_alignment   : 4096
    <d766>   DW_AT_alignment   : 4096
    <d7ef>   DW_AT_alignment   : 4096
[acme@quaco pahole]$

Thanks for the pointer, going to my TODO to use when rebuilding the data
structures, i.e. in class__fprintf() and also to be taken into account
in the reorganize code.

- Arnaldo
 
>    DW_AT_alignment Non-default alignment of type, subprogram or
>    variable
> 
>    2.24 Alignment
> 
>    A debugging information entry may have a DW_AT_alignment attribute
>    whose value of class constant is a positive, non-zero, integer
>    describing the alignment of the entity.
> 
>    For example, an alignment attribute whose value is 8 indicates that
>    the entity to which it applies occurs at an address that is a
>    multiple of eight (not a multiple of 2^8 or 256).
> 
> $ cat align.c 
> struct tt {
>   char *ptr;
>   int __attribute__((__aligned__(64))) i;
>   int n;
> } t;
> 
> $ gcc -g -c align.c
> $ eu-readelf --debug-dump=info align.o
> 
> DWARF section [ 4] '.debug_info' at offset 0x40:
>  [Offset]
>  Compilation unit at offset 0:
>  Version: 4, Abbreviation section offset: 0, Address size: 8, Offset
> size: 4
>  [     b]  compile_unit         abbrev: 1
>            producer             (strp) "GNU C17 8.2.1 20180905 (Red Hat
> 8.2.1-3) -mtune=generic -march=x86-64 -g"
>            language             (data1) C99 (12)
>            name                 (strp) "align.c"
>            comp_dir             (strp) "/tmp"
>            stmt_list            (sec_offset) 0
>  [    1d]    structure_type       abbrev: 2
>              name                 (string) "tt"
>              byte_size            (data1) 128
>              alignment            (data1) 64
>              decl_file            (data1) align.c (1)
>              decl_line            (data1) 1
>              decl_column          (data1) 8
>              sibling              (ref4) [    4f]
>  [    2a]      member               abbrev: 3
>                name                 (string) "ptr"
>                decl_file            (data1) align.c (1)
>                decl_line            (data1) 2
>                decl_column          (data1) 9
>                type                 (ref4) [    4f]
>                data_member_location (data1) 0
>  [    37]      member               abbrev: 4
>                name                 (string) "i"
>                decl_file            (data1) align.c (1)
>                decl_line            (data1) 3
>                decl_column          (data1) 40
>                type                 (ref4) [    5c]
> HERE =>        alignment            (data1) 64
>                data_member_location (data1) 40
>  [    43]      member               abbrev: 3
>                name                 (string) "n"
>                decl_file            (data1) align.c (1)
>                decl_line            (data1) 4
>                decl_column          (data1) 7
>                type                 (ref4) [    5c]
>                data_member_location (data1) 44
>  [    4f]    pointer_type         abbrev: 5
>              byte_size            (data1) 8
>              type                 (ref4) [    55]
>  [    55]    base_type            abbrev: 6
>              byte_size            (data1) 1
>              encoding             (data1) signed_char (6)
>              name                 (strp) "char"
>  [    5c]    base_type            abbrev: 7
>              byte_size            (data1) 4
>              encoding             (data1) signed (5)
>              name                 (string) "int"
>  [    63]    variable             abbrev: 8
>              name                 (string) "t"
>              decl_file            (data1) align.c (1)
>              decl_line            (data1) 5
>              decl_column          (data1) 3
>              type                 (ref4) [    1d]
>              external             (flag_present) yes
>              location             (exprloc) 
>               [ 0] addr .bss+0

-- 

- Arnaldo



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux