pahole: Describe expected use of 'default' in the man page
[dwarves.git] / changes-v1.13
blobb41ad7ecf3341bb9dff3ca777fb926484f5c4fb2
1 Here is a summary of changes for the 1.13 version of pahole and its friends:
3 - BTF
5   - Use of the recently introduced BTF deduplication algorithm present in the
6     Linux kernel's libbpf library, which allows for all the types in a multi
7     compile unit binary such as vmlinux to be compactly stored, without duplicates.
9     E.g.: from roughly:
11     $ readelf -SW ../build/v5.1-rc4+/vmlinux | grep .debug_info.*PROGBITS
12       [63] .debug_info PROGBITS 0000000000000000 1d80be0 c3c18b9 00 0 0 1
13     $
14     195 MiB
16     to:
18     $ time pahole --btf_encode ../build/v5.1-rc4+/vmlinux 
19     real    0m19.168s
20     user    0m17.707s         # On a Lenovo t480s (i7-8650U) SSD
21     sys     0m1.337s
22     $
24     $ readelf -SW ../build/v5.1-rc4+/vmlinux | grep .BTF.*PROGBITS
25       [78] .BTF        PROGBITS 0000000000000000 27b49f61 1e23c3 00 0 0 1
26     $ 
27     ~2 MiB
29   - Introduce a 'btfdiff' utility that prints the output from DWARF and from
30     BTF, comparing the pretty printed outputs, running it on various linux
31     kernel images, such as an allyesconfig for ppc64.
33     Running it on the above 5.1-rc4+ vmlinux:
35       $ btfdiff ../build/v5.1-rc4+/vmlinux
36       $ 
38     No differences from the types generated from the DWARF ELF sections to the
39     ones generated from the BTF ELF section.
41   - Add a BTF loader, i.e. 'pahole -F btf' allows pretty printing of structs
42     and unions in the same fashion as with DWARF info, and since BTF is way
43     more compact, using it is much faster than using DWARF.
45       $ cat ../build/v5.1-rc4+/vmlinux > /dev/null
46       $ perf stat -e cycles pahole -F btf ../build/v5.1-rc4+/vmlinux  > /dev/null
47       
48        Performance counter stats for 'pahole -F btf ../build/v5.1-rc4+/vmlinux':
49       
50              229,712,692      cycles:u                                                    
51              0.063379597 seconds time elapsed
52              0.056265000 seconds user
53              0.006911000 seconds sys
54       
55       $ perf stat -e cycles pahole -F dwarf ../build/v5.1-rc4+/vmlinux  > /dev/null
56       
57        Performance counter stats for 'pahole -F dwarf ../build/v5.1-rc4+/vmlinux':
58       
59           49,579,679,466      cycles:u                                                    
60             13.063487352 seconds time elapsed
61             12.612512000 seconds user
62              0.426226000 seconds sys
63       $
65 - Better union support:
67   - Allow unions to be specified in pahole in the same fashion as structs
69     $ pahole -C thread_union ../build/v5.1-rc4+/net/ipv4/tcp.o
70     union thread_union {
71             struct task_struct task __attribute__((__aligned__(64))); /* 0 11008 */
72             long unsigned int          stack[2048];                   /* 0 16384 */
73     };
74     $
76 - Infer __attribute__((__packed__)) when structs have no alignment holes
77   and violate basic types (integer, longs, short integer) natural alignment
78   requirements. Several heuristics are used to infer the __packed__
79   attribute, see the changeset log for descriptions.
81   $ pahole -F btf -C boot_e820_entry ../build/v5.1-rc4+/vmlinux
82   struct boot_e820_entry {
83           __u64             addr;     /*     0     8 */
84           __u64             size;     /*     8     8 */
85           __u32             type;     /*    16     4 */
87         /* size: 20, cachelines: 1, members: 3 */
88         /* last cacheline: 20 bytes */
89   } __attribute__((__packed__));
90   $ 
92   $ pahole -F btf -C lzma_header ../build/v5.1-rc4+/vmlinux
93   struct lzma_header {
94           uint8_t                    pos;                  /*     0     1 */
95           uint32_t                   dict_size;            /*     1     4 */
96           uint64_t                   dst_size;             /*     5     8 */
98           /* size: 13, cachelines: 1, members: 3 */
99           /* last cacheline: 13 bytes */
100   } __attribute__((__packed__));
102 - Support DWARF5's DW_AT_alignment, which, together with the __packed__
103   attribute inference algorithms produce output that, when compiled, should
104   produce structures with layouts that match the original source code.
106   See it in action with 'struct task_struct', which will also show some of the
107   new information at the struct summary, at the end of the struct:
109   $ pahole -C task_struct ../build/v5.1-rc4+/vmlinux | tail -19
110         /* --- cacheline 103 boundary (6592 bytes) --- */
111         struct vm_struct   * stack_vm_area;              /*  6592     8 */
112         refcount_t                 stack_refcount;       /*  6600     4 */
113   
114         /* XXX 4 bytes hole, try to pack */
115   
116         void *                     security;             /*  6608     8 */
117   
118         /* XXX 40 bytes hole, try to pack */
119   
120         /* --- cacheline 104 boundary (6656 bytes) --- */
121         struct thread_struct thread __attribute__((__aligned__(64))); /*  6656  4352 */
122   
123         /* size: 11008, cachelines: 172, members: 207 */
124         /* sum members: 10902, holes: 16, sum holes: 98 */
125         /* sum bitfield members: 10 bits, bit holes: 2, sum bit holes: 54 bits */
126         /* paddings: 3, sum paddings: 14 */
127         /* forced alignments: 6, forced holes: 1, sum forced holes: 40 */
128   } __attribute__((__aligned__(64)));
129   $
131 - Add a '--compile' option to 'pfunct' that produces compileable output for the
132   function prototypes in an object file. There are still some bugs but the vast
133   majority of the kernel single compilation unit files the ones produced from a
134   single .c file are working, see the new 'fullcircle' utility that uses this
135   feature.
137   Example of it in action:
139   $ pfunct --compile=static_key_false ../build/v5.1-rc4+/net/ipv4/tcp.o  
140   typedef _Bool bool;
141   typedef struct {
142         int                        counter;              /*     0     4 */
143   
144         /* size: 4, cachelines: 1, members: 1 */
145         /* last cacheline: 4 bytes */
146   } atomic_t;
147   
148   struct jump_entry;
149   
150   struct static_key_mod;
151   
152   
153   struct static_key {
154         atomic_t                   enabled;              /*     0     4 */
155   
156         /* XXX 4 bytes hole, try to pack */
157   
158         union {
159                 long unsigned int  type;                 /*     8     8 */
160                 struct jump_entry * entries;             /*     8     8 */
161                 struct static_key_mod * next;            /*     8     8 */
162         };                                               /*     8     8 */
163   
164         /* size: 16, cachelines: 1, members: 2 */
165         /* sum members: 12, holes: 1, sum holes: 4 */
166         /* last cacheline: 16 bytes */
167   };
168   
169   bool static_key_false(struct static_key * key)
170   {
171         return *(bool *)1;
172   }
173   
174   $
176 The generation of compilable code from the type information and its use in the
177 new tool 'fullcircle, helps validate all the parts of this codebase, finding
178 bugs that were lurking forever, go read the csets to find all sorts of curious
179 C language features that are rarely seen, like unnamed zero sized bitfields and
180 the way people have been using it over the years in a codebase like the linux
181 kernel.
183 Certainly there are several other features, changes and fixes that I forgot to
184 mention! Now lemme release this version so that we can use it more extensively
185 together with a recent patch merged for 5.2:
187   [PATCH bpf-next] kbuild: add ability to generate BTF type info for vmlinux
189 With it BTF will be always available for all the types of the kernel, which will
190 open a pandora box of cool new features that are in the works, and, for people
191 already using pahole, will greatly speed up its usage.
193 Please try to alias it to use btf, i.e.
195    alias pahole='pahole -F btf'
197 Please report any problems you may find with this new version or with the BTF
198 loader or any errors in the layout generated/pretty printed.
200 Thanks to the fine BTF guys at Facebook for the patches and help in testing,
201 fixing bugs and getting this out of the door, the stats for this release are:
203       Changesets: 157
205       113 Arnaldo Carvalho de Melo       Red Hat
206        32 Andrii Nakryiko                Facebook
207        10 Yonghong Song                  Facebook
208         1 Martin Lau                     Facebook
209         1 Domenico Andreoli