From: Alan Modra Date: Wed, 21 Feb 2024 11:29:40 +0000 (+1030) Subject: Re: PR29785, memory bloat after b43771b045fb X-Git-Tag: gdb-15-branchpoint~918 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f96127310144d360eac93444c1b6efe80497d163;p=thirdparty%2Fbinutils-gdb.git Re: PR29785, memory bloat after b43771b045fb Commit 7bd1e04a3532 introduced "dwarf2.c:2152:29: runtime error: shift exponent 64 is too large". This is on the bucket_high_pc calculation which was moved to the top of insert_arange_in_trie where previously it was later, at a point where the overflow could not occur. Move it back and arrange for a duplicate calculation of bucket_high_pc which is also protected from overflow. PR 29785 * dwarf2.c (insert_arange_in_trie): Split bucket_high_pc. Move trie_pc_bits < VMA_BITS into splitting_leaf_will_help. --- diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index 8491257aaaf..5eda14e1e7e 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -2148,8 +2148,6 @@ insert_arange_in_trie (bfd *abfd, bfd_vma low_pc, bfd_vma high_pc) { - bfd_vma bucket_high_pc = - trie_pc + ((bfd_vma) -1 >> trie_pc_bits); /* Inclusive. */ bfd_vma clamped_low_pc, clamped_high_pc; int ch, from_ch, to_ch; bool is_full_leaf = false; @@ -2180,13 +2178,15 @@ insert_arange_in_trie (bfd *abfd, is_full_leaf = leaf->num_stored_in_leaf == trie->num_room_in_leaf; - if (is_full_leaf) + if (is_full_leaf && trie_pc_bits < VMA_BITS) { /* See if we have at least one leaf that does _not_ cover the entire bucket, so that splitting will actually reduce the number of elements in at least one of the child nodes. (For simplicity, we don't test the range we're inserting, but it will be counted on the next insertion where we're full, if any.) */ + bfd_vma bucket_high_pc = + trie_pc + ((bfd_vma) -1 >> trie_pc_bits); /* Inclusive. */ for (i = 0; i < leaf->num_stored_in_leaf; ++i) { if (leaf->ranges[i].low_pc > trie_pc @@ -2201,7 +2201,7 @@ insert_arange_in_trie (bfd *abfd, /* If we're a leaf with no more room and we're _not_ at the bottom, convert to an interior node. */ - if (is_full_leaf && splitting_leaf_will_help && trie_pc_bits < VMA_BITS) + if (is_full_leaf && splitting_leaf_will_help) { const struct trie_leaf *leaf = (struct trie_leaf *) trie; unsigned int i; @@ -2265,6 +2265,8 @@ insert_arange_in_trie (bfd *abfd, clamped_high_pc = high_pc; if (trie_pc_bits > 0) { + bfd_vma bucket_high_pc = + trie_pc + ((bfd_vma) -1 >> trie_pc_bits); /* Inclusive. */ if (clamped_low_pc < trie_pc) clamped_low_pc = trie_pc; if (clamped_high_pc > bucket_high_pc)