]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 476548 - valgrind 3.22.0 fails on assertion when loading debuginfo file produced...
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sat, 18 Nov 2023 07:49:34 +0000 (08:49 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sat, 18 Nov 2023 07:50:45 +0000 (08:50 +0100)
NEWS
coregrind/m_debuginfo/image.c
coregrind/m_debuginfo/priv_image.h
coregrind/m_debuginfo/readelf.c

diff --git a/NEWS b/NEWS
index 93ab2f08ba29f746e53163af3ffbad3193adcf48..45381c40342a6de4a443f840150291196e547d38 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 476320  Build failure with GCC
 476535  Difference in allocation size for massif/tests/overloaded-new between
         clang++/libc++ and g++/libstdc++
+476548  valgrind 3.22.0 fails on assertion when loading debuginfo file produced by mold
 476708  valgrind-monitor.py regular expressions should use raw strings
 476780  Extend strlcat and strlcpy wrappers to GNU libc
 476787  Build of Valgrind 3.21.0 fails when SOLARIS_PT_SUNDWTRACE_THRP is
index 02e5090713ddc25d7beaa03de6ebe80747a3af25..445f95555151fa605f88307495c9610c846e3612 100644 (file)
@@ -1221,6 +1221,20 @@ Int ML_(img_strcmp_c)(DiImage* img, DiOffT off1, const HChar* str2)
    }
 }
 
+Int ML_(img_strcmp_n)(DiImage* img, DiOffT off1, const HChar* str2, Word n)
+{
+   ensure_valid(img, off1, 1, "ML_(img_strcmp_c)");
+   while (n) {
+      UChar c1 = get(img, off1);
+      UChar c2 = *(const UChar*)str2;
+      if (c1 < c2) return -1;
+      if (c1 > c2) return 1;
+      if (c1 == 0) return 0;
+      off1++; str2++; --n;
+   }
+   return 0;
+}
+
 UChar ML_(img_get_UChar)(DiImage* img, DiOffT offset)
 {
    ensure_valid(img, offset, 1, "ML_(img_get_UChar)");
index a49846f149a38090851948dffdd492a07b68e21e..c91e49f015f4843ec75fa2b9a0de7257867f6491 100644 (file)
@@ -115,6 +115,10 @@ Int ML_(img_strcmp)(DiImage* img, DiOffT off1, DiOffT off2);
    cast to HChar before comparison. */
 Int ML_(img_strcmp_c)(DiImage* img, DiOffT off1, const HChar* str2);
 
+/* Do strncmp of a C string in the image vs a normal one.  Chars are
+   cast to HChar before comparison. */
+Int ML_(img_strcmp_n)(DiImage* img, DiOffT off1, const HChar* str2, Word n);
+
 /* Do strlen of a C string in the image. */
 SizeT ML_(img_strlen)(DiImage* img, DiOffT off);
 
index 3af8072d2014e4d0dab279622e6c7d679a7f030d..418ee8627c6f3350fc562f003b6dd1087bcdb896 100644 (file)
@@ -2501,8 +2501,7 @@ Bool ML_(read_elf_object) ( struct _DebugInfo* di )
             di->rodata_avma += inrw1->bias;
             di->rodata_bias = inrw1->bias;
             di->rodata_debug_bias = inrw1->bias;
-         }
-         else {
+         } else {
             BAD(".rodata");  /* should not happen? */
          }
          di->rodata_present = True;
@@ -2977,6 +2976,46 @@ Bool ML_(read_elf_object) ( struct _DebugInfo* di )
    return retval;
 }
 
+static void find_rodata(Word i, Word shnum, DiImage* dimg, struct _DebugInfo* di, DiOffT shdr_dioff,
+                        UWord shdr_dent_szB, DiOffT shdr_strtab_dioff, PtrdiffT rw_dbias)
+{
+   ElfXX_Shdr a_shdr;
+   ElfXX_Shdr a_extra_shdr;
+   ML_(img_get)(&a_shdr, dimg,
+                INDEX_BIS(shdr_dioff, i, shdr_dent_szB),
+                sizeof(a_shdr));
+   if (di->rodata_present &&
+       0 == ML_(img_strcmp_c)(dimg, shdr_strtab_dioff
+                                    + a_shdr.sh_name, ".rodata")) {
+      Word sh_size = a_shdr.sh_size;
+      Word j;
+      Word next_addr = a_shdr.sh_addr + a_shdr.sh_size;
+      for (j = i  + 1; j < shnum; ++j) {
+         ML_(img_get)(&a_extra_shdr, dimg,
+                      INDEX_BIS(shdr_dioff, j, shdr_dent_szB),
+                      sizeof(a_shdr));
+         if (0 == ML_(img_strcmp_n)(dimg, shdr_strtab_dioff
+                                             + a_extra_shdr.sh_name, ".rodata", 7)) {
+            if (a_extra_shdr.sh_addr ==
+                VG_ROUNDUP(next_addr, a_extra_shdr.sh_addralign)) {
+               sh_size = VG_ROUNDUP(sh_size, a_extra_shdr.sh_addralign) + a_extra_shdr.sh_size;
+            }
+            next_addr = a_extra_shdr.sh_addr + a_extra_shdr.sh_size;
+         } else {
+            break;
+         }
+      }
+      vg_assert(di->rodata_size == sh_size);
+      vg_assert(di->rodata_avma +  a_shdr.sh_addr + rw_dbias);
+      di->rodata_debug_svma = a_shdr.sh_addr;
+      di->rodata_debug_bias = di->rodata_bias +
+                             di->rodata_svma - di->rodata_debug_svma;
+      TRACE_SYMTAB("acquiring .rodata  debug svma = %#lx .. %#lx\n",
+                   di->rodata_debug_svma,
+                   di->rodata_debug_svma + di->rodata_size - 1);
+      TRACE_SYMTAB("acquiring .rodata debug bias = %#lx\n", (UWord)di->rodata_debug_bias);
+   }
+}
 Bool ML_(read_elf_debug) ( struct _DebugInfo* di )
 {
    Word     i, j;
@@ -3391,7 +3430,11 @@ Bool ML_(read_elf_debug) ( struct _DebugInfo* di )
             FIND(text,   rx)
             FIND(data,   rw)
             FIND(sdata,  rw)
-            FIND(rodata, rw)
+            // https://bugs.kde.org/show_bug.cgi?id=476548
+            // special handling for rodata as adjacent
+            // rodata sections may have been merged in ML_(read_elf_object)
+            //FIND(rodata, rw)
+            find_rodata(i, ehdr_dimg.e_shnum, dimg, di, shdr_dioff, shdr_dent_szB, shdr_strtab_dioff, rw_dbias);
             FIND(bss,    rw)
             FIND(sbss,   rw)