[PATCH 1/1] bfd, gdb: fix missing "Core was generated by" when loading a x32 corefile.
Felix Willgerodt
felix.willgerodt@intel.com
Tue Jan 24 13:42:02 GMT 2023
When loading a corefile that was generated using 'gcore', gdb usually
displays "Core was generated by" followed by the path of the
executable. If the binary, however, was compiled with '-mx32', the
'Elf_Internal_Note' (bfd/elf64-x86-64.c:elf_x86_64_grok_psinfo)
contains a 4 byte offset compared to the default 'struct elf_prpsinfo'
on Linux/x32:
note of 124 byte (initial default case on Linux/x32):
| pid | program | command
offset | 12 | 28 | 44
note of 128 byte (Linux/x32):
| pid | program | command
offset | 12 | 32 | 48
Initially, the 'Elf_Internal_Note' had a size of 124 bytes for x32
and for 32 bit.
Commit a2f63b2 ("ELF/BFD,GDB: Handle both variants of the 32-bit Linux
core PRPSINFO note") changed that by differentiating between 2 and 4
bytes for 'uid' and 'gid' and not handling the resulting offset in the
function 'elf_x86_64_grok_psinfo'.
The reason for this are the different sizes for '__kernel_uid_t'
and '__kernel_gid_t' (16 vs 32).
'bfd/elf.c:elfcore_write_linux_prpsinfo32' differentiates between
'elf_external_linux_prpsinfo32_ugid16' and
'elf_external_linux_prpsinfo32_ugid32'.
Consequently, the function 'elf_x86_64_grok_psinfo' cannot find the
respective information and does not assign the path of the executable to
the current 'bfd' object. The function directly returns with the
respective path string still being null.
The proposed fix circumvents this by adding a separate case for
128 byte notes with the respective offsets.
'gdb.base/gcore-relro.exp' already tests the expected behaviour;
the fail before this patch can be reproduced using
'--target_board=unix/-mx32'.
Co-authored-by: Christoph Rotte <christoph.rotte@intel.com>
bfd/ChangeLog:
2023-01-24 Felix Willgerodt <felix.willgerodt@intel.com>
* elf64-x86-64.c (elf_x86_64_grok_psinfo): Check for
elf_external_linux_prpsinfo32_ugid32.
---
bfd/elf64-x86-64.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 914f82d0151..30789a9da8c 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -389,7 +389,8 @@ elf_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
default:
return false;
- case 124: /* sizeof(struct elf_prpsinfo) on Linux/x32 */
+ case 124:
+ /* sizeof (struct elf_external_linux_prpsinfo32_ugid16). */
elf_tdata (abfd)->core->pid
= bfd_get_32 (abfd, note->descdata + 12);
elf_tdata (abfd)->core->program
@@ -398,6 +399,16 @@ elf_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
= _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
break;
+ case 128:
+ /* sizeof (struct elf_external_linux_prpsinfo32_ugid32). */
+ elf_tdata (abfd)->core->pid
+ = bfd_get_32 (abfd, note->descdata + 12);
+ elf_tdata (abfd)->core->program
+ = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
+ elf_tdata (abfd)->core->command
+ = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
+ break;
+
case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */
elf_tdata (abfd)->core->pid
= bfd_get_32 (abfd, note->descdata + 24);
--
2.34.3
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
More information about the Binutils
mailing list