public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Felix Willgerodt <felix.willgerodt@intel.com>
To: binutils@sourceware.org
Cc: gdb-patches@sourceware.org,
	Felix Willgerodt <felix.willgerodt@intel.com>,
	Christoph Rotte <christoph.rotte@intel.com>
Subject: [PATCH 1/1] bfd, gdb: fix missing "Core was generated by" when loading a x32 corefile.
Date: Tue, 24 Jan 2023 14:42:02 +0100	[thread overview]
Message-ID: <20230124134202.2452845-1-felix.willgerodt@intel.com> (raw)

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


             reply	other threads:[~2023-01-24 13:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24 13:42 Felix Willgerodt [this message]
2023-02-20 12:50 ` [PING] " Willgerodt, Felix
2023-02-27 13:05   ` Nick Clifton

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=20230124134202.2452845-1-felix.willgerodt@intel.com \
    --to=felix.willgerodt@intel.com \
    --cc=binutils@sourceware.org \
    --cc=christoph.rotte@intel.com \
    --cc=gdb-patches@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).