From: "mark at klomp dot org" <sourceware-bugzilla@sourceware.org>
To: elfutils-devel@sourceware.org
Subject: [Bug libdw/28220] dwarf_location_attr returns high-bit junk from .debug_addr when fetching 32-bit addresses
Date: Thu, 26 Aug 2021 17:12:02 +0000 [thread overview]
Message-ID: <bug-28220-10460-sVQi61Cr0u@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-28220-10460@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=28220
Mark Wielaard <mark at klomp dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
CC| |mark at klomp dot org
Last reconfirmed| |2021-08-26
Ever confirmed|0 |1
--- Comment #2 from Mark Wielaard <mark at klomp dot org> ---
That was an interesting bug. The issue is the use of DW_OP_addrx which creates
a fake attribute of DW_FORM_addr pointing to the actual address. This fake
attribute also has a fake CU. We didn't set the correct address size on this
fake CU.
The following patch fixes it:
commit d18228697f750e651bf0bdf19abdaab0a4217008
Author: Mark Wielaard <mark@klomp.org>
Date: Thu Aug 26 19:05:45 2021 +0200
PR28220
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)
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;
}
}
Also on
https://code.wildebeest.org/git/user/mjw/elfutils/commit/?h=fake_cu_elf_addr_size
Thanks for the testcases I'll try to incorporate them into the testsuite.
--
You are receiving this mail because:
You are on the CC list for the bug.
next prev parent reply other threads:[~2021-08-26 17:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-11 12:00 [Bug libdw/28220] New: " gprocida at google dot com
2021-08-11 12:01 ` [Bug libdw/28220] " gprocida at google dot com
2021-08-11 12:06 ` gprocida at google dot com
2021-08-26 17:12 ` mark at klomp dot org [this message]
2021-08-26 22:47 ` gprocida at google dot com
2021-09-08 16:01 ` mark at klomp dot org
2021-09-08 20:15 ` mark at klomp dot org
2021-09-12 19:45 ` mark at klomp dot org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-28220-10460-sVQi61Cr0u@http.sourceware.org/bugzilla/ \
--to=sourceware-bugzilla@sourceware.org \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).