From: Mark Wielaard Date: Thu, 5 Feb 2026 18:58:05 +0000 (+0100) Subject: readelf: Handle CUs that share an addr_base or str_offsets_base X-Git-Tag: elfutils-0.195~58 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=15f0b72c31dbcd73594f81f32e456afeb5236933;p=thirdparty%2Felfutils.git readelf: Handle CUs that share an addr_base or str_offsets_base readelf assumed each .debug_addr and .debug_str_offsets was associated with precisely one CU DIE. But CU DIEs can have the same DW_AT_addr_base or DW_AT_str_offsets_base. Change the code to find the first CU associated with the offset. * src/readelf.c (print_debug_addr_section): Skip CUs that have an addr_base already handled. (print_debug_str_offsets_section): Likewise for str_offsets_base. Signed-off-by: Mark Wielaard --- diff --git a/src/readelf.c b/src/readelf.c index 5db86f0a..3eab60c1 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -6053,7 +6053,13 @@ print_debug_addr_section (Dwfl_Module *dwflmod __attribute__ ((unused)), fprintf (out, "Table at offset %" PRIx64 " ", off); - struct listptr *listptr = get_listptr (&known_addrbases, idx++); + /* Find the first CU that could plausibly be associated with + this address base offset. Skip CUs that point their addr_base + before this table. */ + struct listptr *listptr = get_listptr (&known_addrbases, idx); + while (listptr != NULL && listptr->offset < off) + listptr = get_listptr (&known_addrbases, ++idx); + const unsigned char *next_unitp; uint64_t unit_length; @@ -6087,7 +6093,7 @@ print_debug_addr_section (Dwfl_Module *dwflmod __attribute__ ((unused)), version = 4; /* The addresses start here, but where do they end? */ - listptr = get_listptr (&known_addrbases, idx); + listptr = get_listptr (&known_addrbases, idx + 1); if (listptr == NULL) next_unitp = readendp; else if (listptr->cu->version < 5) @@ -11402,7 +11408,13 @@ print_debug_str_offsets_section (Dwfl_Module *dwflmod __attribute__ ((unused)), fprintf (out, "Table at offset %" PRIx64 " ", off); - struct listptr *listptr = get_listptr (&known_stroffbases, idx++); + /* Find the first CU that could plausibly be associated with + this string offsets index. Skip CUs that point + str_offsets_base before this table. */ + struct listptr *listptr = get_listptr (&known_stroffbases, idx); + while (listptr != NULL && listptr->offset < off) + listptr = get_listptr (&known_stroffbases, ++idx); + const unsigned char *next_unitp = readendp; uint8_t offset_size; bool has_header;