2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2006 Mandriva Conectiva S.A.
|
|
|
|
Copyright (C) 2006 Arnaldo Carvalho de Melo <acme@mandriva.com>
|
|
|
|
Copyright (C) 2007 Red Hat Inc.
|
|
|
|
Copyright (C) 2007 Arnaldo Carvalho de Melo <acme@redhat.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of version 2 of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "list.h"
|
|
|
|
#include "dwarves_reorganize.h"
|
|
|
|
#include "dwarves.h"
|
|
|
|
|
2009-03-17 18:31:18 +01:00
|
|
|
void class__subtract_offsets_from(struct class *self,
|
2007-05-07 05:30:02 +02:00
|
|
|
struct class_member *from,
|
|
|
|
const uint16_t size)
|
|
|
|
{
|
|
|
|
struct class_member *member =
|
2007-05-24 17:07:41 +02:00
|
|
|
list_prepare_entry(from, class__tags(self), tag.node);
|
2007-05-07 05:30:02 +02:00
|
|
|
|
2007-05-24 17:07:41 +02:00
|
|
|
list_for_each_entry_continue(member, class__tags(self), tag.node)
|
2007-05-24 03:38:29 +02:00
|
|
|
if (member->tag.tag == DW_TAG_member)
|
2009-03-17 15:43:17 +01:00
|
|
|
member->byte_offset -= size;
|
2007-05-07 05:30:02 +02:00
|
|
|
|
|
|
|
if (self->padding != 0) {
|
|
|
|
struct class_member *last_member =
|
2007-05-24 03:10:50 +02:00
|
|
|
type__last_member(&self->type);
|
2009-03-17 18:31:18 +01:00
|
|
|
const ssize_t new_padding = (class__size(self) -
|
|
|
|
(last_member->byte_offset +
|
|
|
|
last_member->byte_size));
|
2007-05-07 05:30:02 +02:00
|
|
|
if (new_padding > 0)
|
|
|
|
self->padding = new_padding;
|
|
|
|
else
|
|
|
|
self->padding = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-12 15:26:06 +01:00
|
|
|
void class__add_offsets_from(struct class *self, struct class_member *from,
|
|
|
|
const uint16_t size)
|
|
|
|
{
|
|
|
|
struct class_member *member =
|
|
|
|
list_prepare_entry(from, class__tags(self), tag.node);
|
|
|
|
|
|
|
|
list_for_each_entry_continue(member, class__tags(self), tag.node)
|
|
|
|
if (member->tag.tag == DW_TAG_member)
|
2009-03-17 15:43:17 +01:00
|
|
|
member->byte_offset += size;
|
2008-01-12 15:26:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: Check this more thoroughly. Right now it is used because I was
|
|
|
|
* to lazy to do class__remove_member properly, adjusting alignments and
|
|
|
|
* holes as we go removing fields. Ditto for class__add_offsets_from.
|
|
|
|
*/
|
|
|
|
void class__fixup_alignment(struct class *self, const struct cu *cu)
|
|
|
|
{
|
|
|
|
struct class_member *pos, *last_member = NULL;
|
|
|
|
size_t power2;
|
|
|
|
|
|
|
|
type__for_each_data_member(&self->type, pos) {
|
2009-03-17 15:43:17 +01:00
|
|
|
if (last_member == NULL && pos->byte_offset != 0) { /* paranoid! */
|
2009-03-17 18:31:18 +01:00
|
|
|
class__subtract_offsets_from(self, pos,
|
|
|
|
(pos->byte_offset -
|
|
|
|
pos->byte_size));
|
2009-03-17 15:43:17 +01:00
|
|
|
pos->byte_offset = 0;
|
2008-01-12 17:25:28 +01:00
|
|
|
} else if (last_member != NULL &&
|
|
|
|
last_member->hole >= cu->addr_size) {
|
|
|
|
size_t dec = (last_member->hole / cu->addr_size) *
|
|
|
|
cu->addr_size;
|
|
|
|
|
|
|
|
last_member->hole -= dec;
|
|
|
|
if (last_member->hole == 0)
|
|
|
|
--self->nr_holes;
|
2009-03-17 15:43:17 +01:00
|
|
|
pos->byte_offset -= dec;
|
2008-01-12 17:25:28 +01:00
|
|
|
self->type.size -= dec;
|
2009-03-17 18:31:18 +01:00
|
|
|
class__subtract_offsets_from(self, pos, dec);
|
2008-01-12 15:26:06 +01:00
|
|
|
} else for (power2 = cu->addr_size; power2 >= 2; power2 /= 2) {
|
2009-03-17 15:43:17 +01:00
|
|
|
const size_t remainder = pos->byte_offset % power2;
|
2008-01-12 15:26:06 +01:00
|
|
|
|
2009-03-17 18:31:18 +01:00
|
|
|
if (pos->byte_size == power2) {
|
2008-01-12 15:26:06 +01:00
|
|
|
if (remainder == 0) /* perfectly aligned */
|
|
|
|
break;
|
|
|
|
if (last_member->hole >= remainder) {
|
|
|
|
last_member->hole -= remainder;
|
|
|
|
if (last_member->hole == 0)
|
|
|
|
--self->nr_holes;
|
2009-03-17 15:43:17 +01:00
|
|
|
pos->byte_offset -= remainder;
|
2009-03-17 18:31:18 +01:00
|
|
|
class__subtract_offsets_from(self, pos, remainder);
|
2008-01-12 15:26:06 +01:00
|
|
|
} else {
|
|
|
|
const size_t inc = power2 - remainder;
|
|
|
|
|
|
|
|
if (last_member->hole == 0)
|
|
|
|
++self->nr_holes;
|
|
|
|
last_member->hole += inc;
|
2009-03-17 15:43:17 +01:00
|
|
|
pos->byte_offset += inc;
|
2008-01-12 15:26:06 +01:00
|
|
|
self->type.size += inc;
|
|
|
|
class__add_offsets_from(self, pos, inc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-14 17:50:36 +01:00
|
|
|
|
2008-01-12 15:26:06 +01:00
|
|
|
last_member = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_member != NULL) {
|
2008-01-13 19:04:59 +01:00
|
|
|
struct class_member *m =
|
|
|
|
type__find_first_biggest_size_base_type_member(&self->type, cu);
|
2009-03-17 18:31:18 +01:00
|
|
|
size_t unpadded_size = last_member->byte_offset + last_member->byte_size;
|
|
|
|
size_t m_size = m->byte_size, remainder;
|
2008-01-13 19:04:59 +01:00
|
|
|
|
|
|
|
/* google for struct zone_padding in the linux kernel for an example */
|
|
|
|
if (m_size == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
remainder = unpadded_size % m_size;
|
|
|
|
if (remainder != 0) {
|
|
|
|
self->padding = m_size - remainder;
|
|
|
|
self->type.size = unpadded_size + self->padding;
|
2008-01-12 15:26:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-07 05:30:02 +02:00
|
|
|
static struct class_member *
|
|
|
|
class__find_next_hole_of_size(struct class *class,
|
2009-03-17 18:31:18 +01:00
|
|
|
struct class_member *from, size_t size)
|
2007-05-07 05:30:02 +02:00
|
|
|
{
|
|
|
|
struct class_member *member =
|
2007-05-24 17:07:41 +02:00
|
|
|
list_prepare_entry(from, class__tags(class), tag.node);
|
2007-05-07 05:30:02 +02:00
|
|
|
struct class_member *bitfield_head = NULL;
|
|
|
|
|
2007-05-24 17:07:41 +02:00
|
|
|
list_for_each_entry_continue(member, class__tags(class), tag.node) {
|
2007-05-24 03:38:29 +02:00
|
|
|
if (member->tag.tag != DW_TAG_member)
|
|
|
|
continue;
|
2009-03-17 15:43:17 +01:00
|
|
|
if (member->bitfield_size != 0) {
|
2007-05-07 05:30:02 +02:00
|
|
|
if (bitfield_head == NULL)
|
|
|
|
bitfield_head = member;
|
|
|
|
} else
|
|
|
|
bitfield_head = NULL;
|
|
|
|
if (member->hole != 0) {
|
2009-03-17 18:31:18 +01:00
|
|
|
if (member->byte_size != 0 && member->byte_size <= size)
|
2007-05-07 05:30:02 +02:00
|
|
|
return bitfield_head ? : member;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct class_member *
|
|
|
|
class__find_last_member_of_size(struct class *class,
|
2009-03-17 18:31:18 +01:00
|
|
|
struct class_member *to, size_t size)
|
2007-05-07 05:30:02 +02:00
|
|
|
{
|
|
|
|
struct class_member *member;
|
|
|
|
|
2007-05-24 17:07:41 +02:00
|
|
|
list_for_each_entry_reverse(member, class__tags(class), tag.node) {
|
2007-05-24 03:38:29 +02:00
|
|
|
if (member->tag.tag != DW_TAG_member)
|
|
|
|
continue;
|
|
|
|
|
2007-05-07 05:30:02 +02:00
|
|
|
if (member == to)
|
|
|
|
break;
|
2007-10-26 17:28:18 +02:00
|
|
|
/*
|
|
|
|
* Check if this is the first member of a bitfield. It either
|
|
|
|
* has another member before it that is not part of the current
|
|
|
|
* bitfield or it is the first member of the struct.
|
|
|
|
*/
|
2009-03-17 15:43:17 +01:00
|
|
|
if (member->bitfield_size != 0 && member->byte_offset != 0) {
|
2007-05-07 05:30:02 +02:00
|
|
|
struct class_member *prev =
|
|
|
|
list_entry(member->tag.node.prev,
|
|
|
|
struct class_member,
|
|
|
|
tag.node);
|
2009-03-17 15:43:17 +01:00
|
|
|
if (prev->bitfield_size != 0)
|
2007-05-07 05:30:02 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-03-17 18:31:18 +01:00
|
|
|
if (member->byte_size != 0 && member->byte_size <= size)
|
2007-05-07 05:30:02 +02:00
|
|
|
return member;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct class_member *
|
2007-05-24 23:45:34 +02:00
|
|
|
class__find_next_bit_hole_of_size(struct class *class,
|
2007-05-07 05:30:02 +02:00
|
|
|
struct class_member *from,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
struct class_member *member =
|
2007-05-24 17:07:41 +02:00
|
|
|
list_prepare_entry(from, class__tags(class), tag.node);
|
2007-05-07 05:30:02 +02:00
|
|
|
|
2007-05-24 17:07:41 +02:00
|
|
|
list_for_each_entry_continue(member, class__tags(class), tag.node) {
|
2007-05-24 03:38:29 +02:00
|
|
|
if (member->tag.tag != DW_TAG_member)
|
|
|
|
continue;
|
2007-05-07 05:30:02 +02:00
|
|
|
if (member->bit_hole != 0 &&
|
2009-03-17 15:43:17 +01:00
|
|
|
member->bitfield_size <= size)
|
2007-05-07 05:30:02 +02:00
|
|
|
return member;
|
2007-05-24 03:38:29 +02:00
|
|
|
}
|
2007-05-07 05:30:02 +02:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* FIXME: Handle the case where the bit padding is on the same bitfield
|
|
|
|
* that we're looking, i.e. we can't combine a bitfield with itself,
|
|
|
|
* perhaps we should tag bitfields with a sequential, clearly marking
|
|
|
|
* each of the bitfields in advance, so that all the algoriths that
|
|
|
|
* have to deal with bitfields, moving them around, demoting, etc, can
|
|
|
|
* be simplified.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Now look if the last member is a one member bitfield,
|
|
|
|
* i.e. if we have bit_padding
|
|
|
|
*/
|
|
|
|
if (class->bit_padding != 0)
|
2007-05-24 03:10:50 +02:00
|
|
|
return type__last_member(&class->type);
|
2007-05-07 05:30:02 +02:00
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void class__move_member(struct class *class, struct class_member *dest,
|
|
|
|
struct class_member *from, const struct cu *cu,
|
|
|
|
int from_padding, const int verbose, FILE *fp)
|
|
|
|
{
|
2009-03-17 18:31:18 +01:00
|
|
|
const size_t from_size = from->byte_size;
|
|
|
|
const size_t dest_size = dest->byte_size;
|
2007-11-11 16:45:00 +01:00
|
|
|
const bool from_was_last = from->tag.node.next == class__tags(class);
|
2007-05-07 05:30:02 +02:00
|
|
|
struct class_member *tail_from = from;
|
|
|
|
struct class_member *from_prev = list_entry(from->tag.node.prev,
|
|
|
|
struct class_member,
|
|
|
|
tag.node);
|
|
|
|
uint16_t orig_tail_from_hole = tail_from->hole;
|
2009-03-17 15:43:17 +01:00
|
|
|
const uint16_t orig_from_offset = from->byte_offset;
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* Align 'from' after 'dest':
|
|
|
|
*/
|
|
|
|
const uint16_t offset = dest->hole % (from_size > cu->addr_size ?
|
|
|
|
cu->addr_size : from_size);
|
|
|
|
/*
|
2009-03-17 15:43:17 +01:00
|
|
|
* Set new 'from' offset, after 'dest->byte_offset', aligned
|
2007-05-07 05:30:02 +02:00
|
|
|
*/
|
2009-03-17 15:43:17 +01:00
|
|
|
const uint16_t new_from_offset = dest->byte_offset + dest_size + offset;
|
2007-05-07 05:30:02 +02:00
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
fputs("/* Moving", fp);
|
|
|
|
|
2009-03-17 15:43:17 +01:00
|
|
|
if (from->bitfield_size != 0) {
|
2007-05-07 05:30:02 +02:00
|
|
|
struct class_member *pos =
|
2007-05-24 17:07:41 +02:00
|
|
|
list_prepare_entry(from, class__tags(class),
|
2007-05-07 05:30:02 +02:00
|
|
|
tag.node);
|
|
|
|
struct class_member *tmp;
|
|
|
|
uint8_t orig_tail_from_bit_hole;
|
|
|
|
LIST_HEAD(from_list);
|
|
|
|
|
|
|
|
if (verbose)
|
2008-10-02 19:34:42 +02:00
|
|
|
fprintf(fp, " bitfield('%s' ... ", class_member__name(from));
|
2007-05-24 17:07:41 +02:00
|
|
|
list_for_each_entry_safe_from(pos, tmp, class__tags(class),
|
2007-05-07 05:30:02 +02:00
|
|
|
tag.node) {
|
2007-05-24 03:38:29 +02:00
|
|
|
if (pos->tag.tag != DW_TAG_member)
|
|
|
|
continue;
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* Have we reached the end of the bitfield?
|
|
|
|
*/
|
2009-03-17 15:43:17 +01:00
|
|
|
if (pos->byte_offset != orig_from_offset)
|
2007-05-07 05:30:02 +02:00
|
|
|
break;
|
|
|
|
tail_from = pos;
|
|
|
|
orig_tail_from_hole = tail_from->hole;
|
|
|
|
orig_tail_from_bit_hole = tail_from->bit_hole;
|
2009-03-17 15:43:17 +01:00
|
|
|
pos->byte_offset = new_from_offset;
|
2007-05-07 05:30:02 +02:00
|
|
|
pos->hole = 0;
|
|
|
|
pos->bit_hole = 0;
|
|
|
|
list_move_tail(&pos->tag.node, &from_list);
|
|
|
|
}
|
|
|
|
tail_from->bit_hole = orig_tail_from_bit_hole;
|
|
|
|
list_splice(&from_list, &dest->tag.node);
|
|
|
|
if (verbose)
|
2008-10-02 19:34:42 +02:00
|
|
|
fprintf(fp, "'%s')", class_member__name(tail_from));
|
2007-05-07 05:30:02 +02:00
|
|
|
} else {
|
|
|
|
if (verbose)
|
2008-10-02 19:34:42 +02:00
|
|
|
fprintf(fp, " '%s'", class_member__name(from));
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* Remove 'from' from the list
|
|
|
|
*/
|
|
|
|
list_del(&from->tag.node);
|
|
|
|
/*
|
|
|
|
* Add 'from' after 'dest':
|
|
|
|
*/
|
|
|
|
__list_add(&from->tag.node, &dest->tag.node,
|
|
|
|
dest->tag.node.next);
|
2009-03-17 15:43:17 +01:00
|
|
|
from->byte_offset = new_from_offset;
|
2007-05-07 05:30:02 +02:00
|
|
|
}
|
2009-03-14 17:50:36 +01:00
|
|
|
|
2007-05-07 05:30:02 +02:00
|
|
|
if (verbose)
|
|
|
|
fprintf(fp, " from after '%s' to after '%s' */\n",
|
2008-10-02 19:34:42 +02:00
|
|
|
class_member__name(from_prev),
|
|
|
|
class_member__name(dest));
|
2007-05-07 05:30:02 +02:00
|
|
|
|
|
|
|
if (from_padding) {
|
|
|
|
/*
|
|
|
|
* Check if we're eliminating the need for padding:
|
|
|
|
*/
|
|
|
|
if (orig_from_offset % cu->addr_size == 0) {
|
|
|
|
/*
|
|
|
|
* Good, no need for padding anymore:
|
|
|
|
*/
|
|
|
|
class->type.size -= from_size + class->padding;
|
|
|
|
class->padding = 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* No, so just add from_size to the padding:
|
|
|
|
*/
|
|
|
|
class->padding += from_size;
|
|
|
|
if (verbose)
|
|
|
|
fprintf(fp, "/* adding %zd bytes from %s to "
|
|
|
|
"the padding */\n",
|
2008-10-02 19:34:42 +02:00
|
|
|
from_size, class_member__name(from));
|
2007-05-07 05:30:02 +02:00
|
|
|
}
|
2007-11-11 16:45:00 +01:00
|
|
|
} else if (from_was_last) {
|
|
|
|
class->type.size -= from_size + class->padding;
|
|
|
|
class->padding = 0;
|
2007-05-07 05:30:02 +02:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* See if we are adding a new hole that is bigger than
|
|
|
|
* sizeof(long), this may have problems with explicit alignment
|
|
|
|
* made by the programmer, perhaps we need A switch that allows
|
|
|
|
* us to avoid realignment, just using existing holes but
|
|
|
|
* keeping the existing alignment, anyway the programmer has to
|
|
|
|
* check the resulting rerganization before using it, and for
|
|
|
|
* automatic stuff such as the one that will be used for struct
|
|
|
|
* "views" in tools such as ctracer we are more interested in
|
|
|
|
* packing the subset as tightly as possible.
|
|
|
|
*/
|
|
|
|
if (orig_tail_from_hole + from_size >= cu->addr_size) {
|
|
|
|
class->type.size -= cu->addr_size;
|
2009-03-17 18:31:18 +01:00
|
|
|
class__subtract_offsets_from(class, from_prev,
|
2007-05-07 05:30:02 +02:00
|
|
|
cu->addr_size);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Add the hole after 'from' + its size to the member
|
|
|
|
* before it:
|
|
|
|
*/
|
|
|
|
from_prev->hole += orig_tail_from_hole + from_size;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check if we have eliminated a hole
|
|
|
|
*/
|
|
|
|
if (dest->hole == from_size)
|
|
|
|
class->nr_holes--;
|
|
|
|
}
|
|
|
|
|
|
|
|
tail_from->hole = dest->hole - (from_size + offset);
|
|
|
|
dest->hole = offset;
|
|
|
|
|
|
|
|
if (verbose > 1) {
|
2009-03-17 18:31:18 +01:00
|
|
|
class__find_holes(class);
|
2007-05-07 05:30:02 +02:00
|
|
|
class__fprintf(class, cu, NULL, fp);
|
|
|
|
fputc('\n', fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void class__move_bit_member(struct class *class, const struct cu *cu,
|
|
|
|
struct class_member *dest,
|
|
|
|
struct class_member *from,
|
|
|
|
const int verbose, FILE *fp)
|
|
|
|
{
|
|
|
|
struct class_member *from_prev = list_entry(from->tag.node.prev,
|
|
|
|
struct class_member,
|
|
|
|
tag.node);
|
|
|
|
const uint8_t is_last_member = (from->tag.node.next ==
|
2007-05-24 17:07:41 +02:00
|
|
|
class__tags(class));
|
2007-05-07 05:30:02 +02:00
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
fprintf(fp, "/* Moving '%s:%u' from after '%s' to "
|
|
|
|
"after '%s:%u' */\n",
|
2009-03-17 15:43:17 +01:00
|
|
|
class_member__name(from), from->bitfield_size,
|
2008-10-02 19:34:42 +02:00
|
|
|
class_member__name(from_prev),
|
2009-03-17 15:43:17 +01:00
|
|
|
class_member__name(dest), dest->bitfield_size);
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* Remove 'from' from the list
|
|
|
|
*/
|
|
|
|
list_del(&from->tag.node);
|
|
|
|
/*
|
|
|
|
* Add from after dest:
|
|
|
|
*/
|
|
|
|
__list_add(&from->tag.node,
|
|
|
|
&dest->tag.node,
|
|
|
|
dest->tag.node.next);
|
|
|
|
|
|
|
|
/* Check if this was the last entry in the bitfield */
|
2009-03-17 15:43:17 +01:00
|
|
|
if (from_prev->bitfield_size == 0) {
|
2009-03-17 18:31:18 +01:00
|
|
|
size_t from_size = from->byte_size;
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* Are we shrinking the struct?
|
|
|
|
*/
|
|
|
|
if (from_size + from->hole >= cu->addr_size) {
|
|
|
|
class->type.size -= from_size + from->hole;
|
2009-03-17 18:31:18 +01:00
|
|
|
class__subtract_offsets_from(class, from_prev,
|
2007-05-07 05:30:02 +02:00
|
|
|
from_size + from->hole);
|
|
|
|
} else if (is_last_member)
|
|
|
|
class->padding += from_size;
|
|
|
|
else
|
|
|
|
from_prev->hole += from_size + from->hole;
|
|
|
|
if (is_last_member) {
|
|
|
|
/*
|
|
|
|
* Now we don't have bit_padding anymore
|
|
|
|
*/
|
|
|
|
class->bit_padding = 0;
|
|
|
|
} else
|
|
|
|
class->nr_bit_holes--;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Add add the holes after from + its size to the member
|
|
|
|
* before it:
|
|
|
|
*/
|
2009-03-17 15:43:17 +01:00
|
|
|
from_prev->bit_hole += from->bit_hole + from->bitfield_size;
|
2007-05-07 05:30:02 +02:00
|
|
|
from_prev->hole = from->hole;
|
|
|
|
}
|
2009-03-17 15:43:17 +01:00
|
|
|
from->bit_hole = dest->bit_hole - from->bitfield_size;
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* Tricky, what are the rules for bitfield layouts on this arch?
|
|
|
|
* Assume its IA32
|
|
|
|
*/
|
2009-03-17 15:43:17 +01:00
|
|
|
from->bitfield_offset = dest->bitfield_offset + dest->bitfield_size;
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* Now both have the some offset:
|
|
|
|
*/
|
2009-03-17 15:43:17 +01:00
|
|
|
from->byte_offset = dest->byte_offset;
|
2007-05-07 05:30:02 +02:00
|
|
|
dest->bit_hole = 0;
|
|
|
|
from->hole = dest->hole;
|
|
|
|
dest->hole = 0;
|
|
|
|
if (verbose > 1) {
|
2009-03-17 18:31:18 +01:00
|
|
|
class__find_holes(class);
|
2007-05-07 05:30:02 +02:00
|
|
|
class__fprintf(class, cu, NULL, fp);
|
|
|
|
fputc('\n', fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void class__demote_bitfield_members(struct class *class,
|
|
|
|
struct class_member *from,
|
|
|
|
struct class_member *to,
|
|
|
|
const struct base_type *old_type,
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
const struct base_type *new_type,
|
|
|
|
uint16_t new_type_id)
|
2007-05-07 05:30:02 +02:00
|
|
|
{
|
2008-03-04 22:38:21 +01:00
|
|
|
const uint8_t bit_diff = old_type->bit_size - new_type->bit_size;
|
2007-05-07 05:30:02 +02:00
|
|
|
struct class_member *member =
|
2007-05-24 17:07:41 +02:00
|
|
|
list_prepare_entry(from, class__tags(class), tag.node);
|
2007-05-07 05:30:02 +02:00
|
|
|
|
2007-05-24 17:07:41 +02:00
|
|
|
list_for_each_entry_from(member, class__tags(class), tag.node) {
|
2007-05-24 03:38:29 +02:00
|
|
|
if (member->tag.tag != DW_TAG_member)
|
|
|
|
continue;
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* Assume IA32 bitfield layout
|
|
|
|
*/
|
2009-03-17 15:43:17 +01:00
|
|
|
member->bitfield_offset -= bit_diff;
|
2009-04-02 20:57:21 +02:00
|
|
|
member->byte_size = new_type->bit_size / 8;
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
member->tag.type = new_type_id;
|
2007-05-07 05:30:02 +02:00
|
|
|
if (member == to)
|
|
|
|
break;
|
|
|
|
member->bit_hole = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct tag *cu__find_base_type_of_size(const struct cu *cu,
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
const size_t size, uint16_t *id)
|
2007-05-07 05:30:02 +02:00
|
|
|
{
|
2009-03-02 20:07:43 +01:00
|
|
|
const char *type_name, *type_name_alt = NULL;
|
2007-05-07 05:30:02 +02:00
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case sizeof(unsigned char):
|
|
|
|
type_name = "unsigned char"; break;
|
|
|
|
case sizeof(unsigned short int):
|
2009-03-02 20:07:43 +01:00
|
|
|
type_name = "short unsigned int";
|
2009-03-07 20:35:17 +01:00
|
|
|
type_name_alt = "unsigned short"; break;
|
2007-05-07 05:30:02 +02:00
|
|
|
case sizeof(unsigned int):
|
2009-03-02 20:07:43 +01:00
|
|
|
type_name = "unsigned int";
|
|
|
|
type_name_alt = "unsigned"; break;
|
2007-05-07 05:30:02 +02:00
|
|
|
case sizeof(unsigned long long):
|
2009-03-02 20:07:43 +01:00
|
|
|
if (cu->addr_size == 8) {
|
2007-05-07 05:30:02 +02:00
|
|
|
type_name = "long unsigned int";
|
2009-03-02 20:07:43 +01:00
|
|
|
type_name_alt = "unsigned long";
|
|
|
|
} else {
|
2007-05-07 05:30:02 +02:00
|
|
|
type_name = "long long unsigned int";
|
2009-03-02 20:07:43 +01:00
|
|
|
type_name_alt = "unsigned long long";
|
|
|
|
}
|
2007-05-07 05:30:02 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
struct tag *ret = cu__find_base_type_by_name(cu, type_name, id);
|
|
|
|
return ret ?: cu__find_base_type_by_name(cu, type_name_alt, id);
|
2007-05-07 05:30:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int class__demote_bitfields(struct class *class, const struct cu *cu,
|
|
|
|
const int verbose, FILE *fp)
|
|
|
|
{
|
|
|
|
struct class_member *member;
|
|
|
|
struct class_member *bitfield_head = NULL;
|
|
|
|
const struct tag *old_type_tag, *new_type_tag;
|
|
|
|
size_t current_bitfield_size = 0, size, bytes_needed, new_size;
|
|
|
|
int some_was_demoted = 0;
|
|
|
|
|
2007-05-29 19:06:33 +02:00
|
|
|
type__for_each_data_member(&class->type, member) {
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* Check if we are moving away from a bitfield
|
|
|
|
*/
|
2009-03-17 15:43:17 +01:00
|
|
|
if (member->bitfield_size == 0) {
|
2007-05-07 05:30:02 +02:00
|
|
|
current_bitfield_size = 0;
|
|
|
|
bitfield_head = NULL;
|
|
|
|
} else {
|
|
|
|
if (bitfield_head == NULL) {
|
|
|
|
bitfield_head = member;
|
2009-03-17 15:43:17 +01:00
|
|
|
current_bitfield_size = member->bitfield_size;
|
|
|
|
} else if (bitfield_head->byte_offset != member->byte_offset) {
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* We moved from one bitfield to another, for
|
|
|
|
* now don't handle this case, just move on to
|
|
|
|
* the next bitfield, we may well move it to
|
|
|
|
* another place and then the first bitfield will
|
|
|
|
* be isolated and will be handled in the next
|
|
|
|
* pass.
|
|
|
|
*/
|
|
|
|
bitfield_head = member;
|
2009-03-17 15:43:17 +01:00
|
|
|
current_bitfield_size = member->bitfield_size;
|
2007-05-07 05:30:02 +02:00
|
|
|
} else
|
2009-03-17 15:43:17 +01:00
|
|
|
current_bitfield_size += member->bitfield_size;
|
2007-05-07 05:30:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Have we got to the end of a bitfield with holes?
|
|
|
|
*/
|
|
|
|
if (member->bit_hole == 0)
|
|
|
|
continue;
|
|
|
|
|
2009-03-17 18:31:18 +01:00
|
|
|
size = member->byte_size;
|
2007-05-07 05:30:02 +02:00
|
|
|
bytes_needed = (current_bitfield_size + 7) / 8;
|
|
|
|
if (bytes_needed == size)
|
|
|
|
continue;
|
|
|
|
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
uint16_t new_type_id;
|
2009-03-18 16:17:07 +01:00
|
|
|
old_type_tag = cu__type(cu, member->tag.type);
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
new_type_tag = cu__find_base_type_of_size(cu, bytes_needed,
|
|
|
|
&new_type_id);
|
2007-11-20 20:55:18 +01:00
|
|
|
|
|
|
|
if (new_type_tag == NULL) {
|
|
|
|
fprintf(fp, "/* BRAIN FART ALERT! couldn't find a "
|
|
|
|
"%zd bytes base type */\n\n", bytes_needed);
|
|
|
|
continue;
|
|
|
|
}
|
2009-04-02 21:12:36 +02:00
|
|
|
if (verbose) {
|
|
|
|
char old_bf[64], new_bf[64];
|
2007-05-07 05:30:02 +02:00
|
|
|
fprintf(fp, "/* Demoting bitfield ('%s' ... '%s') "
|
|
|
|
"from '%s' to '%s' */\n",
|
2008-10-02 19:34:42 +02:00
|
|
|
class_member__name(bitfield_head),
|
|
|
|
class_member__name(member),
|
2009-04-02 21:12:36 +02:00
|
|
|
base_type__name(tag__base_type(old_type_tag),
|
|
|
|
old_bf, sizeof(old_bf)),
|
|
|
|
base_type__name(tag__base_type(new_type_tag),
|
|
|
|
new_bf, sizeof(new_bf)));
|
|
|
|
}
|
2007-05-07 05:30:02 +02:00
|
|
|
|
|
|
|
class__demote_bitfield_members(class,
|
2009-03-14 17:50:36 +01:00
|
|
|
bitfield_head, member,
|
2007-05-07 05:30:02 +02:00
|
|
|
tag__base_type(old_type_tag),
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
tag__base_type(new_type_tag),
|
|
|
|
new_type_id);
|
2009-03-17 18:31:18 +01:00
|
|
|
new_size = member->byte_size;
|
2007-05-07 05:30:02 +02:00
|
|
|
member->hole = size - new_size;
|
|
|
|
if (member->hole != 0)
|
|
|
|
++class->nr_holes;
|
|
|
|
member->bit_hole = new_size * 8 - current_bitfield_size;
|
|
|
|
some_was_demoted = 1;
|
|
|
|
/*
|
|
|
|
* Have we packed it so that there are no hole now?
|
|
|
|
*/
|
|
|
|
if (member->bit_hole == 0)
|
|
|
|
--class->nr_bit_holes;
|
|
|
|
if (verbose > 1) {
|
2009-03-17 18:31:18 +01:00
|
|
|
class__find_holes(class);
|
2007-05-07 05:30:02 +02:00
|
|
|
class__fprintf(class, cu, NULL, fp);
|
|
|
|
fputc('\n', fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Now look if we have bit padding, i.e. if the the last member
|
|
|
|
* is a bitfield and its the sole member in this bitfield, i.e.
|
|
|
|
* if it wasn't already demoted as part of a bitfield of more than
|
|
|
|
* one member:
|
|
|
|
*/
|
2007-05-24 03:10:50 +02:00
|
|
|
member = type__last_member(&class->type);
|
2007-05-07 05:30:02 +02:00
|
|
|
if (class->bit_padding != 0 && bitfield_head == member) {
|
2009-03-17 18:31:18 +01:00
|
|
|
size = member->byte_size;
|
2009-03-17 15:43:17 +01:00
|
|
|
bytes_needed = (member->bitfield_size + 7) / 8;
|
2007-05-07 05:30:02 +02:00
|
|
|
if (bytes_needed < size) {
|
2009-03-18 16:17:07 +01:00
|
|
|
old_type_tag = cu__type(cu, member->tag.type);
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
uint16_t new_type_id;
|
2007-05-07 05:30:02 +02:00
|
|
|
new_type_tag =
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
cu__find_base_type_of_size(cu, bytes_needed,
|
|
|
|
&new_type_id);
|
2007-05-07 05:30:02 +02:00
|
|
|
|
2008-04-20 23:56:36 +02:00
|
|
|
tag__assert_search_result(old_type_tag);
|
|
|
|
tag__assert_search_result(new_type_tag);
|
|
|
|
|
2009-04-02 21:12:36 +02:00
|
|
|
if (verbose) {
|
|
|
|
char old_bf[64], new_bf[64];
|
2007-05-07 05:30:02 +02:00
|
|
|
fprintf(fp, "/* Demoting bitfield ('%s') "
|
|
|
|
"from '%s' to '%s' */\n",
|
2008-10-02 19:34:42 +02:00
|
|
|
class_member__name(member),
|
2009-04-02 21:12:36 +02:00
|
|
|
base_type__name(tag__base_type(old_type_tag),
|
|
|
|
old_bf, sizeof(old_bf)),
|
|
|
|
base_type__name(tag__base_type(new_type_tag),
|
|
|
|
new_bf, sizeof(new_bf)));
|
|
|
|
}
|
2007-05-07 05:30:02 +02:00
|
|
|
class__demote_bitfield_members(class,
|
2009-03-14 17:50:36 +01:00
|
|
|
member, member,
|
2007-05-07 05:30:02 +02:00
|
|
|
tag__base_type(old_type_tag),
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
tag__base_type(new_type_tag),
|
|
|
|
new_type_id);
|
2009-03-17 18:31:18 +01:00
|
|
|
new_size = member->byte_size;
|
2007-05-07 05:30:02 +02:00
|
|
|
member->hole = 0;
|
|
|
|
/*
|
|
|
|
* Do we need byte padding?
|
|
|
|
*/
|
2009-03-17 15:43:17 +01:00
|
|
|
if (member->byte_offset + new_size < class__size(class)) {
|
2007-05-07 05:30:02 +02:00
|
|
|
class->padding = (class__size(class) -
|
2009-03-17 15:43:17 +01:00
|
|
|
(member->byte_offset + new_size));
|
2007-05-07 05:30:02 +02:00
|
|
|
class->bit_padding = 0;
|
|
|
|
member->bit_hole = (new_size * 8 -
|
2009-03-17 15:43:17 +01:00
|
|
|
member->bitfield_size);
|
2007-05-07 05:30:02 +02:00
|
|
|
} else {
|
|
|
|
class->padding = 0;
|
|
|
|
class->bit_padding = (new_size * 8 -
|
2009-03-17 15:43:17 +01:00
|
|
|
member->bitfield_size);
|
2007-05-07 05:30:02 +02:00
|
|
|
member->bit_hole = 0;
|
|
|
|
}
|
|
|
|
some_was_demoted = 1;
|
|
|
|
if (verbose > 1) {
|
2009-03-17 18:31:18 +01:00
|
|
|
class__find_holes(class);
|
2007-05-07 05:30:02 +02:00
|
|
|
class__fprintf(class, cu, NULL, fp);
|
|
|
|
fputc('\n', fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return some_was_demoted;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void class__reorganize_bitfields(struct class *class,
|
|
|
|
const struct cu *cu,
|
|
|
|
const int verbose, FILE *fp)
|
|
|
|
{
|
|
|
|
struct class_member *member, *brother;
|
|
|
|
restart:
|
2007-05-29 19:06:33 +02:00
|
|
|
type__for_each_data_member(&class->type, member) {
|
2007-05-07 05:30:02 +02:00
|
|
|
/* See if we have a hole after this member */
|
|
|
|
if (member->bit_hole != 0) {
|
|
|
|
/*
|
|
|
|
* OK, try to find a member that has a bit hole after
|
|
|
|
* it and that has a size that fits the current hole:
|
|
|
|
*/
|
|
|
|
brother =
|
|
|
|
class__find_next_bit_hole_of_size(class, member,
|
|
|
|
member->bit_hole);
|
|
|
|
if (brother != NULL) {
|
|
|
|
class__move_bit_member(class, cu,
|
|
|
|
member, brother,
|
|
|
|
verbose, fp);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-24 23:45:34 +02:00
|
|
|
static void class__fixup_bitfield_types(struct class *self,
|
2007-05-07 05:30:02 +02:00
|
|
|
struct class_member *from,
|
|
|
|
struct class_member *to_before,
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
uint16_t type)
|
2007-05-07 05:30:02 +02:00
|
|
|
{
|
|
|
|
struct class_member *member =
|
2007-05-24 17:07:41 +02:00
|
|
|
list_prepare_entry(from, class__tags(self), tag.node);
|
2007-05-07 05:30:02 +02:00
|
|
|
|
2007-05-24 17:07:41 +02:00
|
|
|
list_for_each_entry_from(member, class__tags(self), tag.node) {
|
2007-05-24 03:38:29 +02:00
|
|
|
if (member->tag.tag != DW_TAG_member)
|
|
|
|
continue;
|
2007-05-07 05:30:02 +02:00
|
|
|
if (member == to_before)
|
|
|
|
break;
|
|
|
|
member->tag.type = type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Think about this pahole output a bit:
|
|
|
|
*
|
|
|
|
* [filo examples]$ pahole swiss_cheese cheese
|
|
|
|
* / * <11b> /home/acme/git/pahole/examples/swiss_cheese.c:3 * /
|
|
|
|
* struct cheese {
|
|
|
|
* <SNIP>
|
|
|
|
* int bitfield1:1; / * 64 4 * /
|
|
|
|
* int bitfield2:1; / * 64 4 * /
|
|
|
|
*
|
|
|
|
* / * XXX 14 bits hole, try to pack * /
|
|
|
|
* / * Bitfield WARNING: DWARF size=4, real size=2 * /
|
|
|
|
*
|
|
|
|
* short int d; / * 66 2 * /
|
|
|
|
* <SNIP>
|
2009-03-14 17:50:36 +01:00
|
|
|
*
|
2007-05-07 05:30:02 +02:00
|
|
|
* The compiler (gcc 4.1.1 20070105 (Red Hat 4.1.1-51) in the above example),
|
|
|
|
* Decided to combine what was declared as an int (4 bytes) bitfield but doesn't
|
|
|
|
* uses even one byte with the next field, that is a short int (2 bytes),
|
|
|
|
* without demoting the type of the bitfield to short int (2 bytes), so in terms
|
|
|
|
* of alignment the real size is 2, not 4, to make things easier for the rest of
|
|
|
|
* the reorganizing routines we just do the demotion ourselves, fixing up the
|
|
|
|
* sizes.
|
|
|
|
*/
|
|
|
|
static void class__fixup_member_types(struct class *self, const struct cu *cu,
|
|
|
|
const uint8_t verbose, FILE *fp)
|
|
|
|
{
|
|
|
|
struct class_member *pos, *bitfield_head = NULL;
|
|
|
|
uint8_t fixup_was_done = 0;
|
|
|
|
|
2007-05-29 19:06:33 +02:00
|
|
|
type__for_each_data_member(&self->type, pos) {
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* Is this bitfield member?
|
|
|
|
*/
|
2009-03-17 15:43:17 +01:00
|
|
|
if (pos->bitfield_size != 0) {
|
2007-05-07 05:30:02 +02:00
|
|
|
/*
|
|
|
|
* The first entry in a bitfield?
|
|
|
|
*/
|
|
|
|
if (bitfield_head == NULL)
|
|
|
|
bitfield_head = pos;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* OK, not a bitfield member, but have we just passed
|
|
|
|
* by a bitfield?
|
|
|
|
*/
|
|
|
|
if (bitfield_head != NULL) {
|
2009-03-17 15:43:17 +01:00
|
|
|
const uint16_t real_size = (pos->byte_offset -
|
|
|
|
bitfield_head->byte_offset);
|
2009-03-17 18:31:18 +01:00
|
|
|
const size_t size = bitfield_head->byte_size;
|
2007-05-07 05:30:02 +02:00
|
|
|
if (real_size != size) {
|
2009-03-14 17:50:36 +01:00
|
|
|
uint16_t new_type_id;
|
2007-05-07 05:30:02 +02:00
|
|
|
struct tag *new_type_tag =
|
|
|
|
cu__find_base_type_of_size(cu,
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
real_size,
|
|
|
|
&new_type_id);
|
2007-05-07 05:30:02 +02:00
|
|
|
if (new_type_tag == NULL) {
|
2009-03-07 20:35:17 +01:00
|
|
|
fprintf(stderr, "%s: couldn't find"
|
2007-05-07 05:30:02 +02:00
|
|
|
" a base_type of %d bytes!\n",
|
2009-03-07 20:35:17 +01:00
|
|
|
__func__, real_size);
|
2007-05-07 05:30:02 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
class__fixup_bitfield_types(self,
|
|
|
|
bitfield_head, pos,
|
dwarves: Remove some more DWARF details from the core
Had to be a big sweeping change, but the regression tests shows just
improvements :-)
Now we stop using an id in struct tag, only storing the type, that now
uses 16 bits only, as CTF does.
Each format loader has to go on adding the types to the core, that
figures out if it is a tag that can be on the tag->type field
(tag__is_tag_type).
Formats that already have the types separated and in sequence, such as
CTF, just ask the core to insert in the types_table directly with its
original ID.
For DWARF, we ask the core to put it on the table, in sequence, and return the
index, that is then stashed with the DWARF specific info (original id, type,
decl_line, etc) and hashed by the original id. Later we recode everything,
looking up via the original type, getting the small_id to put on the tag->type.
The underlying debugging info not needed by the core is stashed in tag->priv,
and the DWARF loader now just allocates sizeof(struct dwarf_tag) at the end of
the core tag and points it there, and makes that info available thru
cu->orig_info. In the future we can ask, when loading a cu, that this info be
trown away, so that we reduce the memory footprint for big multi-cu files such
as the Linux kernel.
There is also a routine to ask for inserting a NULL, as we still have
bugs in the CTF decoding and thus some entries are being lost, to avoid
using an undefined pointer when traversing the types_table the ctf
loader puts a NULL there via cu__table_nullify_type_entry() and then
cu__for_each_type skips those.
There is some more cleanups for leftovers that I avoided cleaning to
reduce this changeset.
And also while doing this I saw that enums can appear without any
enumerators and that an array with DW_TAG_GNU_vector is actually a
different tag, encoded this way till we get to DWARF4 ;-)
So now we don't have to lookup on a hash table looking for DWARF
offsets, we can do the more sensible thing of just indexing the
types_tags array.
Now to do some cleanups and try to get the per cu encoder done. Then
order all the cus per number of type entries, pick the one with more,
then go on merging/recoding the types of the others and putting the
parent linkage in place.
Just to show the extent of the changes:
$ codiff /tmp/libdwarves.so.1.0.0 build/libdwarves.so.1.0.0
/home/acme/git/pahole/dwarves.c:
struct cu | -4048
struct tag | -32
struct ptr_to_member_type | -32
struct namespace | -32
struct type | -32
struct class | -32
struct base_type | -32
struct array_type | -32
struct class_member | -32
struct lexblock | -32
struct ftype | -32
struct function | -64
struct parameter | -32
struct variable | -32
struct inline_expansion | -32
struct label | -32
struct enumerator | -32
17 structs changed
tag__follow_typedef | +3
tag__fprintf_decl_info | +25
array_type__fprintf | +6
type__name | -126
type__find_first_biggest_size_base_type_member | -3
typedef__fprintf | +16
imported_declaration__fprintf | +6
imported_module__fprintf | +3
cu__new | +26
cu__delete | +26
hashtags__hash | -65
hash_64 | -124
hlist_add_head | -78
hashtags__find | -157
cu__hash | -80
cu__add_tag | +20
tag__prefix | -3
cu__find_tag_by_id | -2
cu__find_type_by_id | -3
cu__find_first_typedef_of_type | +38
cu__find_base_type_by_name | +68
cu__find_base_type_by_name_and_size | +72
cu__find_struct_by_name | +59
cus__find_struct_by_name | +8
cus__find_tag_by_id | +5
cus__find_cu_by_name | -6
lexblock__find_tag_by_id | -173
cu__find_variable_by_id | -197
list__find_tag_by_id | -308
cu__find_parameter_by_id | -60
tag__ptr_name | +6
tag__name | +15
variable__type | +13
variable__name | +7
class_member__size | +6
parameter__name | -119
tag__parameter | -14
parameter__type | -143
type__fprintf | -29
union__fprintf | +6
class__add_vtable_entry | -9
type__add_member | -6
type__clone_members | -3
enumeration__add | -6
function__name | -156
ftype__has_parm_of_type | -39
class__find_holes | -27
class__has_hole_ge | -3
type__nr_members_of_type | +3
lexblock__account_inline_expansions | +3
cu__account_inline_expansions | -18
ftype__fprintf_parms | +46
function__tag_fprintf | +24
lexblock__fprintf | -6
ftype__fprintf | +3
function__fprintf_stats | -18
function__size | -6
class__vtable_fprintf | -11
class__fprintf | -21
tag__fprintf | -35
60 functions changed, 513 bytes added, 2054 bytes removed, diff: -1541
/home/acme/git/pahole/ctf_loader.c:
struct ctf_short_type | +0
14 structs changed
type__init | -14
type__new | -9
class__new | -12
create_new_base_type | -7
create_new_base_type_float | -7
create_new_array | -8
create_new_subroutine_type | -9
create_full_members | -18
create_short_members | -18
create_new_class | +1
create_new_union | +1
create_new_enumeration | -19
create_new_forward_decl | -2
create_new_typedef | +3
create_new_tag | -5
load_types | +16
class__fixup_ctf_bitfields | -3
17 functions changed, 21 bytes added, 131 bytes removed, diff: -110
/home/acme/git/pahole/dwarf_loader.c:
17 structs changed
zalloc | -56
tag__init | +3
array_type__new | +20
type__init | -24
class_member__new | +46
inline_expansion__new | +12
class__new | +81
lexblock__init | +19
function__new | +43
die__create_new_array | +20
die__create_new_parameter | +4
die__create_new_label | +4
die__create_new_subroutine_type | +113
die__create_new_enumeration | -21
die__process_class | +79
die__process_namespace | +76
die__create_new_inline_expansion | +4
die__process_function | +147
__die__process_tag | +34
die__process_unit | +56
die__process | +90
21 functions changed, 851 bytes added, 101 bytes removed, diff: +750
/home/acme/git/pahole/dwarves.c:
struct ptr_table | +16
struct cu_orig_info | +32
2 structs changed
tag__decl_line | +68
tag__decl_file | +70
tag__orig_id | +71
ptr_table__init | +46
ptr_table__exit | +37
ptr_table__add | +183
ptr_table__add_with_id | +165
ptr_table__entry | +64
cu__table_add_tag | +171
cu__table_nullify_type_entry | +38
10 functions changed, 913 bytes added, diff: +913
/home/acme/git/pahole/ctf_loader.c:
2 structs changed
tag__alloc | +52
1 function changed, 52 bytes added, diff: +52
/home/acme/git/pahole/dwarf_loader.c:
struct dwarf_tag | +48
struct dwarf_cu | +4104
4 structs changed
dwarf_cu__init | +83
hashtags__hash | +61
hash_64 | +124
hlist_add_head | +78
hashtags__find | +161
cu__hash | +95
tag__is_tag_type | +171
tag__is_type | +85
tag__is_union | +28
tag__is_struct | +57
tag__is_typedef | +28
tag__is_enumeration | +28
dwarf_cu__find_tag_by_id | +56
dwarf_cu__find_type_by_id | +63
tag__alloc | +114
__tag__print_type_not_found | +108
namespace__recode_dwarf_types | +346
tag__namespace | +14
tag__has_namespace | +86
tag__is_namespace | +28
type__recode_dwarf_specification | +182
tag__type | +14
__tag__print_abstract_origin_not_found | +105
ftype__recode_dwarf_types | +322
tag__ftype | +14
tag__parameter | +14
lexblock__recode_dwarf_types | +736
tag__lexblock | +14
tag__label | +14
tag__recode_dwarf_type | +766
tag__ptr_to_member_type | +14
cu__recode_dwarf_types_table | +88
cu__recode_dwarf_types | +48
dwarf_tag__decl_file | +77
strings__ptr | +33
dwarf_tag__decl_line | +59
dwarf_tag__orig_id | +59
dwarf_tag__orig_type | +59
38 functions changed, 4432 bytes added, diff: +4432
build/libdwarves.so.1.0.0:
147 functions changed, 6782 bytes added, 2286 bytes removed, diff: +4496
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-06 00:29:35 +01:00
|
|
|
new_type_id);
|
2007-05-07 05:30:02 +02:00
|
|
|
fixup_was_done = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bitfield_head = NULL;
|
|
|
|
}
|
|
|
|
if (verbose && fixup_was_done) {
|
|
|
|
fprintf(fp, "/* bitfield types were fixed */\n");
|
|
|
|
if (verbose > 1) {
|
2009-03-17 18:31:18 +01:00
|
|
|
class__find_holes(self);
|
2007-05-07 05:30:02 +02:00
|
|
|
class__fprintf(self, cu, NULL, fp);
|
|
|
|
fputc('\n', fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-29 18:37:52 +02:00
|
|
|
void class__reorganize(struct class *self, const struct cu *cu,
|
|
|
|
const int verbose, FILE *fp)
|
2007-05-07 05:30:02 +02:00
|
|
|
{
|
|
|
|
struct class_member *member, *brother, *last_member;
|
|
|
|
|
|
|
|
class__fixup_member_types(self, cu, verbose, fp);
|
|
|
|
|
|
|
|
while (class__demote_bitfields(self, cu, verbose, fp))
|
|
|
|
class__reorganize_bitfields(self, cu, verbose, fp);
|
2009-03-14 17:50:36 +01:00
|
|
|
|
2007-05-07 05:30:02 +02:00
|
|
|
/* Now try to combine holes */
|
|
|
|
restart:
|
2009-03-17 18:31:18 +01:00
|
|
|
class__find_holes(self);
|
2007-05-29 18:32:14 +02:00
|
|
|
/*
|
|
|
|
* It can be NULL if this class doesn't have any data members,
|
|
|
|
* just inheritance entries
|
|
|
|
*/
|
2007-05-24 03:10:50 +02:00
|
|
|
last_member = type__last_member(&self->type);
|
2007-05-29 18:32:14 +02:00
|
|
|
if (last_member == NULL)
|
2007-05-29 18:37:52 +02:00
|
|
|
return;
|
2007-05-29 18:32:14 +02:00
|
|
|
|
2007-05-29 19:06:33 +02:00
|
|
|
type__for_each_data_member(&self->type, member) {
|
2007-05-07 05:30:02 +02:00
|
|
|
/* See if we have a hole after this member */
|
|
|
|
if (member->hole != 0) {
|
|
|
|
/*
|
|
|
|
* OK, try to find a member that has a hole after it
|
|
|
|
* and that has a size that fits the current hole:
|
|
|
|
*/
|
|
|
|
brother = class__find_next_hole_of_size(self, member,
|
|
|
|
member->hole);
|
|
|
|
if (brother != NULL) {
|
|
|
|
struct class_member *brother_prev =
|
|
|
|
list_entry(brother->tag.node.prev,
|
|
|
|
struct class_member,
|
|
|
|
tag.node);
|
|
|
|
/*
|
|
|
|
* If it the next member, avoid moving it closer,
|
|
|
|
* it could be a explicit alignment rule, like
|
|
|
|
* ____cacheline_aligned_in_smp in the Linux
|
|
|
|
* kernel.
|
|
|
|
*/
|
|
|
|
if (brother_prev != member) {
|
|
|
|
class__move_member(self, member,
|
|
|
|
brother, cu, 0,
|
|
|
|
verbose, fp);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* OK, but is there padding? If so the last member
|
|
|
|
* has a hole, if we are not at the last member and
|
|
|
|
* it has a size that is smaller than the current hole
|
|
|
|
* we can move it after the current member, reducing
|
|
|
|
* the padding or eliminating it altogether.
|
|
|
|
*/
|
|
|
|
if (self->padding > 0 &&
|
|
|
|
member != last_member &&
|
2009-03-17 18:31:18 +01:00
|
|
|
last_member->byte_size != 0 &&
|
|
|
|
last_member->byte_size <= member->hole) {
|
2007-05-07 05:30:02 +02:00
|
|
|
class__move_member(self, member, last_member,
|
|
|
|
cu, 1, verbose, fp);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now try to move members at the tail to after holes */
|
|
|
|
if (self->nr_holes == 0)
|
2007-05-29 18:37:52 +02:00
|
|
|
return;
|
2007-05-07 05:30:02 +02:00
|
|
|
|
2007-05-29 19:06:33 +02:00
|
|
|
type__for_each_data_member(&self->type, member) {
|
2007-05-07 05:30:02 +02:00
|
|
|
/* See if we have a hole after this member */
|
|
|
|
if (member->hole != 0) {
|
|
|
|
brother = class__find_last_member_of_size(self, member,
|
|
|
|
member->hole);
|
|
|
|
if (brother != NULL) {
|
|
|
|
struct class_member *brother_prev =
|
|
|
|
list_entry(brother->tag.node.prev,
|
|
|
|
struct class_member,
|
|
|
|
tag.node);
|
|
|
|
/*
|
|
|
|
* If it the next member, avoid moving it closer,
|
|
|
|
* it could be a explicit alignment rule, like
|
|
|
|
* ____cacheline_aligned_in_smp in the Linux
|
|
|
|
* kernel.
|
|
|
|
*/
|
|
|
|
if (brother_prev != member) {
|
|
|
|
class__move_member(self, member,
|
|
|
|
brother, cu, 0,
|
|
|
|
verbose, fp);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|