[LIB]: Emit a warning when the compiler gets the byte_offset (seemingly) wrong

[acme@filo examples]$ pahole -a mpg_audio_frame_t
/* <14f> /home/acme/git/pahole/examples/mpg_audio_frame_t.c:4 */
typedef struct {
        uint16_t     frame_sync;           /*     0     2 */
        uint8_t      layer;                /*     2     1 */

        /* WARNING: DWARF offset=0, real offset=3 */

        uint32_t     mpeg25_bit:1;         /*     0     4 */
        uint32_t     lsf_bit:1;            /*     0     4 */
        uint32_t     bitrate_idx:4;        /*     0     4 */
<SNIP>

So gcc combined a uint16_t + a uint8_t + the first entries in the uint32_t
bitfield that could fit in the 8 bits after the first two fields but haven't
updated the size of the bitfield (4) and wrote 0 as the offset, warn about such
inconsistencies.

Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
This commit is contained in:
Arnaldo Carvalho de Melo 2007-03-29 11:25:02 -03:00
parent 27ac8cec6c
commit 0dcc856a7f
1 changed files with 14 additions and 2 deletions

View File

@ -2519,7 +2519,6 @@ size_t class__fprintf(const struct class *self, const struct cu *cu,
list_for_each_entry(pos, &tself->members, tag.node) {
struct tag *type;
const ssize_t cc_last_size = pos->offset - last_offset;
if (pos->offset != last_offset)
printed +=
@ -2529,7 +2528,20 @@ size_t class__fprintf(const struct class *self, const struct cu *cu,
&last_cacheline,
indent + 1, fp);
if (last_offset != -1) {
if (cc_last_size > 0 &&
const ssize_t cc_last_size = pos->offset - last_offset;
if (pos->offset < last_offset) {
if (!newline++) {
fputc('\n', fp);
++printed;
}
printed += fprintf(fp, "%.*s/* WARNING: DWARF"
" offset=%zd, real offset="
"%zd */\n",
indent + 1, tabs,
pos->offset,
last_offset + last_size);
} else if (cc_last_size > 0 &&
(size_t)cc_last_size < last_size) {
if (!newline++) {
fputc('\n', fp);