summaryrefslogtreecommitdiff
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-12 21:37:31 +0200
commit52b0d9caf5575a62322c9fbe920b69444dd09162 (patch)
treeafe71be86cef94e5774edfb274b2a6ec2bce488e /libdw/dwarf_begin_elf.c
parentbbf0dc0162e82770f296b2ecda77a2b5bd6f7405 (diff)
downloadelfutils-52b0d9caf5575a62322c9fbe920b69444dd09162.tar.gz
libdw: set address size, offset size and version on fake CUs
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 7bde61b3..53b44cd4 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -224,6 +224,23 @@ valid_p (Dwarf *result)
result = NULL;
}
+ /* We are setting up some "fake" CUs, which need an address size.
+ Check the ELF class to come up with something reasonable. */
+ int elf_addr_size = 8;
+ if (result != NULL)
+ {
+ GElf_Ehdr ehdr;
+ if (gelf_getehdr (result->elf, &ehdr) == NULL)
+ {
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_INVALID_ELF);
+ free (result);
+ result = NULL;
+ }
+ else if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
+ elf_addr_size = 4;
+ }
+
/* For dwarf_location_attr () we need a "fake" CU to indicate
where the "fake" attribute data comes from. This is a block
inside the .debug_loc or .debug_loclists section. */
@@ -247,8 +264,9 @@ valid_p (Dwarf *result)
= (result->sectiondata[IDX_debug_loc]->d_buf
+ result->sectiondata[IDX_debug_loc]->d_size);
result->fake_loc_cu->locs = NULL;
- result->fake_loc_cu->address_size = 0;
- result->fake_loc_cu->version = 0;
+ result->fake_loc_cu->address_size = elf_addr_size;
+ result->fake_loc_cu->offset_size = 4;
+ result->fake_loc_cu->version = 4;
result->fake_loc_cu->split = NULL;
}
}
@@ -274,8 +292,9 @@ valid_p (Dwarf *result)
= (result->sectiondata[IDX_debug_loclists]->d_buf
+ result->sectiondata[IDX_debug_loclists]->d_size);
result->fake_loclists_cu->locs = NULL;
- result->fake_loclists_cu->address_size = 0;
- result->fake_loclists_cu->version = 0;
+ result->fake_loclists_cu->address_size = elf_addr_size;
+ result->fake_loclists_cu->offset_size = 4;
+ result->fake_loclists_cu->version = 5;
result->fake_loclists_cu->split = NULL;
}
}
@@ -306,8 +325,9 @@ valid_p (Dwarf *result)
= (result->sectiondata[IDX_debug_addr]->d_buf
+ result->sectiondata[IDX_debug_addr]->d_size);
result->fake_addr_cu->locs = NULL;
- result->fake_addr_cu->address_size = 0;
- result->fake_addr_cu->version = 0;
+ result->fake_addr_cu->address_size = elf_addr_size;
+ result->fake_addr_cu->offset_size = 4;
+ result->fake_addr_cu->version = 5;
result->fake_addr_cu->split = NULL;
}
}