[binutils-gdb] Re: PR29785, memory bloat after b43771b045fb

Alan Modra amodra@sourceware.org
Wed Feb 21 13:10:57 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f96127310144d360eac93444c1b6efe80497d163

commit f96127310144d360eac93444c1b6efe80497d163
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Feb 21 21:59:40 2024 +1030

    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:
---
 bfd/dwarf2.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

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)


More information about the Binutils-cvs mailing list