Skip to content

Commit 6afe884

Browse files
committed
dwarf_loader: Delay recoding bitfield types
Till all the tags were processed, as in DWARF we can have class_member types being defined _after_ them, so we don't find it when trying to recode class_member at constructor time (class_member__new). Do it later after all the types are hashed, in namespace__recode_dwarf_types. Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent bc77517 commit 6afe884

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

dwarf_loader.c

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ int class_member__dwarf_recode_bitfield(struct class_member *self,
579579
return 0;
580580
}
581581

582-
static struct class_member *class_member__new(Dwarf_Die *die, struct cu *cu)
582+
static struct class_member *class_member__new(Dwarf_Die *die)
583583
{
584584
struct class_member *self = tag__alloc(sizeof(*self));
585585

@@ -594,16 +594,6 @@ static struct class_member *class_member__new(Dwarf_Die *die, struct cu *cu)
594594
self->bitfield_offset = attr_numeric(die, DW_AT_bit_offset);
595595
self->bitfield_size = attr_numeric(die, DW_AT_bit_size);
596596
self->bit_offset = self->byte_offset * 8 + self->bitfield_offset;
597-
/*
598-
* We may need to recode the type, possibly creating a suitably
599-
* sized new base_type
600-
*/
601-
if (self->bitfield_size != 0 &&
602-
class_member__dwarf_recode_bitfield(self, cu)) {
603-
free(self->tag.priv);
604-
free(self);
605-
return NULL;
606-
}
607597
self->bit_hole = 0;
608598
self->bitfield_end = 0;
609599
self->visited = 0;
@@ -1108,7 +1098,7 @@ static int die__process_class(Dwarf_Die *die, struct type *class,
11081098
switch (dwarf_tag(die)) {
11091099
case DW_TAG_inheritance:
11101100
case DW_TAG_member: {
1111-
struct class_member *member = class_member__new(die, cu);
1101+
struct class_member *member = class_member__new(die);
11121102

11131103
if (member == NULL)
11141104
return -ENOMEM;
@@ -1365,7 +1355,7 @@ static void __tag__print_type_not_found(struct tag *self, const char *func)
13651355

13661356
static void ftype__recode_dwarf_types(struct tag *self, struct cu *cu);
13671357

1368-
static void namespace__recode_dwarf_types(struct tag *self, struct cu *cu)
1358+
static int namespace__recode_dwarf_types(struct tag *self, struct cu *cu)
13691359
{
13701360
struct tag *pos;
13711361
struct dwarf_cu *dcu = cu->priv;
@@ -1376,15 +1366,24 @@ static void namespace__recode_dwarf_types(struct tag *self, struct cu *cu)
13761366
struct dwarf_tag *dpos = pos->priv;
13771367

13781368
if (tag__has_namespace(pos)) {
1379-
namespace__recode_dwarf_types(pos, cu);
1369+
if (namespace__recode_dwarf_types(pos, cu))
1370+
return -1;
13801371
continue;
13811372
}
13821373

13831374
switch (pos->tag) {
1384-
case DW_TAG_member:
1385-
/* Check if this is an already recoded bitfield */
1386-
if (pos->type != 0)
1375+
case DW_TAG_member: {
1376+
struct class_member *member = tag__class_member(pos);
1377+
/*
1378+
* We may need to recode the type, possibly creating a
1379+
* suitably sized new base_type
1380+
*/
1381+
if (member->bitfield_size != 0) {
1382+
if (class_member__dwarf_recode_bitfield(member, cu))
1383+
return -1;
13871384
continue;
1385+
}
1386+
}
13881387
break;
13891388
case DW_TAG_subroutine_type:
13901389
case DW_TAG_subprogram:
@@ -1413,6 +1412,7 @@ static void namespace__recode_dwarf_types(struct tag *self, struct cu *cu)
14131412
next:
14141413
pos->type = dtype->small_id;
14151414
}
1415+
return 0;
14161416
}
14171417

14181418
static void type__recode_dwarf_specification(struct tag *self, struct cu *cu)
@@ -1572,22 +1572,20 @@ static void lexblock__recode_dwarf_types(struct lexblock *self, struct cu *cu)
15721572
}
15731573
}
15741574

1575-
static void tag__recode_dwarf_type(struct tag *self, struct cu *cu)
1575+
static int tag__recode_dwarf_type(struct tag *self, struct cu *cu)
15761576
{
15771577
struct dwarf_tag *dtag = self->priv;
15781578
struct dwarf_tag *dtype;
15791579

15801580
/* Check if this is an already recoded bitfield */
15811581
if (dtag == NULL)
1582-
return;
1582+
return 0;
15831583

15841584
if (tag__is_type(self))
15851585
type__recode_dwarf_specification(self, cu);
15861586

1587-
if (tag__has_namespace(self)) {
1588-
namespace__recode_dwarf_types(self, cu);
1589-
return;
1590-
}
1587+
if (tag__has_namespace(self))
1588+
return namespace__recode_dwarf_types(self, cu);
15911589

15921590
switch (self->tag) {
15931591
case DW_TAG_subprogram: {
@@ -1601,7 +1599,7 @@ static void tag__recode_dwarf_type(struct tag *self, struct cu *cu)
16011599
* <3><1423de>: Abbrev Number: 209 (DW_TAG_subprogram)
16021600
* <1423e0> DW_AT_declaration : 1
16031601
*/
1604-
return;
1602+
return 0;
16051603
}
16061604
dtype = dwarf_cu__find_tag_by_id(cu->priv, dtag->abstract_origin);
16071605
if (dtype == NULL)
@@ -1629,7 +1627,7 @@ static void tag__recode_dwarf_type(struct tag *self, struct cu *cu)
16291627

16301628
case DW_TAG_lexical_block:
16311629
lexblock__recode_dwarf_types(tag__lexblock(self), cu);
1632-
return;
1630+
return 0;
16331631

16341632
case DW_TAG_ptr_to_member_type: {
16351633
struct ptr_to_member_type *pt = tag__ptr_to_member_type(self);
@@ -1649,8 +1647,7 @@ static void tag__recode_dwarf_type(struct tag *self, struct cu *cu)
16491647
break;
16501648

16511649
case DW_TAG_namespace:
1652-
namespace__recode_dwarf_types(self, cu);
1653-
return;
1650+
return namespace__recode_dwarf_types(self, cu);
16541651
/* Damn, DW_TAG_inlined_subroutine is an special case
16551652
as dwarf_tag->id is in fact an abtract origin, i.e. must be
16561653
looked up in the tags_table, not in the types_table.
@@ -1669,37 +1666,42 @@ static void tag__recode_dwarf_type(struct tag *self, struct cu *cu)
16691666

16701667
if (dtag->type == 0) {
16711668
self->type = 0; /* void */
1672-
return;
1669+
return 0;
16731670
}
16741671

16751672
find_type:
16761673
dtype = dwarf_cu__find_type_by_id(cu->priv, dtag->type);
16771674
check_type:
16781675
if (dtype == NULL) {
16791676
tag__print_type_not_found(self);
1680-
return;
1677+
return 0;
16811678
}
16821679
out:
16831680
self->type = dtype->small_id;
1681+
return 0;
16841682
}
16851683

1686-
static void cu__recode_dwarf_types_table(struct cu *self,
1687-
struct ptr_table *pt,
1688-
uint32_t i)
1684+
static int cu__recode_dwarf_types_table(struct cu *self,
1685+
struct ptr_table *pt,
1686+
uint32_t i)
16891687
{
16901688
for (; i < pt->nr_entries; ++i) {
16911689
struct tag *tag = pt->entries[i];
16921690

16931691
if (tag != NULL) /* void, see cu__new */
1694-
tag__recode_dwarf_type(tag, self);
1692+
if (tag__recode_dwarf_type(tag, self))
1693+
return -1;
16951694
}
1695+
return 0;
16961696
}
16971697

1698-
static void cu__recode_dwarf_types(struct cu *self)
1698+
static int cu__recode_dwarf_types(struct cu *self)
16991699
{
1700-
cu__recode_dwarf_types_table(self, &self->types_table, 1);
1701-
cu__recode_dwarf_types_table(self, &self->tags_table, 0);
1702-
cu__recode_dwarf_types_table(self, &self->functions_table, 0);
1700+
if (cu__recode_dwarf_types_table(self, &self->types_table, 1) ||
1701+
cu__recode_dwarf_types_table(self, &self->tags_table, 0) ||
1702+
cu__recode_dwarf_types_table(self, &self->functions_table, 0))
1703+
return -1;
1704+
return 0;
17031705
}
17041706

17051707
static const char *dwarf_tag__decl_file(const struct tag *self,
@@ -1783,8 +1785,7 @@ static int die__process(Dwarf_Die *die, struct cu *cu)
17831785
"DW_TAG_compile_unit!\n",
17841786
__FUNCTION__, dwarf_tag_name(tag));
17851787

1786-
cu__recode_dwarf_types(cu);
1787-
return 0;
1788+
return cu__recode_dwarf_types(cu);
17881789
}
17891790

17901791
static int class_member__cache_byte_size(struct tag *self, struct cu *cu,

0 commit comments

Comments
 (0)