summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/recipes-devtools/binutils/binutils-2.38.inc4
-rw-r--r--meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-1.patch1224
-rw-r--r--meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-2.patch188
-rw-r--r--meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-3.patch211
-rw-r--r--meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-4.patch43
5 files changed, 1670 insertions, 0 deletions
diff --git a/meta/recipes-devtools/binutils/binutils-2.38.inc b/meta/recipes-devtools/binutils/binutils-2.38.inc
index 2ddeb0ed39..fc88d4a79e 100644
--- a/meta/recipes-devtools/binutils/binutils-2.38.inc
+++ b/meta/recipes-devtools/binutils/binutils-2.38.inc
@@ -35,5 +35,9 @@ SRC_URI = "\
35 file://0014-CVE-2019-1010204.patch \ 35 file://0014-CVE-2019-1010204.patch \
36 file://0015-CVE-2022-38533.patch \ 36 file://0015-CVE-2022-38533.patch \
37 file://0016-CVE-2022-38126.patch \ 37 file://0016-CVE-2022-38126.patch \
38 file://0017-CVE-2022-38127-1.patch \
39 file://0017-CVE-2022-38127-2.patch \
40 file://0017-CVE-2022-38127-3.patch \
41 file://0017-CVE-2022-38127-4.patch \
38" 42"
39S = "${WORKDIR}/git" 43S = "${WORKDIR}/git"
diff --git a/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-1.patch b/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-1.patch
new file mode 100644
index 0000000000..9bbf1d6453
--- /dev/null
+++ b/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-1.patch
@@ -0,0 +1,1224 @@
1From 19c26da69d68d5d863f37c06ad73ab6292d02ffa Mon Sep 17 00:00:00 2001
2From: Nick Clifton <nickc@redhat.com>
3Date: Wed, 6 Apr 2022 14:43:37 +0100
4Subject: [PATCH] Add code to display the contents of .debug_loclists sections
5 which contain offset entry tables.
6
7 PR 28981
8 * dwarf.c (fetch_indexed_value): Rename to fecth_indexed_addr and
9 return the address, rather than a string.
10 (fetch_indexed_value): New function - returns a value indexed by a
11 DW_FORM_loclistx or DW_FORM_rnglistx form.
12 (read_and_display_attr_value): Add support for DW_FORM_loclistx
13 and DW_FORM_rnglistx.
14 (process_debug_info): Load the loclists and rnglists sections.
15 (display_loclists_list): Add support for DW_LLE_base_addressx,
16 DW_LLE_startx_endx, DW_LLE_startx_length and
17 DW_LLE_default_location.
18 (display_offset_entry_loclists): New function. Displays a
19 .debug_loclists section that contains offset entry tables.
20 (display_debug_loc): Call the new function.
21 (display_debug_rnglists_list): Add support for
22 DW_RLE_base_addressx, DW_RLE_startx_endx and DW_RLE_startx_length.
23 (display_debug_ranges): Display the contents of the section's
24 header.
25 * dwarf.h (struct debug_info): Add loclists_base field.
26 * testsuite/binutils-all/dw5.W: Update expected output.
27 * testsuite/binutils-all/x86-64/pr26808.dump: Likewise.
28
29Upstream-Status: Backport [https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=19c26da69d68d5d863f37c06ad73ab6292d02ffa]
30
31Signed-off-by: Pgowda <pgowda.cve@gmail.com>
32---
33 binutils/ChangeLog | 24 +
34 binutils/dwarf.c | 513 +++++++++++++++---
35 binutils/dwarf.h | 4 +
36 binutils/testsuite/binutils-all/dw5.W | 2 +-
37 .../binutils-all/x86-64/pr26808.dump | 82 +--
38 gas/ChangeLog | 5 +
39 gas/testsuite/gas/elf/dwarf-5-irp.d | 2 +-
40 7 files changed, 517 insertions(+), 115 deletions(-)
41
42diff --git a/binutils/dwarf.c b/binutils/dwarf.c
43index 15b3c81a138..bc862f77c04 100644
44--- a/binutils/dwarf.c
45+++ b/binutils/dwarf.c
46@@ -240,7 +240,7 @@ static const char *
47 dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
48 {
49 /* As dwarf_vmatoa is used more then once in a printf call
50- for output, we are cycling through an fixed array of pointers
51+ for output, we are cycling through a fixed array of pointers
52 for return address. */
53 static int buf_pos = 0;
54 static struct dwarf_vmatoa_buf
55@@ -796,24 +796,70 @@ fetch_indexed_string (dwarf_vma idx, str
56 return ret;
57 }
58
59-static const char *
60-fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
61+static dwarf_vma
62+fetch_indexed_addr (dwarf_vma offset, uint32_t num_bytes)
63 {
64 struct dwarf_section *section = &debug_displays [debug_addr].section;
65
66 if (section->start == NULL)
67- return (_("<no .debug_addr section>"));
68+ {
69+ warn (_("<no .debug_addr section>"));
70+ return 0;
71+ }
72
73- if (offset + bytes > section->size)
74+ if (offset + num_bytes > section->size)
75 {
76 warn (_("Offset into section %s too big: 0x%s\n"),
77 section->name, dwarf_vmatoa ("x", offset));
78- return "<offset too big>";
79+ return 0;
80 }
81
82- return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
83+ return byte_get (section->start + offset, num_bytes);
84 }
85
86+/* Fetch a value from a debug section that has been indexed by
87+ something in another section (eg DW_FORM_loclistx).
88+ Returns 0 if the value could not be found. */
89+
90+static dwarf_vma
91+fetch_indexed_value (dwarf_vma index,
92+ enum dwarf_section_display_enum sec_enum)
93+{
94+ struct dwarf_section *section = &debug_displays [sec_enum].section;
95+
96+ if (section->start == NULL)
97+ {
98+ warn (_("Unable to locate %s section\n"), section->uncompressed_name);
99+ return 0;
100+ }
101+
102+ uint32_t pointer_size, bias;
103+
104+ if (byte_get (section->start, 4) == 0xffffffff)
105+ {
106+ pointer_size = 8;
107+ bias = 20;
108+ }
109+ else
110+ {
111+ pointer_size = 4;
112+ bias = 12;
113+ }
114+
115+ dwarf_vma offset = index * pointer_size;
116+
117+ /* Offsets are biased by the size of the section header. */
118+ offset += bias;
119+
120+ if (offset + pointer_size > section->size)
121+ {
122+ warn (_("Offset into section %s too big: 0x%s\n"),
123+ section->name, dwarf_vmatoa ("x", offset));
124+ return 0;
125+ }
126+
127+ return byte_get (section->start + offset, pointer_size);
128+}
129
130 /* FIXME: There are better and more efficient ways to handle
131 these structures. For now though, I just want something that
132@@ -1999,6 +2045,8 @@ skip_attr_bytes (unsigned long form,
133 case DW_FORM_strx:
134 case DW_FORM_GNU_addr_index:
135 case DW_FORM_addrx:
136+ case DW_FORM_loclistx:
137+ case DW_FORM_rnglistx:
138 READ_ULEB (uvalue, data, end);
139 break;
140
141@@ -2410,9 +2458,6 @@ read_and_display_attr_value (unsigned lo
142
143 switch (form)
144 {
145- default:
146- break;
147-
148 case DW_FORM_ref_addr:
149 if (dwarf_version == 2)
150 SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
151@@ -2496,6 +2541,8 @@ read_and_display_attr_value (unsigned lo
152 case DW_FORM_udata:
153 case DW_FORM_GNU_addr_index:
154 case DW_FORM_addrx:
155+ case DW_FORM_loclistx:
156+ case DW_FORM_rnglistx:
157 READ_ULEB (uvalue, data, end);
158 break;
159
160@@ -2515,6 +2562,9 @@ read_and_display_attr_value (unsigned lo
161 case DW_FORM_implicit_const:
162 uvalue = implicit_const;
163 break;
164+
165+ default:
166+ break;
167 }
168
169 switch (form)
170@@ -2710,6 +2760,8 @@ read_and_display_attr_value (unsigned lo
171 case DW_FORM_addrx2:
172 case DW_FORM_addrx3:
173 case DW_FORM_addrx4:
174+ case DW_FORM_loclistx:
175+ case DW_FORM_rnglistx:
176 if (!do_loc)
177 {
178 dwarf_vma base;
179@@ -2728,11 +2780,11 @@ read_and_display_attr_value (unsigned lo
180 /* We have already displayed the form name. */
181 printf (_("%c(index: 0x%s): %s"), delimiter,
182 dwarf_vmatoa ("x", uvalue),
183- fetch_indexed_value (offset, pointer_size));
184+ dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
185 else
186 printf (_("%c(addr_index: 0x%s): %s"), delimiter,
187 dwarf_vmatoa ("x", uvalue),
188- fetch_indexed_value (offset, pointer_size));
189+ dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
190 }
191 break;
192
193@@ -2754,6 +2806,13 @@ read_and_display_attr_value (unsigned lo
194 {
195 switch (attribute)
196 {
197+ case DW_AT_loclists_base:
198+ if (debug_info_p->loclists_base)
199+ warn (_("CU @ 0x%s has multiple loclists_base values"),
200+ dwarf_vmatoa ("x", debug_info_p->cu_offset));
201+ debug_info_p->loclists_base = uvalue;
202+ break;
203+
204 case DW_AT_frame_base:
205 have_frame_base = 1;
206 /* Fall through. */
207@@ -2776,7 +2835,8 @@ read_and_display_attr_value (unsigned lo
208 case DW_AT_GNU_call_site_target_clobbered:
209 if ((dwarf_version < 4
210 && (form == DW_FORM_data4 || form == DW_FORM_data8))
211- || form == DW_FORM_sec_offset)
212+ || form == DW_FORM_sec_offset
213+ || form == DW_FORM_loclistx)
214 {
215 /* Process location list. */
216 unsigned int lmax = debug_info_p->max_loc_offsets;
217@@ -2796,11 +2856,17 @@ read_and_display_attr_value (unsigned lo
218 lmax, sizeof (*debug_info_p->have_frame_base));
219 debug_info_p->max_loc_offsets = lmax;
220 }
221- if (this_set != NULL)
222+
223+ if (form == DW_FORM_loclistx)
224+ uvalue = fetch_indexed_value (uvalue, loclists);
225+ else if (this_set != NULL)
226 uvalue += this_set->section_offsets [DW_SECT_LOC];
227+
228 debug_info_p->have_frame_base [num] = have_frame_base;
229 if (attribute != DW_AT_GNU_locviews)
230 {
231+ uvalue += debug_info_p->loclists_base;
232+
233 /* Corrupt DWARF info can produce more offsets than views.
234 See PR 23062 for an example. */
235 if (debug_info_p->num_loc_offsets
236@@ -2844,7 +2910,8 @@ read_and_display_attr_value (unsigned lo
237 case DW_AT_ranges:
238 if ((dwarf_version < 4
239 && (form == DW_FORM_data4 || form == DW_FORM_data8))
240- || form == DW_FORM_sec_offset)
241+ || form == DW_FORM_sec_offset
242+ || form == DW_FORM_rnglistx)
243 {
244 /* Process range list. */
245 unsigned int lmax = debug_info_p->max_range_lists;
246@@ -2858,6 +2925,10 @@ read_and_display_attr_value (unsigned lo
247 lmax, sizeof (*debug_info_p->range_lists));
248 debug_info_p->max_range_lists = lmax;
249 }
250+
251+ if (form == DW_FORM_rnglistx)
252+ uvalue = fetch_indexed_value (uvalue, rnglists);
253+
254 debug_info_p->range_lists [num] = uvalue;
255 debug_info_p->num_range_lists++;
256 }
257@@ -3231,6 +3302,7 @@ read_and_display_attr_value (unsigned lo
258 have_frame_base = 1;
259 /* Fall through. */
260 case DW_AT_location:
261+ case DW_AT_loclists_base:
262 case DW_AT_string_length:
263 case DW_AT_return_addr:
264 case DW_AT_data_member_location:
265@@ -3248,7 +3320,8 @@ read_and_display_attr_value (unsigned lo
266 case DW_AT_GNU_call_site_target_clobbered:
267 if ((dwarf_version < 4
268 && (form == DW_FORM_data4 || form == DW_FORM_data8))
269- || form == DW_FORM_sec_offset)
270+ || form == DW_FORM_sec_offset
271+ || form == DW_FORM_loclistx)
272 printf (_(" (location list)"));
273 /* Fall through. */
274 case DW_AT_allocated:
275@@ -3517,6 +3590,9 @@ process_debug_info (struct dwarf_section
276 }
277
278 load_debug_section_with_follow (abbrev_sec, file);
279+ load_debug_section_with_follow (loclists, file);
280+ load_debug_section_with_follow (rnglists, file);
281+
282 if (debug_displays [abbrev_sec].section.start == NULL)
283 {
284 warn (_("Unable to locate %s section!\n"),
285@@ -3729,6 +3805,7 @@ process_debug_info (struct dwarf_section
286 debug_information [unit].have_frame_base = NULL;
287 debug_information [unit].max_loc_offsets = 0;
288 debug_information [unit].num_loc_offsets = 0;
289+ debug_information [unit].loclists_base = 0;
290 debug_information [unit].range_lists = NULL;
291 debug_information [unit].max_range_lists= 0;
292 debug_information [unit].num_range_lists = 0;
293@@ -6465,20 +6542,21 @@ display_loc_list (struct dwarf_section *
294 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
295
296 static void
297-display_loclists_list (struct dwarf_section *section,
298- unsigned char **start_ptr,
299- unsigned int debug_info_entry,
300- dwarf_vma offset,
301- dwarf_vma base_address,
302- unsigned char **vstart_ptr,
303- int has_frame_base)
304-{
305- unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
306- unsigned char *section_end = section->start + section->size;
307- dwarf_vma cu_offset;
308- unsigned int pointer_size;
309- unsigned int offset_size;
310- int dwarf_version;
311+display_loclists_list (struct dwarf_section * section,
312+ unsigned char ** start_ptr,
313+ unsigned int debug_info_entry,
314+ dwarf_vma offset,
315+ dwarf_vma base_address,
316+ unsigned char ** vstart_ptr,
317+ int has_frame_base)
318+{
319+ unsigned char * start = *start_ptr;
320+ unsigned char * vstart = *vstart_ptr;
321+ unsigned char * section_end = section->start + section->size;
322+ dwarf_vma cu_offset;
323+ unsigned int pointer_size;
324+ unsigned int offset_size;
325+ unsigned int dwarf_version;
326
327 /* Initialize it due to a false compiler warning. */
328 dwarf_vma begin = -1, vbegin = -1;
329@@ -6544,27 +6622,59 @@ display_loclists_list (struct dwarf_sect
330 case DW_LLE_end_of_list:
331 printf (_("<End of list>\n"));
332 break;
333+
334+ case DW_LLE_base_addressx:
335+ READ_ULEB (base_address, start, section_end);
336+ print_dwarf_vma (base_address, pointer_size);
337+ printf (_("(index into .debug_addr) "));
338+ base_address = fetch_indexed_addr (base_address, pointer_size);
339+ print_dwarf_vma (base_address, pointer_size);
340+ printf (_("(base address)\n"));
341+ break;
342+
343+ case DW_LLE_startx_endx:
344+ READ_ULEB (begin, start, section_end);
345+ begin = fetch_indexed_addr (begin, pointer_size);
346+ READ_ULEB (end, start, section_end);
347+ end = fetch_indexed_addr (end, pointer_size);
348+ break;
349+
350+ case DW_LLE_startx_length:
351+ READ_ULEB (begin, start, section_end);
352+ begin = fetch_indexed_addr (begin, pointer_size);
353+ READ_ULEB (end, start, section_end);
354+ end += begin;
355+ break;
356+
357+ case DW_LLE_default_location:
358+ begin = end = 0;
359+ break;
360+
361 case DW_LLE_offset_pair:
362 READ_ULEB (begin, start, section_end);
363 begin += base_address;
364 READ_ULEB (end, start, section_end);
365 end += base_address;
366 break;
367+
368+ case DW_LLE_base_address:
369+ SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
370+ section_end);
371+ print_dwarf_vma (base_address, pointer_size);
372+ printf (_("(base address)\n"));
373+ break;
374+
375 case DW_LLE_start_end:
376 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
377 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
378 break;
379+
380 case DW_LLE_start_length:
381 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
382 READ_ULEB (end, start, section_end);
383 end += begin;
384 break;
385- case DW_LLE_base_address:
386- SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
387- section_end);
388- print_dwarf_vma (base_address, pointer_size);
389- printf (_("(base address)\n"));
390- break;
391+
392 #ifdef DW_LLE_view_pair
393 case DW_LLE_view_pair:
394 if (vstart)
395@@ -6578,15 +6688,17 @@ display_loclists_list (struct dwarf_sect
396 printf (_("views for:\n"));
397 continue;
398 #endif
399+
400 default:
401 error (_("Invalid location list entry type %d\n"), llet);
402 return;
403 }
404+
405 if (llet == DW_LLE_end_of_list)
406 break;
407- if (llet != DW_LLE_offset_pair
408- && llet != DW_LLE_start_end
409- && llet != DW_LLE_start_length)
410+
411+ if (llet == DW_LLE_base_address
412+ || llet == DW_LLE_base_addressx)
413 continue;
414
415 if (start == section_end)
416@@ -6828,6 +6940,218 @@ loc_offsets_compar (const void *ap, cons
417 }
418
419 static int
420+display_offset_entry_loclists (struct dwarf_section *section)
421+{
422+ unsigned char * start = section->start;
423+ unsigned char * const end = start + section->size;
424+
425+ introduce (section, false);
426+
427+ do
428+ {
429+ dwarf_vma length;
430+ unsigned short version;
431+ unsigned char address_size;
432+ unsigned char segment_selector_size;
433+ uint32_t offset_entry_count;
434+ uint32_t i;
435+ bool is_64bit;
436+
437+ printf (_("Table at Offset 0x%lx\n"), (long)(start - section->start));
438+
439+ SAFE_BYTE_GET_AND_INC (length, start, 4, end);
440+ if (length == 0xffffffff)
441+ {
442+ is_64bit = true;
443+ SAFE_BYTE_GET_AND_INC (length, start, 8, end);
444+ }
445+ else
446+ is_64bit = false;
447+
448+ SAFE_BYTE_GET_AND_INC (version, start, 2, end);
449+ SAFE_BYTE_GET_AND_INC (address_size, start, 1, end);
450+ SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, end);
451+ SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, end);
452+
453+ printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", length));
454+ printf (_(" DWARF version: %u\n"), version);
455+ printf (_(" Address size: %u\n"), address_size);
456+ printf (_(" Segment size: %u\n"), segment_selector_size);
457+ printf (_(" Offset entries: %u\n"), offset_entry_count);
458+
459+ if (version < 5)
460+ {
461+ warn (_("The %s section contains a corrupt or "
462+ "unsupported version number: %d.\n"),
463+ section->name, version);
464+ return 0;
465+ }
466+
467+ if (segment_selector_size != 0)
468+ {
469+ warn (_("The %s section contains an "
470+ "unsupported segment selector size: %d.\n"),
471+ section->name, segment_selector_size);
472+ return 0;
473+ }
474+
475+ if (offset_entry_count == 0)
476+ {
477+ warn (_("The %s section contains a table without offset\n"),
478+ section->name);
479+ return 0;
480+ }
481+
482+ printf (_("\n Offset Entries starting at 0x%lx:\n"),
483+ (long)(start - section->start));
484+
485+ if (is_64bit)
486+ {
487+ for (i = 0; i < offset_entry_count; i++)
488+ {
489+ dwarf_vma entry;
490+
491+ SAFE_BYTE_GET_AND_INC (entry, start, 8, end);
492+ printf (_(" [%6u] 0x%s\n"), i, dwarf_vmatoa ("x", entry));
493+ }
494+ }
495+ else
496+ {
497+ for (i = 0; i < offset_entry_count; i++)
498+ {
499+ uint32_t entry;
500+
501+ SAFE_BYTE_GET_AND_INC (entry, start, 4, end);
502+ printf (_(" [%6u] 0x%x\n"), i, entry);
503+ }
504+ }
505+
506+ putchar ('\n');
507+
508+ uint32_t j;
509+
510+ for (j = 1, i = 0; i < offset_entry_count;)
511+ {
512+ unsigned char lle;
513+ dwarf_vma base_address = 0;
514+ dwarf_vma begin;
515+ dwarf_vma finish;
516+ dwarf_vma off = start - section->start;
517+
518+ if (j != i)
519+ {
520+ printf (_(" Offset Entry %u\n"), i);
521+ j = i;
522+ }
523+
524+ printf (" ");
525+ print_dwarf_vma (off, 4);
526+
527+ SAFE_BYTE_GET_AND_INC (lle, start, 1, end);
528+
529+ switch (lle)
530+ {
531+ case DW_LLE_end_of_list:
532+ printf (_("<End of list>\n\n"));
533+ i ++;
534+ continue;
535+
536+ case DW_LLE_base_addressx:
537+ READ_ULEB (base_address, start, end);
538+ print_dwarf_vma (base_address, address_size);
539+ printf (_("(index into .debug_addr) "));
540+ base_address = fetch_indexed_addr (base_address, address_size);
541+ print_dwarf_vma (base_address, address_size);
542+ printf (_("(base address)\n"));
543+ continue;
544+
545+ case DW_LLE_startx_endx:
546+ READ_ULEB (begin, start, end);
547+ begin = fetch_indexed_addr (begin, address_size);
548+ READ_ULEB (finish, start, end);
549+ finish = fetch_indexed_addr (finish, address_size);
550+ break;
551+
552+ case DW_LLE_startx_length:
553+ READ_ULEB (begin, start, end);
554+ begin = fetch_indexed_addr (begin, address_size);
555+ READ_ULEB (finish, start, end);
556+ finish += begin;
557+ break;
558+
559+ case DW_LLE_offset_pair:
560+ READ_ULEB (begin, start, end);
561+ begin += base_address;
562+ READ_ULEB (finish, start, end);
563+ finish += base_address;
564+ break;
565+
566+ case DW_LLE_default_location:
567+ begin = finish = 0;
568+ break;
569+
570+ case DW_LLE_base_address:
571+ SAFE_BYTE_GET_AND_INC (base_address, start, address_size, end);
572+ print_dwarf_vma (base_address, address_size);
573+ printf (_("(base address)\n"));
574+ continue;
575+
576+ case DW_LLE_start_end:
577+ SAFE_BYTE_GET_AND_INC (begin, start, address_size, end);
578+ SAFE_BYTE_GET_AND_INC (finish, start, address_size, end);
579+ break;
580+
581+ case DW_LLE_start_length:
582+ SAFE_BYTE_GET_AND_INC (begin, start, address_size, end);
583+ READ_ULEB (finish, start, end);
584+ finish += begin;
585+ break;
586+
587+ default:
588+ error (_("Invalid location list entry type %d\n"), lle);
589+ return 0;
590+ }
591+
592+ if (start == end)
593+ {
594+ warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
595+ (unsigned long) off);
596+ break;
597+ }
598+
599+ print_dwarf_vma (begin, address_size);
600+ print_dwarf_vma (finish, address_size);
601+
602+ if (begin == finish)
603+ fputs (_(" (start == end)"), stdout);
604+ else if (begin > finish)
605+ fputs (_(" (start > end)"), stdout);
606+
607+ /* Read the counted location descriptions. */
608+ READ_ULEB (length, start, end);
609+
610+ if (length > (size_t) (end - start))
611+ {
612+ warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
613+ (unsigned long) off);
614+ break;
615+ }
616+
617+ putchar (' ');
618+ (void) decode_location_expression (start, address_size, address_size,
619+ version, length, 0, section);
620+ start += length;
621+ putchar ('\n');
622+ }
623+
624+ putchar ('\n');
625+ }
626+ while (start < end);
627+
628+ return 1;
629+}
630+
631+static int
632 display_debug_loc (struct dwarf_section *section, void *file)
633 {
634 unsigned char *start = section->start, *vstart = NULL;
635@@ -6893,13 +7217,9 @@ display_debug_loc (struct dwarf_section
636 }
637
638 SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
639+
640 if (offset_entry_count != 0)
641- {
642- warn (_("The %s section contains "
643- "unsupported offset entry count: %d.\n"),
644- section->name, offset_entry_count);
645- return 0;
646- }
647+ return display_offset_entry_loclists (section);
648
649 expected_start = hdrptr - section_begin;
650 }
651@@ -6959,9 +7279,10 @@ display_debug_loc (struct dwarf_section
652 if (debug_information [first].num_loc_offsets > 0
653 && debug_information [first].loc_offsets [0] != expected_start
654 && debug_information [first].loc_views [0] != expected_start)
655- warn (_("Location lists in %s section start at 0x%s\n"),
656+ warn (_("Location lists in %s section start at 0x%s rather than 0x%s\n"),
657 section->name,
658- dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
659+ dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]),
660+ dwarf_vmatoa ("x", expected_start));
661
662 if (!locs_sorted)
663 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
664@@ -7639,24 +7960,44 @@ display_debug_rnglists_list (unsigned ch
665 case DW_RLE_end_of_list:
666 printf (_("<End of list>\n"));
667 break;
668- case DW_RLE_base_address:
669- SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
670+ case DW_RLE_base_addressx:
671+ READ_ULEB (base_address, start, finish);
672+ print_dwarf_vma (base_address, pointer_size);
673+ printf (_("(base address index) "));
674+ base_address = fetch_indexed_addr (base_address, pointer_size);
675 print_dwarf_vma (base_address, pointer_size);
676 printf (_("(base address)\n"));
677 break;
678- case DW_RLE_start_length:
679- SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
680+ case DW_RLE_startx_endx:
681+ READ_ULEB (begin, start, finish);
682+ READ_ULEB (end, start, finish);
683+ begin = fetch_indexed_addr (begin, pointer_size);
684+ end = fetch_indexed_addr (begin, pointer_size);
685+ break;
686+ case DW_RLE_startx_length:
687+ READ_ULEB (begin, start, finish);
688 READ_ULEB (length, start, finish);
689+ begin = fetch_indexed_addr (begin, pointer_size);
690 end = begin + length;
691 break;
692 case DW_RLE_offset_pair:
693 READ_ULEB (begin, start, finish);
694 READ_ULEB (end, start, finish);
695 break;
696+ case DW_RLE_base_address:
697+ SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
698+ print_dwarf_vma (base_address, pointer_size);
699+ printf (_("(base address)\n"));
700+ break;
701 case DW_RLE_start_end:
702 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
703 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
704 break;
705+ case DW_RLE_start_length:
706+ SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
707+ READ_ULEB (length, start, finish);
708+ end = begin + length;
709+ break;
710 default:
711 error (_("Invalid range list entry type %d\n"), rlet);
712 rlet = DW_RLE_end_of_list;
713@@ -7664,7 +8005,7 @@ display_debug_rnglists_list (unsigned ch
714 }
715 if (rlet == DW_RLE_end_of_list)
716 break;
717- if (rlet == DW_RLE_base_address)
718+ if (rlet == DW_RLE_base_address || rlet == DW_RLE_base_addressx)
719 continue;
720
721 /* Only a DW_RLE_offset_pair needs the base address added. */
722@@ -7709,6 +8050,8 @@ display_debug_ranges (struct dwarf_secti
723 return 0;
724 }
725
726+ introduce (section, false);
727+
728 if (is_rnglists)
729 {
730 dwarf_vma initial_length;
731@@ -7745,19 +8088,19 @@ display_debug_ranges (struct dwarf_secti
732 }
733 }
734
735- /* Get and check the version number. */
736+ /* Get the other fields in the header. */
737 SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
738-
739- if (version != 5)
740- {
741- warn (_("Only DWARF version 5 debug_rnglists info "
742- "is currently supported.\n"));
743- return 0;
744- }
745-
746 SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
747-
748 SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
749+ SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
750+
751+ printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", initial_length));
752+ printf (_(" DWARF version: %u\n"), version);
753+ printf (_(" Address size: %u\n"), address_size);
754+ printf (_(" Segment size: %u\n"), segment_selector_size);
755+ printf (_(" Offset entries: %u\n"), offset_entry_count);
756+
757+ /* Check the fields. */
758 if (segment_selector_size != 0)
759 {
760 warn (_("The %s section contains "
761@@ -7766,16 +8109,39 @@ display_debug_ranges (struct dwarf_secti
762 return 0;
763 }
764
765- SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
766- if (offset_entry_count != 0)
767+ if (version < 5)
768 {
769- warn (_("The %s section contains "
770- "unsupported offset entry count: %u.\n"),
771- section->name, offset_entry_count);
772+ warn (_("Only DWARF version 5+ debug_rnglists info "
773+ "is currently supported.\n"));
774 return 0;
775 }
776- }
777
778+ if (offset_entry_count != 0)
779+ {
780+ printf (_("\n Offsets starting at 0x%lx:\n"), (long)(start - section->start));
781+ if (offset_size == 8)
782+ {
783+ for (i = 0; i < offset_entry_count; i++)
784+ {
785+ dwarf_vma entry;
786+
787+ SAFE_BYTE_GET_AND_INC (entry, start, 8, finish);
788+ printf (_(" [%6u] 0x%s\n"), i, dwarf_vmatoa ("x", entry));
789+ }
790+ }
791+ else
792+ {
793+ for (i = 0; i < offset_entry_count; i++)
794+ {
795+ uint32_t entry;
796+
797+ SAFE_BYTE_GET_AND_INC (entry, start, 4, finish);
798+ printf (_(" [%6u] 0x%x\n"), i, entry);
799+ }
800+ }
801+ }
802+ }
803+
804 if (load_debug_info (file) == 0)
805 {
806 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
807@@ -7834,8 +8200,7 @@ display_debug_ranges (struct dwarf_secti
808 warn (_("Range lists in %s section start at 0x%lx\n"),
809 section->name, (unsigned long) range_entries[0].ranges_offset);
810
811- introduce (section, false);
812-
813+ putchar ('\n');
814 printf (_(" Offset Begin End\n"));
815
816 for (i = 0; i < num_range_list; i++)
817@@ -7895,8 +8260,12 @@ display_debug_ranges (struct dwarf_secti
818 start = next;
819 last_start = next;
820
821- (is_rnglists ? display_debug_rnglists_list : display_debug_ranges_list)
822- (start, finish, pointer_size, offset, base_address);
823+ if (is_rnglists)
824+ display_debug_rnglists_list
825+ (start, finish, pointer_size, offset, base_address);
826+ else
827+ display_debug_ranges_list
828+ (start, finish, pointer_size, offset, base_address);
829 }
830 putchar ('\n');
831
832diff --git a/binutils/dwarf.h b/binutils/dwarf.h
833index 4fc62abfa4c..ccce2461c81 100644
834--- a/binutils/dwarf.h
835+++ b/binutils/dwarf.h
836@@ -181,9 +181,13 @@ typedef struct
837 /* This is an array of offsets to the location view table. */
838 dwarf_vma * loc_views;
839 int * have_frame_base;
840+
841+ /* Information for associating location lists with CUs. */
842 unsigned int num_loc_offsets;
843 unsigned int max_loc_offsets;
844 unsigned int num_loc_views;
845+ dwarf_vma loclists_base;
846+
847 /* List of .debug_ranges offsets seen in this .debug_info. */
848 dwarf_vma * range_lists;
849 unsigned int num_range_lists;
850diff --git a/binutils/testsuite/binutils-all/dw5.W b/binutils/testsuite/binutils-all/dw5.W
851index ebab8b7d3b0..bfcdac175ba 100644
852--- a/binutils/testsuite/binutils-all/dw5.W
853+++ b/binutils/testsuite/binutils-all/dw5.W
854@@ -281,7 +281,7 @@ Contents of the .debug_loclists section:
855 00000039 <End of list>
856
857 Contents of the .debug_rnglists section:
858-
859+#...
860 Offset Begin End
861 0000000c 0000000000001234 0000000000001236
862 00000016 0000000000001234 0000000000001239
863diff --git a/binutils/testsuite/binutils-all/x86-64/pr26808.dump b/binutils/testsuite/binutils-all/x86-64/pr26808.dump
864index f64f9d008f9..7ef73b24dc9 100644
865--- a/binutils/testsuite/binutils-all/x86-64/pr26808.dump
866+++ b/binutils/testsuite/binutils-all/x86-64/pr26808.dump
867@@ -30,13 +30,13 @@ Contents of the .debug_info.dwo section:
868 <a5> DW_AT_decl_file : 1
869 <a6> DW_AT_decl_line : 30
870 <a7> DW_AT_type : <0x90>
871- <ab> DW_AT_low_pc : (addr_index: 0x0): <no .debug_addr section>
872+ <ab> DW_AT_low_pc : (addr_index: 0x0): 0
873 <ac> DW_AT_high_pc : 0x304
874 <b4> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
875 <b6> DW_AT_GNU_all_tail_call_sites: 1
876 <b6> DW_AT_sibling : <0x11b>
877 <2><ba>: Abbrev Number: 14 (DW_TAG_lexical_block)
878- <bb> DW_AT_low_pc : (addr_index: 0x1): <no .debug_addr section>
879+ <bb> DW_AT_low_pc : (addr_index: 0x1): 0
880 <bc> DW_AT_high_pc : 0x2fa
881 <3><c4>: Abbrev Number: 15 (DW_TAG_variable)
882 <c5> DW_AT_name : c1
883@@ -56,7 +56,7 @@ Contents of the .debug_info.dwo section:
884 <ff> DW_AT_artificial : 1
885 <ff> DW_AT_location : 2 byte block: fb 2 (DW_OP_GNU_addr_index <0x2>)
886 <3><102>: Abbrev Number: 14 (DW_TAG_lexical_block)
887- <103> DW_AT_low_pc : (addr_index: 0x3): <no .debug_addr section>
888+ <103> DW_AT_low_pc : (addr_index: 0x3): 0
889 <104> DW_AT_high_pc : 0x2f
890 <4><10c>: Abbrev Number: 17 (DW_TAG_variable)
891 <10d> DW_AT_name : i
892@@ -274,7 +274,7 @@ Contents of the .debug_info.dwo section:
893 <2dd> DW_AT_decl_file : 1
894 <2de> DW_AT_decl_line : 70
895 <2df> DW_AT_linkage_name: _Z4f13iv
896- <2e8> DW_AT_low_pc : (addr_index: 0x0): <no .debug_addr section>
897+ <2e8> DW_AT_low_pc : (addr_index: 0x0): 0
898 <2e9> DW_AT_high_pc : 0x6
899 <2f1> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
900 <2f3> DW_AT_GNU_all_call_sites: 1
901@@ -282,7 +282,7 @@ Contents of the .debug_info.dwo section:
902 <2f4> DW_AT_specification: <0x219>
903 <2f8> DW_AT_decl_file : 2
904 <2f9> DW_AT_decl_line : 30
905- <2fa> DW_AT_low_pc : (addr_index: 0x1): <no .debug_addr section>
906+ <2fa> DW_AT_low_pc : (addr_index: 0x1): 0
907 <2fb> DW_AT_high_pc : 0x20
908 <303> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
909 <305> DW_AT_object_pointer: <0x30d>
910@@ -300,7 +300,7 @@ Contents of the .debug_info.dwo section:
911 <31d> DW_AT_specification: <0x223>
912 <321> DW_AT_decl_file : 2
913 <322> DW_AT_decl_line : 38
914- <323> DW_AT_low_pc : (addr_index: 0x2): <no .debug_addr section>
915+ <323> DW_AT_low_pc : (addr_index: 0x2): 0
916 <324> DW_AT_high_pc : 0x18
917 <32c> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
918 <32e> DW_AT_object_pointer: <0x336>
919@@ -316,7 +316,7 @@ Contents of the .debug_info.dwo section:
920 <341> DW_AT_specification: <0x22d>
921 <345> DW_AT_decl_file : 2
922 <346> DW_AT_decl_line : 46
923- <347> DW_AT_low_pc : (addr_index: 0x3): <no .debug_addr section>
924+ <347> DW_AT_low_pc : (addr_index: 0x3): 0
925 <348> DW_AT_high_pc : 0x18
926 <350> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
927 <352> DW_AT_object_pointer: <0x35a>
928@@ -332,7 +332,7 @@ Contents of the .debug_info.dwo section:
929 <365> DW_AT_specification: <0x237>
930 <369> DW_AT_decl_file : 2
931 <36a> DW_AT_decl_line : 54
932- <36b> DW_AT_low_pc : (addr_index: 0x4): <no .debug_addr section>
933+ <36b> DW_AT_low_pc : (addr_index: 0x4): 0
934 <36c> DW_AT_high_pc : 0x16
935 <374> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
936 <376> DW_AT_object_pointer: <0x37e>
937@@ -348,7 +348,7 @@ Contents of the .debug_info.dwo section:
938 <389> DW_AT_specification: <0x26b>
939 <38d> DW_AT_decl_file : 2
940 <38e> DW_AT_decl_line : 62
941- <38f> DW_AT_low_pc : (addr_index: 0x5): <no .debug_addr section>
942+ <38f> DW_AT_low_pc : (addr_index: 0x5): 0
943 <390> DW_AT_high_pc : 0x16
944 <398> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
945 <39a> DW_AT_object_pointer: <0x3a2>
946@@ -366,7 +366,7 @@ Contents of the .debug_info.dwo section:
947 <3b2> DW_AT_specification: <0x275>
948 <3b6> DW_AT_decl_file : 2
949 <3b7> DW_AT_decl_line : 72
950- <3b8> DW_AT_low_pc : (addr_index: 0x6): <no .debug_addr section>
951+ <3b8> DW_AT_low_pc : (addr_index: 0x6): 0
952 <3b9> DW_AT_high_pc : 0x1b
953 <3c1> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
954 <3c3> DW_AT_object_pointer: <0x3cb>
955@@ -382,7 +382,7 @@ Contents of the .debug_info.dwo section:
956 <3d6> DW_AT_specification: <0x27f>
957 <3da> DW_AT_decl_file : 2
958 <3db> DW_AT_decl_line : 82
959- <3dc> DW_AT_low_pc : (addr_index: 0x7): <no .debug_addr section>
960+ <3dc> DW_AT_low_pc : (addr_index: 0x7): 0
961 <3dd> DW_AT_high_pc : 0x1b
962 <3e5> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
963 <3e7> DW_AT_object_pointer: <0x3ef>
964@@ -398,7 +398,7 @@ Contents of the .debug_info.dwo section:
965 <3fa> DW_AT_specification: <0x289>
966 <3fe> DW_AT_decl_file : 2
967 <3ff> DW_AT_decl_line : 92
968- <400> DW_AT_low_pc : (addr_index: 0x8): <no .debug_addr section>
969+ <400> DW_AT_low_pc : (addr_index: 0x8): 0
970 <401> DW_AT_high_pc : 0x19
971 <409> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
972 <40b> DW_AT_object_pointer: <0x413>
973@@ -414,7 +414,7 @@ Contents of the .debug_info.dwo section:
974 <41e> DW_AT_specification: <0x2ae>
975 <422> DW_AT_decl_file : 2
976 <423> DW_AT_decl_line : 102
977- <424> DW_AT_low_pc : (addr_index: 0x9): <no .debug_addr section>
978+ <424> DW_AT_low_pc : (addr_index: 0x9): 0
979 <425> DW_AT_high_pc : 0x19
980 <42d> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
981 <42f> DW_AT_object_pointer: <0x437>
982@@ -432,7 +432,7 @@ Contents of the .debug_info.dwo section:
983 <447> DW_AT_specification: <0x2b8>
984 <44b> DW_AT_decl_file : 2
985 <44c> DW_AT_decl_line : 112
986- <44d> DW_AT_low_pc : (addr_index: 0xa): <no .debug_addr section>
987+ <44d> DW_AT_low_pc : (addr_index: 0xa): 0
988 <44e> DW_AT_high_pc : 0x1f
989 <456> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
990 <458> DW_AT_object_pointer: <0x460>
991@@ -451,7 +451,7 @@ Contents of the .debug_info.dwo section:
992 <471> DW_AT_decl_line : 120
993 <472> DW_AT_linkage_name: _Z4f11av
994 <47b> DW_AT_type : <0x242>
995- <47f> DW_AT_low_pc : (addr_index: 0xb): <no .debug_addr section>
996+ <47f> DW_AT_low_pc : (addr_index: 0xb): 0
997 <480> DW_AT_high_pc : 0xb
998 <488> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
999 <48a> DW_AT_GNU_all_call_sites: 1
1000@@ -459,7 +459,7 @@ Contents of the .debug_info.dwo section:
1001 <48b> DW_AT_specification: <0x2c2>
1002 <48f> DW_AT_decl_file : 2
1003 <490> DW_AT_decl_line : 126
1004- <491> DW_AT_low_pc : (addr_index: 0xc): <no .debug_addr section>
1005+ <491> DW_AT_low_pc : (addr_index: 0xc): 0
1006 <492> DW_AT_high_pc : 0x20
1007 <49a> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1008 <49c> DW_AT_object_pointer: <0x4a4>
1009@@ -478,7 +478,7 @@ Contents of the .debug_info.dwo section:
1010 <4b4> DW_AT_decl_line : 134
1011 <4b5> DW_AT_linkage_name: _Z3t12v
1012 <4bd> DW_AT_type : <0x249>
1013- <4c1> DW_AT_low_pc : (addr_index: 0xd): <no .debug_addr section>
1014+ <4c1> DW_AT_low_pc : (addr_index: 0xd): 0
1015 <4c2> DW_AT_high_pc : 0x19
1016 <4ca> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1017 <4cc> DW_AT_GNU_all_tail_call_sites: 1
1018@@ -489,7 +489,7 @@ Contents of the .debug_info.dwo section:
1019 <4d2> DW_AT_decl_line : 142
1020 <4d3> DW_AT_linkage_name: _Z3t13v
1021 <4db> DW_AT_type : <0x249>
1022- <4df> DW_AT_low_pc : (addr_index: 0xe): <no .debug_addr section>
1023+ <4df> DW_AT_low_pc : (addr_index: 0xe): 0
1024 <4e0> DW_AT_high_pc : 0x14
1025 <4e8> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1026 <4ea> DW_AT_GNU_all_tail_call_sites: 1
1027@@ -500,13 +500,13 @@ Contents of the .debug_info.dwo section:
1028 <4f0> DW_AT_decl_line : 150
1029 <4f1> DW_AT_linkage_name: _Z3t14v
1030 <4f9> DW_AT_type : <0x249>
1031- <4fd> DW_AT_low_pc : (addr_index: 0xf): <no .debug_addr section>
1032+ <4fd> DW_AT_low_pc : (addr_index: 0xf): 0
1033 <4fe> DW_AT_high_pc : 0x61
1034 <506> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1035 <508> DW_AT_GNU_all_tail_call_sites: 1
1036 <508> DW_AT_sibling : <0x532>
1037 <2><50c>: Abbrev Number: 24 (DW_TAG_lexical_block)
1038- <50d> DW_AT_low_pc : (addr_index: 0x10): <no .debug_addr section>
1039+ <50d> DW_AT_low_pc : (addr_index: 0x10): 0
1040 <50e> DW_AT_high_pc : 0x57
1041 <3><516>: Abbrev Number: 25 (DW_TAG_variable)
1042 <517> DW_AT_name : s1
1043@@ -538,13 +538,13 @@ Contents of the .debug_info.dwo section:
1044 <54b> DW_AT_decl_line : 163
1045 <54c> DW_AT_linkage_name: _Z3t15v
1046 <554> DW_AT_type : <0x249>
1047- <558> DW_AT_low_pc : (addr_index: 0x11): <no .debug_addr section>
1048+ <558> DW_AT_low_pc : (addr_index: 0x11): 0
1049 <559> DW_AT_high_pc : 0x5d
1050 <561> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1051 <563> DW_AT_GNU_all_tail_call_sites: 1
1052 <563> DW_AT_sibling : <0x58d>
1053 <2><567>: Abbrev Number: 24 (DW_TAG_lexical_block)
1054- <568> DW_AT_low_pc : (addr_index: 0x12): <no .debug_addr section>
1055+ <568> DW_AT_low_pc : (addr_index: 0x12): 0
1056 <569> DW_AT_high_pc : 0x53
1057 <3><571>: Abbrev Number: 25 (DW_TAG_variable)
1058 <572> DW_AT_name : s1
1059@@ -576,7 +576,7 @@ Contents of the .debug_info.dwo section:
1060 <5a9> DW_AT_decl_line : 176
1061 <5aa> DW_AT_linkage_name: _Z3t16v
1062 <5b2> DW_AT_type : <0x249>
1063- <5b6> DW_AT_low_pc : (addr_index: 0x13): <no .debug_addr section>
1064+ <5b6> DW_AT_low_pc : (addr_index: 0x13): 0
1065 <5b7> DW_AT_high_pc : 0x13
1066 <5bf> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1067 <5c1> DW_AT_GNU_all_tail_call_sites: 1
1068@@ -587,13 +587,13 @@ Contents of the .debug_info.dwo section:
1069 <5c7> DW_AT_decl_line : 184
1070 <5c8> DW_AT_linkage_name: _Z3t17v
1071 <5d0> DW_AT_type : <0x249>
1072- <5d4> DW_AT_low_pc : (addr_index: 0x14): <no .debug_addr section>
1073+ <5d4> DW_AT_low_pc : (addr_index: 0x14): 0
1074 <5d5> DW_AT_high_pc : 0x5f
1075 <5dd> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1076 <5df> DW_AT_GNU_all_call_sites: 1
1077 <5df> DW_AT_sibling : <0x612>
1078 <2><5e3>: Abbrev Number: 24 (DW_TAG_lexical_block)
1079- <5e4> DW_AT_low_pc : (addr_index: 0x15): <no .debug_addr section>
1080+ <5e4> DW_AT_low_pc : (addr_index: 0x15): 0
1081 <5e5> DW_AT_high_pc : 0x59
1082 <3><5ed>: Abbrev Number: 25 (DW_TAG_variable)
1083 <5ee> DW_AT_name : c
1084@@ -602,7 +602,7 @@ Contents of the .debug_info.dwo section:
1085 <5f2> DW_AT_type : <0x53d>
1086 <5f6> DW_AT_location : 2 byte block: 91 6f (DW_OP_fbreg: -17)
1087 <3><5f9>: Abbrev Number: 24 (DW_TAG_lexical_block)
1088- <5fa> DW_AT_low_pc : (addr_index: 0x16): <no .debug_addr section>
1089+ <5fa> DW_AT_low_pc : (addr_index: 0x16): 0
1090 <5fb> DW_AT_high_pc : 0x50
1091 <4><603>: Abbrev Number: 25 (DW_TAG_variable)
1092 <604> DW_AT_name : i
1093@@ -620,13 +620,13 @@ Contents of the .debug_info.dwo section:
1094 <618> DW_AT_decl_line : 199
1095 <619> DW_AT_linkage_name: _Z3t18v
1096 <621> DW_AT_type : <0x249>
1097- <625> DW_AT_low_pc : (addr_index: 0x17): <no .debug_addr section>
1098+ <625> DW_AT_ow_pc : (addr_index: 0x17): 0
1099 <626> DW_AT_high_pc : 0x5f
1100 <62e> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1101 <630> DW_AT_GNU_all_tail_call_sites: 1
1102 <630> DW_AT_sibling : <0x67a>
1103 <2><634>: Abbrev Number: 24 (DW_TAG_lexical_block)
1104- <635> DW_AT_low_pc : (addr_index: 0x18): <no .debug_addr section>
1105+ <635> DW_AT_low_pc : (addr_index: 0x18): 0
1106 <636> DW_AT_high_pc : 0x55
1107 <3><63e>: Abbrev Number: 25 (DW_TAG_variable)
1108 <63f> DW_AT_name : c
1109@@ -635,7 +635,7 @@ Contents of the .debug_info.dwo section:
1110 <643> DW_AT_type : <0x53d>
1111 <647> DW_AT_location : 2 byte block: 91 6f (DW_OP_fbreg: -17)
1112 <3><64a>: Abbrev Number: 24 (DW_TAG_lexical_block)
1113- <64b> DW_AT_low_pc : (addr_index: 0x19): <no .debug_addr section>
1114+ <64b> DW_AT_low_pc : (addr_index: 0x19): 0
1115 <64c> DW_AT_high_pc : 0x4c
1116 <4><654>: Abbrev Number: 25 (DW_TAG_variable)
1117 <655> DW_AT_name : i
1118@@ -644,7 +644,7 @@ Contents of the .debug_info.dwo section:
1119 <659> DW_AT_type : <0x242>
1120 <65d> DW_AT_location : 2 byte block: 91 68 (DW_OP_fbreg: -24)
1121 <4><660>: Abbrev Number: 24 (DW_TAG_lexical_block)
1122- <661> DW_AT_low_pc : (addr_index: 0x1a): <no .debug_addr section>
1123+ <661> DW_AT_low_pc : (addr_index: 0x1a): 0
1124 <662> DW_AT_high_pc : 0x34
1125 <5><66a>: Abbrev Number: 25 (DW_TAG_variable)
1126 <66b> DW_AT_name : s
1127@@ -786,7 +786,7 @@ Contents of the .debug_info.dwo section:
1128 <7d3> DW_AT_decl_line : 32
1129 <7d4> DW_AT_linkage_name: _Z4t16av
1130 <7dd> DW_AT_type : <0x7c4>
1131- <7e1> DW_AT_low_pc : (addr_index: 0x0): <no .debug_addr section>
1132+ <7e1> DW_AT_low_pc : (addr_index: 0x0): 0
1133 <7e2> DW_AT_high_pc : 0x13
1134 <7ea> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1135 <7ec> DW_AT_GNU_all_tail_call_sites: 1
1136@@ -878,14 +878,14 @@ Contents of the .debug_info.dwo section:
1137 <908> DW_AT_decl_file : 1
1138 <909> DW_AT_decl_line : 70
1139 <90a> DW_AT_linkage_name: _Z4f13iv
1140- <913> DW_AT_low_pc : (addr_index: 0x0): <no .debug_addr section>
1141+ <913> DW_AT_low_pc : (addr_index: 0x0): 0
1142 <914> DW_AT_high_pc : 0x6
1143 <91c> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1144 <91e> DW_AT_GNU_all_call_sites: 1
1145 <1><91e>: Abbrev Number: 17 (DW_TAG_subprogram)
1146 <91f> DW_AT_specification: <0x8a8>
1147 <923> DW_AT_decl_file : 2
1148- <924> DW_AT_low_pc : (addr_index: 0x1): <no .debug_addr section>
1149+ <924> DW_AT_low_pc : (addr_index: 0x1): 0
1150 <925> DW_AT_high_pc : 0xf
1151 <92d> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1152 <92f> DW_AT_object_pointer: <0x937>
1153@@ -903,7 +903,7 @@ Contents of the .debug_info.dwo section:
1154 <94b> DW_AT_specification: <0x89b>
1155 <94f> DW_AT_decl_file : 2
1156 <950> DW_AT_decl_line : 36
1157- <951> DW_AT_low_pc : (addr_index: 0x2): <no .debug_addr section>
1158+ <951> DW_AT_low_pc : (addr_index: 0x2): 0
1159 <952> DW_AT_high_pc : 0x20
1160 <95a> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1161 <95c> DW_AT_object_pointer: <0x964>
1162@@ -922,7 +922,7 @@ Contents of the .debug_info.dwo section:
1163 <978> DW_AT_decl_line : 72
1164 <979> DW_AT_linkage_name: _Z3f10v
1165 <981> DW_AT_type : <0x8b7>
1166- <985> DW_AT_low_pc : (addr_index: 0x3): <no .debug_addr section>
1167+ <985> DW_AT_low_pc : (addr_index: 0x3): 0
1168 <986> DW_AT_high_pc : 0xb
1169 <98e> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1170 <990> DW_AT_GNU_all_call_sites: 1
1171@@ -933,7 +933,7 @@ Contents of the .debug_info.dwo section:
1172 <997> DW_AT_decl_line : 80
1173 <998> DW_AT_linkage_name: _Z4f11bPFivE
1174 <9a5> DW_AT_type : <0x8b7>
1175- <9a9> DW_AT_low_pc : (addr_index: 0x4): <no .debug_addr section>
1176+ <9a9> DW_AT_low_pc : (addr_index: 0x4): 0
1177 <9aa> DW_AT_high_pc : 0x14
1178 <9b2> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1179 <9b4> DW_AT_GNU_all_tail_call_sites: 1
1180@@ -954,7 +954,7 @@ Contents of the .debug_info.dwo section:
1181 <9d3> DW_AT_specification: <0x8e0>
1182 <9d7> DW_AT_decl_file : 2
1183 <9d8> DW_AT_decl_line : 88
1184- <9d9> DW_AT_low_pc : (addr_index: 0x5): <no .debug_addr section>
1185+ <9d9> DW_AT_low_pc : (addr_index: 0x5): 0
1186 <9da> DW_AT_high_pc : 0xf
1187 <9e2> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1188 <9e4> DW_AT_object_pointer: <0x9ec>
1189@@ -976,7 +976,7 @@ Contents of the .debug_info.dwo section:
1190 <a06> DW_AT_decl_line : 96
1191 <a07> DW_AT_linkage_name: _Z3f13v
1192 <a0f> DW_AT_type : <0xa1e>
1193- <a13> DW_AT_low_pc : (addr_index: 0x6): <no .debug_addr section>
1194+ <a13> DW_AT_low_pc : (addr_index: 0x6): 0
1195 <a14> DW_AT_high_pc : 0xb
1196 <a1c> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1197 <a1e> DW_AT_GNU_all_call_sites: 1
1198@@ -990,7 +990,7 @@ Contents of the .debug_info.dwo section:
1199 <a2a> DW_AT_decl_line : 104
1200 <a2b> DW_AT_linkage_name: _Z3f14v
1201 <a33> DW_AT_type : <0xa42>
1202- <a37> DW_AT_low_pc : (addr_index: 0x7): <no .debug_addr section>
1203+ <a37> DW_AT_low_pc : (addr_index: 0x7): 0
1204 <a38> DW_AT_high_pc : 0xb
1205 <a40> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1206 <a42> DW_AT_GNU_all_call_sites: 1
1207@@ -1010,7 +1010,7 @@ Contents of the .debug_info.dwo section:
1208 <a5b> DW_AT_decl_line : 112
1209 <a5c> DW_AT_linkage_name: _Z3f15v
1210 <a64> DW_AT_type : <0xa73>
1211- <a68> DW_AT_low_pc : (addr_index: 0x8): <no .debug_addr section>
1212+ <a68> DW_AT_low_pc : (addr_index: 0x8): 0
1213 <a69> DW_AT_high_pc : 0xb
1214 <a71> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1215 <a73> DW_AT_GNU_all_call_sites: 1
1216@@ -1030,7 +1030,7 @@ Contents of the .debug_info.dwo section:
1217 <a8f> DW_AT_decl_line : 127
1218 <a90> DW_AT_linkage_name: _Z3f18i
1219 <a98> DW_AT_type : <0xa42>
1220- <a9c> DW_AT_low_pc : (addr_index: 0x9): <no .debug_addr section>
1221+ <a9c> DW_AT_low_pc : (addr_index: 0x9): 0
1222 <a9d> DW_AT_high_pc : 0x44
1223 <aa5> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
1224 <aa7> DW_AT_GNU_all_call_sites: 1
diff --git a/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-2.patch b/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-2.patch
new file mode 100644
index 0000000000..0583bfcfab
--- /dev/null
+++ b/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-2.patch
@@ -0,0 +1,188 @@
1From ec41dd75c866599fc03c390c6afb5736c159c0ff Mon Sep 17 00:00:00 2001
2From: Nick Clifton <nickc@redhat.com>
3Date: Tue, 21 Jun 2022 16:37:27 +0100
4Subject: [PATCH] Binutils support for dwarf-5 (location and range lists
5 related)
6
7 * dwarf.h (struct debug_info): Add rnglists_base field.
8 * dwarf.c (read_and_display_attr_value): Read attribute DW_AT_rnglists_base.
9 (display_debug_rnglists_list): While handling DW_RLE_base_addressx,
10 DW_RLE_startx_endx, DW_RLE_startx_length items, pass the proper parameter
11 value to fetch_indexed_addr(), i.e. fetch the proper entry in .debug_addr section.
12 (display_debug_ranges): Add rnglists_base to the .debug_rnglists base address.
13 (load_separate_debug_files): Load .debug_addr section, if exists.
14
15Upstream-Status: Backport [https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=ec41dd75c866599fc03c390c6afb5736c159c0ff]
16
17Signed-off-by: Pgowda <pgowda.cve@gmail.com>
18---
19 binutils/ChangeLog | 10 +++++++++
20 binutils/dwarf.c | 53 ++++++++++++++++++++++++++++++++++------------
21 binutils/dwarf.h | 1 +
22 3 files changed, 51 insertions(+), 13 deletions(-)
23
24diff --git a/binutils/dwarf.c b/binutils/dwarf.c
25index cb2523af1f3..30b64ac68a8 100644
26--- a/binutils/dwarf.c
27+++ b/binutils/dwarf.c
28@@ -2812,7 +2812,12 @@ read_and_display_attr_value (unsigned lo
29 dwarf_vmatoa ("x", debug_info_p->cu_offset));
30 debug_info_p->loclists_base = uvalue;
31 break;
32-
33+ case DW_AT_rnglists_base:
34+ if (debug_info_p->rnglists_base)
35+ warn (_("CU @ 0x%s has multiple rnglists_base values"),
36+ dwarf_vmatoa ("x", debug_info_p->cu_offset));
37+ debug_info_p->rnglists_base = uvalue;
38+ break;
39 case DW_AT_frame_base:
40 have_frame_base = 1;
41 /* Fall through. */
42@@ -3303,6 +3308,7 @@ read_and_display_attr_value (unsigned lo
43 /* Fall through. */
44 case DW_AT_location:
45 case DW_AT_loclists_base:
46+ case DW_AT_rnglists_base:
47 case DW_AT_string_length:
48 case DW_AT_return_addr:
49 case DW_AT_data_member_location:
50@@ -3322,7 +3328,10 @@ read_and_display_attr_value (unsigned lo
51 && (form == DW_FORM_data4 || form == DW_FORM_data8))
52 || form == DW_FORM_sec_offset
53 || form == DW_FORM_loclistx)
54- printf (_(" (location list)"));
55+ {
56+ if (attribute != DW_AT_rnglists_base)
57+ printf (_(" (location list)"));
58+ }
59 /* Fall through. */
60 case DW_AT_allocated:
61 case DW_AT_associated:
62@@ -3809,6 +3818,7 @@ process_debug_info (struct dwarf_section
63 debug_information [unit].range_lists = NULL;
64 debug_information [unit].max_range_lists= 0;
65 debug_information [unit].num_range_lists = 0;
66+ debug_information [unit].rnglists_base = 0;
67 }
68
69 if (!do_loc && dwarf_start_die == 0)
70@@ -7932,9 +7942,16 @@ display_debug_rnglists_list (unsigned ch
71 unsigned char * finish,
72 unsigned int pointer_size,
73 dwarf_vma offset,
74- dwarf_vma base_address)
75+ dwarf_vma base_address,
76+ unsigned int offset_size)
77 {
78 unsigned char *next = start;
79+ unsigned int debug_addr_section_hdr_len;
80+
81+ if (offset_size == 4)
82+ debug_addr_section_hdr_len = 8;
83+ else
84+ debug_addr_section_hdr_len = 16;
85
86 while (1)
87 {
88@@ -7964,20 +7981,24 @@ display_debug_rnglists_list (unsigned ch
89 READ_ULEB (base_address, start, finish);
90 print_dwarf_vma (base_address, pointer_size);
91 printf (_("(base address index) "));
92- base_address = fetch_indexed_addr (base_address, pointer_size);
93+ base_address = fetch_indexed_addr ((base_address * pointer_size)
94+ + debug_addr_section_hdr_len, pointer_size);
95 print_dwarf_vma (base_address, pointer_size);
96 printf (_("(base address)\n"));
97 break;
98 case DW_RLE_startx_endx:
99 READ_ULEB (begin, start, finish);
100 READ_ULEB (end, start, finish);
101- begin = fetch_indexed_addr (begin, pointer_size);
102- end = fetch_indexed_addr (begin, pointer_size);
103+ begin = fetch_indexed_addr ((begin * pointer_size)
104+ + debug_addr_section_hdr_len, pointer_size);
105+ end = fetch_indexed_addr ((begin * pointer_size)
106+ + debug_addr_section_hdr_len, pointer_size);
107 break;
108 case DW_RLE_startx_length:
109 READ_ULEB (begin, start, finish);
110 READ_ULEB (length, start, finish);
111- begin = fetch_indexed_addr (begin, pointer_size);
112+ begin = fetch_indexed_addr ((begin * pointer_size)
113+ + debug_addr_section_hdr_len, pointer_size);
114 end = begin + length;
115 break;
116 case DW_RLE_offset_pair:
117@@ -8003,6 +8024,7 @@ display_debug_rnglists_list (unsigned ch
118 rlet = DW_RLE_end_of_list;
119 break;
120 }
121+
122 if (rlet == DW_RLE_end_of_list)
123 break;
124 if (rlet == DW_RLE_base_address || rlet == DW_RLE_base_addressx)
125@@ -8043,6 +8065,7 @@ display_debug_ranges (struct dwarf_secti
126 /* Initialize it due to a false compiler warning. */
127 unsigned char address_size = 0;
128 dwarf_vma last_offset = 0;
129+ unsigned int offset_size = 0;
130
131 if (bytes == 0)
132 {
133@@ -8054,10 +8077,10 @@ display_debug_ranges (struct dwarf_secti
134
135 if (is_rnglists)
136 {
137- dwarf_vma initial_length;
138- unsigned char segment_selector_size;
139- unsigned int offset_size, offset_entry_count;
140- unsigned short version;
141+ dwarf_vma initial_length;
142+ unsigned char segment_selector_size;
143+ unsigned int offset_entry_count;
144+ unsigned short version;
145
146 /* Get and check the length of the block. */
147 SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
148@@ -8230,7 +8253,8 @@ display_debug_ranges (struct dwarf_secti
149 (unsigned long) offset, i);
150 continue;
151 }
152- next = section_begin + offset;
153+
154+ next = section_begin + offset + debug_info_p->rnglists_base;
155
156 /* If multiple DWARF entities reference the same range then we will
157 have multiple entries in the `range_entries' list for the same
158@@ -8262,7 +8286,7 @@ display_debug_ranges (struct dwarf_secti
159
160 if (is_rnglists)
161 display_debug_rnglists_list
162- (start, finish, pointer_size, offset, base_address);
163+ (start, finish, pointer_size, offset, base_address, offset_size);
164 else
165 display_debug_ranges_list
166 (start, finish, pointer_size, offset, base_address);
167@@ -11911,6 +11935,9 @@ load_separate_debug_files (void * file,
168 && load_debug_section (abbrev, file)
169 && load_debug_section (info, file))
170 {
171+ /* Load the .debug_addr section, if it exists. */
172+ load_debug_section (debug_addr, file);
173+
174 free_dwo_info ();
175
176 if (process_debug_info (& debug_displays[info].section, file, abbrev,
177diff --git a/binutils/dwarf.h b/binutils/dwarf.h
178index 040e674c6ce..8a89c08e7c2 100644
179--- a/binutils/dwarf.h
180+++ b/binutils/dwarf.h
181@@ -192,6 +192,7 @@ typedef struct
182 dwarf_vma * range_lists;
183 unsigned int num_range_lists;
184 unsigned int max_range_lists;
185+ dwarf_vma rnglists_base;
186 }
187 debug_info;
188
diff --git a/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-3.patch b/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-3.patch
new file mode 100644
index 0000000000..56331b1128
--- /dev/null
+++ b/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-3.patch
@@ -0,0 +1,211 @@
1From f18acc9c4e5d18f4783f3a7d59e3ec95d7af0199 Mon Sep 17 00:00:00 2001
2From: "Kumar N, Bhuvanendra" <Kavitha.Natarajan@amd.com>
3Date: Wed, 22 Jun 2022 17:07:25 +0100
4Subject: [PATCH] Binutils support for split-dwarf and dwarf-5
5
6 * dwarf.c (fetch_indexed_string): Added new parameter
7 str_offsets_base to calculate the string offset.
8 (read_and_display_attr_value): Read DW_AT_str_offsets_base
9 attribute.
10 (process_debug_info): While allocating memory and initializing
11 debug_information, do it for do_debug_info also, if its true.
12 (load_separate_debug_files): Load .debug_str_offsets if exists.
13 * dwarf.h (struct debug_info): Add str_offsets_base field.
14
15Upstream-Status: Backport [https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=f18acc9c4e5d18f4783f3a7d59e3ec95d7af0199]
16
17Signed-off-by: Pgowda <pgowda.cve@gmail.com>
18---
19 binutils/ChangeLog | 13 ++++++++++-
20 binutils/dwarf.c | 57 ++++++++++++++++++++++++++++++++++------------
21 binutils/dwarf.h | 1 +
22 3 files changed, 56 insertions(+), 15 deletions(-)
23
24diff --git a/binutils/dwarf.c b/binutils/dwarf.c
25index f9c46cf54dd..d9a3144023c 100644
26--- a/binutils/dwarf.c
27+++ b/binutils/dwarf.c
28@@ -687,8 +687,11 @@ fetch_indirect_line_string (dwarf_vma of
29 }
30
31 static const char *
32-fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
33- dwarf_vma offset_size, bool dwo)
34+fetch_indexed_string (dwarf_vma idx,
35+ struct cu_tu_set * this_set,
36+ dwarf_vma offset_size,
37+ bool dwo,
38+ dwarf_vma str_offsets_base)
39 {
40 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
41 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
42@@ -776,7 +779,15 @@ fetch_indexed_string (dwarf_vma idx, str
43 return _("<index offset is too big>");
44 }
45
46- str_offset = byte_get (curr + index_offset, offset_size);
47+ if (str_offsets_base > 0)
48+ {
49+ if (offset_size == 8)
50+ str_offsets_base -= 16;
51+ else
52+ str_offsets_base -= 8;
53+ }
54+
55+ str_offset = byte_get (curr + index_offset + str_offsets_base, offset_size);
56 str_offset -= str_section->address;
57 if (str_offset >= str_section->size)
58 {
59@@ -2721,11 +2732,13 @@ read_and_display_attr_value (unsigned lo
60 /* We have already displayed the form name. */
61 printf (_("%c(offset: 0x%s): %s"), delimiter,
62 dwarf_vmatoa ("x", uvalue),
63- fetch_indexed_string (uvalue, this_set, offset_size, dwo));
64+ fetch_indexed_string (uvalue, this_set, offset_size, dwo,
65+ debug_info_p->str_offsets_base));
66 else
67 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
68 dwarf_vmatoa ("x", uvalue),
69- fetch_indexed_string (uvalue, this_set, offset_size, dwo));
70+ fetch_indexed_string (uvalue, this_set, offset_size, dwo,
71+ debug_info_p->str_offsets_base));
72 }
73 break;
74
75@@ -2800,7 +2813,7 @@ read_and_display_attr_value (unsigned lo
76 break;
77 }
78
79- if ((do_loc || do_debug_loc || do_debug_ranges)
80+ if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info)
81 && num_debug_info_entries == 0
82 && debug_info_p != NULL)
83 {
84@@ -2818,6 +2831,13 @@ read_and_display_attr_value (unsigned lo
85 dwarf_vmatoa ("x", debug_info_p->cu_offset));
86 debug_info_p->rnglists_base = uvalue;
87 break;
88+ case DW_AT_str_offsets_base:
89+ if (debug_info_p->str_offsets_base)
90+ warn (_("CU @ 0x%s has multiple str_offsets_base values"),
91+ dwarf_vmatoa ("x", debug_info_p->cu_offset));
92+ debug_info_p->str_offsets_base = uvalue;
93+ break;
94+
95 case DW_AT_frame_base:
96 have_frame_base = 1;
97 /* Fall through. */
98@@ -2956,7 +2976,9 @@ read_and_display_attr_value (unsigned lo
99 case DW_FORM_strx2:
100 case DW_FORM_strx3:
101 case DW_FORM_strx4:
102- add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset);
103+ add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, false,
104+ debug_info_p->str_offsets_base),
105+ cu_offset);
106 break;
107 case DW_FORM_string:
108 add_dwo_name ((const char *) orig_data, cu_offset);
109@@ -2988,7 +3010,9 @@ read_and_display_attr_value (unsigned lo
110 case DW_FORM_strx2:
111 case DW_FORM_strx3:
112 case DW_FORM_strx4:
113- add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset);
114+ add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false,
115+ debug_info_p->str_offsets_base),
116+ cu_offset);
117 break;
118 case DW_FORM_string:
119 add_dwo_dir ((const char *) orig_data, cu_offset);
120@@ -3309,6 +3333,7 @@ read_and_display_attr_value (unsigned lo
121 case DW_AT_location:
122 case DW_AT_loclists_base:
123 case DW_AT_rnglists_base:
124+ case DW_AT_str_offsets_base:
125 case DW_AT_string_length:
126 case DW_AT_return_addr:
127 case DW_AT_data_member_location:
128@@ -3329,7 +3354,8 @@ read_and_display_attr_value (unsigned lo
129 || form == DW_FORM_sec_offset
130 || form == DW_FORM_loclistx)
131 {
132- if (attribute != DW_AT_rnglists_base)
133+ if (attribute != DW_AT_rnglists_base
134+ && attribute != DW_AT_str_offsets_base)
135 printf (_(" (location list)"));
136 }
137 /* Fall through. */
138@@ -3562,7 +3588,7 @@ process_debug_info (struct dwarf_section
139 return false;
140 }
141
142- if ((do_loc || do_debug_loc || do_debug_ranges)
143+ if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info)
144 && num_debug_info_entries == 0
145 && ! do_types)
146 {
147@@ -3797,7 +3823,7 @@ process_debug_info (struct dwarf_section
148 continue;
149 }
150
151- if ((do_loc || do_debug_loc || do_debug_ranges)
152+ if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info)
153 && num_debug_info_entries == 0
154 && alloc_num_debug_info_entries > unit
155 && ! do_types)
156@@ -3819,6 +3845,7 @@ process_debug_info (struct dwarf_section
157 debug_information [unit].max_range_lists= 0;
158 debug_information [unit].num_range_lists = 0;
159 debug_information [unit].rnglists_base = 0;
160+ debug_information [unit].str_offsets_base = 0;
161 }
162
163 if (!do_loc && dwarf_start_die == 0)
164@@ -4089,7 +4116,7 @@ process_debug_info (struct dwarf_section
165
166 /* Set num_debug_info_entries here so that it can be used to check if
167 we need to process .debug_loc and .debug_ranges sections. */
168- if ((do_loc || do_debug_loc || do_debug_ranges)
169+ if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info)
170 && num_debug_info_entries == 0
171 && ! do_types)
172 {
173@@ -6237,7 +6264,7 @@ display_debug_macro (struct dwarf_sectio
174 READ_ULEB (lineno, curr, end);
175 READ_ULEB (offset, curr, end);
176 string = (const unsigned char *)
177- fetch_indexed_string (offset, NULL, offset_size, false);
178+ fetch_indexed_string (offset, NULL, offset_size, false, 0);
179 if (op == DW_MACRO_define_strx)
180 printf (" DW_MACRO_define_strx ");
181 else
182@@ -7851,7 +7878,7 @@ display_debug_str_offsets (struct dwarf_
183 SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, entries_end);
184 if (dwo)
185 string = (const unsigned char *)
186- fetch_indexed_string (idx, NULL, entry_length, dwo);
187+ fetch_indexed_string (idx, NULL, entry_length, dwo, 0);
188 else
189 string = fetch_indirect_string (offset);
190
191@@ -11937,6 +11964,8 @@ load_separate_debug_files (void * file,
192 {
193 /* Load the .debug_addr section, if it exists. */
194 load_debug_section (debug_addr, file);
195+ /* Load the .debug_str_offsets section, if it exists. */
196+ load_debug_section (str_index, file);
197
198 free_dwo_info ();
199
200diff --git a/binutils/dwarf.h b/binutils/dwarf.h
201index 8a89c08e7c2..adbf20f9a28 100644
202--- a/binutils/dwarf.h
203+++ b/binutils/dwarf.h
204@@ -193,6 +193,7 @@ typedef struct
205 unsigned int num_range_lists;
206 unsigned int max_range_lists;
207 dwarf_vma rnglists_base;
208+ dwarf_vma str_offsets_base;
209 }
210 debug_info;
211
diff --git a/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-4.patch b/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-4.patch
new file mode 100644
index 0000000000..e59b19c184
--- /dev/null
+++ b/meta/recipes-devtools/binutils/binutils/0017-CVE-2022-38127-4.patch
@@ -0,0 +1,43 @@
1From e98e7d9a70dcc987bff0e925f20b78cd4a2979ed Mon Sep 17 00:00:00 2001
2From: Nick Clifton <nickc@redhat.com>
3Date: Mon, 27 Jun 2022 13:30:35 +0100
4Subject: [PATCH] Fix NULL pointer indirection when parsing corrupt DWARF data.
5
6 PR 29290
7 * dwarf.c (read_and_display_attr_value): Check that debug_info_p
8 is set before dereferencing it.
9
10Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e98e7d9a70dcc987bff0e925f20b78cd4a2979ed]
11
12Signed-off-by: Pgowda <pgowda.cve@gmail.com>
13---
14 binutils/dwarf.c | 11 +++++------
15
16diff --git a/binutils/dwarf.c b/binutils/dwarf.c
17index bcabb61b871..37b477b886d 100644
18--- a/binutils/dwarf.c
19+++ b/binutils/dwarf.c
20@@ -2727,18 +2727,17 @@ read_and_display_attr_value (unsigned lo
21 {
22 const char *suffix = strrchr (section->name, '.');
23 bool dwo = suffix && strcmp (suffix, ".dwo") == 0;
24+ const char *strng;
25
26+ strng = fetch_indexed_string (uvalue, this_set, offset_size, dwo,
27+ debug_info_p ? debug_info_p->str_offsets_base : 0);
28 if (do_wide)
29 /* We have already displayed the form name. */
30 printf (_("%c(offset: 0x%s): %s"), delimiter,
31- dwarf_vmatoa ("x", uvalue),
32- fetch_indexed_string (uvalue, this_set, offset_size, dwo,
33- debug_info_p->str_offsets_base));
34+ dwarf_vmatoa ("x", uvalue), strng);
35 else
36 printf (_("%c(indexed string: 0x%s): %s"), delimiter,
37- dwarf_vmatoa ("x", uvalue),
38- fetch_indexed_string (uvalue, this_set, offset_size, dwo,
39- debug_info_p->str_offsets_base));
40+ dwarf_vmatoa ("x", uvalue), strng);
41 }
42 break;
43