summaryrefslogtreecommitdiffstats
path: root/libdw/dwarf_begin_elf.c
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2021-08-26 19:05:45 +0200
committerMark Wielaard <mark@klomp.org>2021-09-08 22:24:22 +0200
commit7d3ce8f4d9ff057c376d2f77905a4e8b95e61e56 (patch)
treebc05feba747ee79fe7fcca3d62bd8dd941f9f9ca /libdw/dwarf_begin_elf.c
parenttests: Make sure to wait for initial scan and groom cycle earlier (diff)
downloadelfutils-fake_cu_elf_addr_size.tar.gz
elfutils-fake_cu_elf_addr_size.tar.bz2
elfutils-fake_cu_elf_addr_size.tar.xz
libdw: set address size, offset size and version on fake CUsfake_cu_elf_addr_size
There are three "fake CUs" that are associated with .debug_loc, .debug_loclist and .debug_addr. These fake CUs are used for "fake attributes" to provide values that are stored in these sections instead of in the .debug_info section. These fake CUs didn't have the address size, offset size and DWARF version set. This meant that values that depended on those properties might not be interpreted correctly. One example was the value associated with a DW_OP_addrx (which comes from the .debug_addr section). Add a testcase using varlocs to test that addresses can correctly be retrieved for gcc/clang, DWARF4/5 and 32/64 bits objects. https://sourceware.org/bugzilla/show_bug.cgi?id=28220 Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdw/dwarf_begin_elf.c')
-rw-r--r--libdw/dwarf_begin_elf.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index 9e944b86..a368feb8 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -224,6 +224,23 @@ valid_p (Dwarf *result)
224 result = NULL; 224 result = NULL;
225 } 225 }
226 226
227 /* We are setting up some "fake" CUs, which need an address size.
228 Check the ELF class to come up with something reasonable. */
229 int elf_addr_size = 8;
230 if (result != NULL)
231 {
232 GElf_Ehdr ehdr;
233 if (gelf_getehdr (result->elf, &ehdr) == NULL)
234 {
235 Dwarf_Sig8_Hash_free (&result->sig8_hash);
236 __libdw_seterrno (DWARF_E_INVALID_ELF);
237 free (result);
238 result = NULL;
239 }
240 else if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
241 elf_addr_size = 4;
242 }
243
227 /* For dwarf_location_attr () we need a "fake" CU to indicate 244 /* For dwarf_location_attr () we need a "fake" CU to indicate
228 where the "fake" attribute data comes from. This is a block 245 where the "fake" attribute data comes from. This is a block
229 inside the .debug_loc or .debug_loclists section. */ 246 inside the .debug_loc or .debug_loclists section. */
@@ -247,8 +264,9 @@ valid_p (Dwarf *result)
247 = (result->sectiondata[IDX_debug_loc]->d_buf 264 = (result->sectiondata[IDX_debug_loc]->d_buf
248 + result->sectiondata[IDX_debug_loc]->d_size); 265 + result->sectiondata[IDX_debug_loc]->d_size);
249 result->fake_loc_cu->locs = NULL; 266 result->fake_loc_cu->locs = NULL;
250 result->fake_loc_cu->address_size = 0; 267 result->fake_loc_cu->address_size = elf_addr_size;
251 result->fake_loc_cu->version = 0; 268 result->fake_loc_cu->offset_size = 4;
269 result->fake_loc_cu->version = 4;
252 result->fake_loc_cu->split = NULL; 270 result->fake_loc_cu->split = NULL;
253 } 271 }
254 } 272 }
@@ -274,8 +292,9 @@ valid_p (Dwarf *result)
274 = (result->sectiondata[IDX_debug_loclists]->d_buf 292 = (result->sectiondata[IDX_debug_loclists]->d_buf
275 + result->sectiondata[IDX_debug_loclists]->d_size); 293 + result->sectiondata[IDX_debug_loclists]->d_size);
276 result->fake_loclists_cu->locs = NULL; 294 result->fake_loclists_cu->locs = NULL;
277 result->fake_loclists_cu->address_size = 0; 295 result->fake_loclists_cu->address_size = elf_addr_size;
278 result->fake_loclists_cu->version = 0; 296 result->fake_loclists_cu->offset_size = 4;
297 result->fake_loclists_cu->version = 5;
279 result->fake_loclists_cu->split = NULL; 298 result->fake_loclists_cu->split = NULL;
280 } 299 }
281 } 300 }
@@ -306,8 +325,9 @@ valid_p (Dwarf *result)
306 = (result->sectiondata[IDX_debug_addr]->d_buf 325 = (result->sectiondata[IDX_debug_addr]->d_buf
307 + result->sectiondata[IDX_debug_addr]->d_size); 326 + result->sectiondata[IDX_debug_addr]->d_size);
308 result->fake_addr_cu->locs = NULL; 327 result->fake_addr_cu->locs = NULL;
309 result->fake_addr_cu->address_size = 0; 328 result->fake_addr_cu->address_size = elf_addr_size;
310 result->fake_addr_cu->version = 0; 329 result->fake_addr_cu->offset_size = 4;
330 result->fake_addr_cu->version = 5;
311 result->fake_addr_cu->split = NULL; 331 result->fake_addr_cu->split = NULL;
312 } 332 }
313 } 333 }