3 - When expanding types using 'pahole -E' do it for union and struct typedefs and for enums too.
5 E.g: that 'state' field in 'struct module':
9 enum module_state state; /* 0 4 */
11 /* XXX 4 bytes hole, try to pack */
13 struct list_head list; /* 8 16 */
14 char name[56]; /* 24 56 */
15 /* --- cacheline 1 boundary (64 bytes) was 16 bytes ago --- */
16 struct module_kobject mkobj; /* 80 96 */
17 /* --- cacheline 2 boundary (128 bytes) was 48 bytes ago --- */
22 $ pahole -E module | head
25 MODULE_STATE_LIVE = 0,
26 MODULE_STATE_COMING = 1,
27 MODULE_STATE_GOING = 2,
28 MODULE_STATE_UNFORMED = 3,
31 /* XXX 4 bytes hole, try to pack */
35 - Print number of holes, bit holes and bit paddings in class member types.
37 Doing this recursively to show how much waste a complex data structure has
38 is something that still needs to be done, there were the low hanging fruits
39 on the path to having that feature.
41 For instance, for 'struct task_struct' in the Linux kernel we get this
44 --- task_struct.before.c 2024-02-09 11:38:39.249638750 -0300
45 +++ task_struct.after.c 2024-02-09 16:19:34.221134835 -0300
48 /* --- cacheline 2 boundary (128 bytes) --- */
49 struct sched_entity se; /* 128 256 */
51 + /* XXX last struct has 3 holes */
53 /* --- cacheline 6 boundary (384 bytes) --- */
54 struct sched_rt_entity rt; /* 384 48 */
55 struct sched_dl_entity dl; /* 432 224 */
57 + /* XXX last struct has 1 bit hole */
59 /* --- cacheline 10 boundary (640 bytes) was 16 bytes ago --- */
60 const struct sched_class * sched_class; /* 656 8 */
61 struct rb_node core_node; /* 664 24 */
63 /* --- cacheline 35 boundary (2240 bytes) was 16 bytes ago --- */
64 struct list_head tasks; /* 2256 16 */
65 struct plist_node pushable_tasks; /* 2272 40 */
67 + /* XXX last struct has 1 hole */
69 /* --- cacheline 36 boundary (2304 bytes) was 8 bytes ago --- */
70 struct rb_node pushable_dl_tasks; /* 2312 24 */
71 struct mm_struct * mm; /* 2336 8 */
73 /* XXX last struct has 4 bytes of padding */
75 struct vtime vtime; /* 2744 48 */
77 + /* XXX last struct has 1 hole */
79 /* --- cacheline 43 boundary (2752 bytes) was 40 bytes ago --- */
80 atomic_t tick_dep_mask; /* 2792 4 */
83 /* --- cacheline 145 boundary (9280 bytes) --- */
84 struct thread_struct thread __attribute__((__aligned__(64))); /* 9280 4416 */
86 + /* XXX last struct has 1 hole, 1 bit hole */
88 /* size: 13696, cachelines: 214, members: 262 */
89 /* sum members: 13518, holes: 21, sum holes: 162 */
90 /* sum bitfield members: 82 bits, bit holes: 2, sum bit holes: 46 bits */
91 /* member types with holes: 4, total: 6, bit holes: 2, total: 2 */
92 /* paddings: 6, sum paddings: 49 */
93 /* forced alignments: 2, forced holes: 2, sum forced holes: 88 */
96 - Introduce --contains_enumerator=ENUMERATOR_NAME:
100 $ pahole --contains_enumerator S_VERSION
101 enum file_time_flags {
109 The shorter form --contains_enum is also accepted.
111 - Fix pretty printing when using DWARF, where sometimes the class (-C) and a specified "type_enum",
112 may not be present on the same CU, so wait till both are found.
114 Now this example that reads the 'struct perf_event_header' and 'enum perf_event_type'
115 from the DWARF info in ~/bin/perf to pretty print records in the perf.data file works
116 just like when using type info from BTF in ~/bin/perf:
118 $ pahole -F dwarf -V ~/bin/perf \
119 --header=perf_file_header \
120 --seek_bytes '$header.data.offset' \
121 --size_bytes='$header.data.size' \
122 -C 'perf_event_header(sizeof,type,type_enum=perf_event_type,filter=type==PERF_RECORD_MMAP2)' \
123 --prettify perf.data --count 1
124 pahole: sizeof_operator for 'perf_event_header' is 'size'
125 pahole: type member for 'perf_event_header' is 'type'
126 pahole: type enum for 'perf_event_header' is 'perf_event_type'
127 pahole: filter for 'perf_event_header' is 'type==PERF_RECORD_MMAP2'
128 pahole: seek bytes evaluated from --seek_bytes=$header.data.offset is 0x3f0
129 pahole: size bytes evaluated from --size_bytes=$header.data.size is 0xd10
130 // type=perf_event_header, offset=0xc20, sizeof=8, real_sizeof=112
133 .type = PERF_RECORD_MMAP2,
139 .start = 94667542700032,
145 .ino_generation = 26870,
150 .build_id = { 33, 0, 0, 0, -85, 4, 36, 2, 0, 0, 0, 0, -10, 104, 0, 0, 0, 0, 0, 0 },
154 .filename = "/usr/bin/ls",
160 - Add support for DW_TAG_constant, first seen in Go DWARF.
162 - Fix loading DW_TAG_subroutine_type generated by the Go compiler, where it may
163 have a DW_AT_byte_size. Go DWARF. And pretty print it as if
164 it was from C, this helped in writing BPF programs to attach to Go binaries, using
169 - Fix loading of 32-bit signed enums.
173 - Add 'pahole --btf_features' to allow consumers to specify an opt-in set of
174 features they want to use in BTF encoding.
176 Supported features are a comma-separated combination of
178 encode_force Ignore invalid symbols when encoding BTF.
179 var Encode variables using BTF_KIND_VAR in BTF.
180 float Encode floating-point types in BTF.
181 decl_tag Encode declaration tags using BTF_KIND_DECL_TAG.
182 type_tag Encode type tags using BTF_KIND_TYPE_TAG.
183 enum64 Encode enum64 values with BTF_KIND_ENUM64.
184 optimized_func Encode representations of optimized functions
185 with suffixes like ".isra.0" etc
186 consistent_func Avoid encoding inconsistent static functions.
187 These occur when a parameter is optimized out
188 in some CUs and not others, or when the same
189 function name has inconsistent BTF descriptions
192 Specifying "--btf_features=all" is the equivalent to setting all of the
193 above. If pahole does not know about a feature specified in
194 --btf_features it silently ignores it.
196 The --btf_features can either be specified via a single comma-separated
198 --btf_features=enum64,float
200 ...or via multiple --btf_features values
202 --btf_features=enum64 --btf_features=float
204 These properties allow us to use the --btf_features option in the kernel
205 scripts/pahole_flags.sh script to specify the desired set of BTF
208 If a feature named in --btf_features is not present in the version of
209 pahole used, BTF encoding will not complain. This is desired because it
210 means we no longer have to tie new features to a specific pahole
213 Use --btf_features_strict to change that behaviour and bail out if one of
214 the requested features isn't present.
216 To see the supported features, use:
218 $ pahole --supported_btf_features
219 encode_force,var,float,decl_tag,type_tag,enum64,optimized_func,consistent_func
224 - Parallelize loading BTF and DWARF, speeding up a bit.
226 - Do type expansion to cover "private" types and enumerations.
228 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>