Poke-a-hole and friends

submited by
Style Pass
2025-07-30 21:00:04

Poke-a-hole (pahole) is an object-file analysis tool to find the size of the data structures, and the holes caused due to aligning the data elements to the word-size of the CPU by the compiler. Consider a simple data structure:

Compiling this on a 32-bit architecture (ILP32, or Int-Long-Pointer 32 bits) reveals that the size is actually 20 bytes. The additional bytes are inserted by the compiler to make the data elements aligned to word size of the CPU. In this case, two bytes padding is added after char a[2], and another two bytes are added after short s. Compiling the same program on a 64-bit machine (LP64, or Long-Pointer 64 bits) results in struct sample occupying 40 bytes. In this case, six bytes are added after char a[2], four bytes after int i, and six bytes after short 2. Pahole was developed to narrow down on such holes created by word-size alignment by the compiler. To analyze the object files, the source must be compiled with the debugging flag "-g". In the kernel, this is activated by CONFIG_DEBUG_INFO, or "Kernel Hacking > Compile the kernel with debug info".

i386$ pahole sizes.o struct sample { char c[2]; /* 0 2 */ /* XXX 2 bytes hole, try to pack */ long int l; /* 4 4 */ int i; /* 8 4 */ void * p; /* 12 4 */ short int s; /* 16 2 */ /* size: 20, cachelines: 1, members: 5 */ /* sum members: 16, holes: 1, sum holes: 2 */ /* padding: 2 */ /* last cacheline: 20 bytes */ };

Leave a Comment
Related Posts