summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/valgrind/valgrind/0002-Bug-476548-valgrind-3.22.0-fails-on-assertion-when-l.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/valgrind/valgrind/0002-Bug-476548-valgrind-3.22.0-fails-on-assertion-when-l.patch')
-rw-r--r--meta/recipes-devtools/valgrind/valgrind/0002-Bug-476548-valgrind-3.22.0-fails-on-assertion-when-l.patch147
1 files changed, 147 insertions, 0 deletions
diff --git a/meta/recipes-devtools/valgrind/valgrind/0002-Bug-476548-valgrind-3.22.0-fails-on-assertion-when-l.patch b/meta/recipes-devtools/valgrind/valgrind/0002-Bug-476548-valgrind-3.22.0-fails-on-assertion-when-l.patch
new file mode 100644
index 0000000000..5759fa039a
--- /dev/null
+++ b/meta/recipes-devtools/valgrind/valgrind/0002-Bug-476548-valgrind-3.22.0-fails-on-assertion-when-l.patch
@@ -0,0 +1,147 @@
1From 1d00e5ce0fb069911c4b525ec38289fb5d9021b0 Mon Sep 17 00:00:00 2001
2From: Paul Floyd <pjfloyd@wanadoo.fr>
3Date: Sat, 18 Nov 2023 08:49:34 +0100
4Subject: [PATCH 2/4] Bug 476548 - valgrind 3.22.0 fails on assertion when
5 loading debuginfo file produced by mold
6
7(cherry picked from commit 9ea4ae66707a4dcc6f4328e11911652e4418c585)
8
9Upstream-Status: Backport [https://sourceware.org/git/?p=valgrind.git;a=commit;h=1d00e5ce0fb069911c4b525ec38289fb5d9021b0]
10Signed-off-by: Khem Raj <raj.khem@gmail.com>
11---
12 NEWS | 2 ++
13 coregrind/m_debuginfo/image.c | 14 +++++++++
14 coregrind/m_debuginfo/priv_image.h | 4 +++
15 coregrind/m_debuginfo/readelf.c | 49 ++++++++++++++++++++++++++++--
16 4 files changed, 66 insertions(+), 3 deletions(-)
17
18diff --git a/NEWS b/NEWS
19index ee5b4ff11..6cd13429a 100644
20--- a/NEWS
21+++ b/NEWS
22@@ -5,6 +5,8 @@ Branch 3.22
23
24 The following bugs have been fixed or resolved on this branch.
25
26+476548 valgrind 3.22.0 fails on assertion when loading debuginfo
27+ file produced by mold
28 476708 valgrind-monitor.py regular expressions should use raw strings
29
30 To see details of a given bug, visit
31diff --git a/coregrind/m_debuginfo/image.c b/coregrind/m_debuginfo/image.c
32index 02e509071..445f95555 100644
33--- a/coregrind/m_debuginfo/image.c
34+++ b/coregrind/m_debuginfo/image.c
35@@ -1221,6 +1221,20 @@ Int ML_(img_strcmp_c)(DiImage* img, DiOffT off1, const HChar* str2)
36 }
37 }
38
39+Int ML_(img_strcmp_n)(DiImage* img, DiOffT off1, const HChar* str2, Word n)
40+{
41+ ensure_valid(img, off1, 1, "ML_(img_strcmp_c)");
42+ while (n) {
43+ UChar c1 = get(img, off1);
44+ UChar c2 = *(const UChar*)str2;
45+ if (c1 < c2) return -1;
46+ if (c1 > c2) return 1;
47+ if (c1 == 0) return 0;
48+ off1++; str2++; --n;
49+ }
50+ return 0;
51+}
52+
53 UChar ML_(img_get_UChar)(DiImage* img, DiOffT offset)
54 {
55 ensure_valid(img, offset, 1, "ML_(img_get_UChar)");
56diff --git a/coregrind/m_debuginfo/priv_image.h b/coregrind/m_debuginfo/priv_image.h
57index a49846f14..c91e49f01 100644
58--- a/coregrind/m_debuginfo/priv_image.h
59+++ b/coregrind/m_debuginfo/priv_image.h
60@@ -115,6 +115,10 @@ Int ML_(img_strcmp)(DiImage* img, DiOffT off1, DiOffT off2);
61 cast to HChar before comparison. */
62 Int ML_(img_strcmp_c)(DiImage* img, DiOffT off1, const HChar* str2);
63
64+/* Do strncmp of a C string in the image vs a normal one. Chars are
65+ cast to HChar before comparison. */
66+Int ML_(img_strcmp_n)(DiImage* img, DiOffT off1, const HChar* str2, Word n);
67+
68 /* Do strlen of a C string in the image. */
69 SizeT ML_(img_strlen)(DiImage* img, DiOffT off);
70
71diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c
72index fb64ed976..46f8c8343 100644
73--- a/coregrind/m_debuginfo/readelf.c
74+++ b/coregrind/m_debuginfo/readelf.c
75@@ -2501,8 +2501,7 @@ Bool ML_(read_elf_object) ( struct _DebugInfo* di )
76 di->rodata_avma += inrw1->bias;
77 di->rodata_bias = inrw1->bias;
78 di->rodata_debug_bias = inrw1->bias;
79- }
80- else {
81+ } else {
82 BAD(".rodata"); /* should not happen? */
83 }
84 di->rodata_present = True;
85@@ -2977,6 +2976,46 @@ Bool ML_(read_elf_object) ( struct _DebugInfo* di )
86 return retval;
87 }
88
89+static void find_rodata(Word i, Word shnum, DiImage* dimg, struct _DebugInfo* di, DiOffT shdr_dioff,
90+ UWord shdr_dent_szB, DiOffT shdr_strtab_dioff, PtrdiffT rw_dbias)
91+{
92+ ElfXX_Shdr a_shdr;
93+ ElfXX_Shdr a_extra_shdr;
94+ ML_(img_get)(&a_shdr, dimg,
95+ INDEX_BIS(shdr_dioff, i, shdr_dent_szB),
96+ sizeof(a_shdr));
97+ if (di->rodata_present &&
98+ 0 == ML_(img_strcmp_c)(dimg, shdr_strtab_dioff
99+ + a_shdr.sh_name, ".rodata")) {
100+ Word sh_size = a_shdr.sh_size;
101+ Word j;
102+ Word next_addr = a_shdr.sh_addr + a_shdr.sh_size;
103+ for (j = i + 1; j < shnum; ++j) {
104+ ML_(img_get)(&a_extra_shdr, dimg,
105+ INDEX_BIS(shdr_dioff, j, shdr_dent_szB),
106+ sizeof(a_shdr));
107+ if (0 == ML_(img_strcmp_n)(dimg, shdr_strtab_dioff
108+ + a_extra_shdr.sh_name, ".rodata", 7)) {
109+ if (a_extra_shdr.sh_addr ==
110+ VG_ROUNDUP(next_addr, a_extra_shdr.sh_addralign)) {
111+ sh_size = VG_ROUNDUP(sh_size, a_extra_shdr.sh_addralign) + a_extra_shdr.sh_size;
112+ }
113+ next_addr = a_extra_shdr.sh_addr + a_extra_shdr.sh_size;
114+ } else {
115+ break;
116+ }
117+ }
118+ vg_assert(di->rodata_size == sh_size);
119+ vg_assert(di->rodata_avma + a_shdr.sh_addr + rw_dbias);
120+ di->rodata_debug_svma = a_shdr.sh_addr;
121+ di->rodata_debug_bias = di->rodata_bias +
122+ di->rodata_svma - di->rodata_debug_svma;
123+ TRACE_SYMTAB("acquiring .rodata debug svma = %#lx .. %#lx\n",
124+ di->rodata_debug_svma,
125+ di->rodata_debug_svma + di->rodata_size - 1);
126+ TRACE_SYMTAB("acquiring .rodata debug bias = %#lx\n", (UWord)di->rodata_debug_bias);
127+ }
128+}
129 Bool ML_(read_elf_debug) ( struct _DebugInfo* di )
130 {
131 Word i, j;
132@@ -3391,7 +3430,11 @@ Bool ML_(read_elf_debug) ( struct _DebugInfo* di )
133 FIND(text, rx)
134 FIND(data, rw)
135 FIND(sdata, rw)
136- FIND(rodata, rw)
137+ // https://bugs.kde.org/show_bug.cgi?id=476548
138+ // special handling for rodata as adjacent
139+ // rodata sections may have been merged in ML_(read_elf_object)
140+ //FIND(rodata, rw)
141+ find_rodata(i, ehdr_dimg.e_shnum, dimg, di, shdr_dioff, shdr_dent_szB, shdr_strtab_dioff, rw_dbias);
142 FIND(bss, rw)
143 FIND(sbss, rw)
144
145--
1462.44.0
147