From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by sourceware.org (Postfix) with ESMTPS id 871A73858D28; Tue, 24 Jan 2023 13:42:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 871A73858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674567766; x=1706103766; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=hiO+UV+BtoBdFpmd43nrdiVGO3QI68KgLKE4jC5FJbg=; b=I9GdWSnGxPp6DQs3ApPpPlrqvAimKQ9riT3/PT9ZmChXh0Z1YSs6gjZg TKZJnfC+HfSHxLLmmfpTZnO2MCEjwa9iMPX3UXo/nmZWo4+LaxolAkCIH 29TgexFt6oEXMmYUNDkOiLjRUBDf6Cgyg4d7hTDLUTQbYWEYWNg/2MARn Z46Etf4JSSJLEO8h9KIiuJfo0yYCQU8bvwYUyhrjkE4i54TdkcdYMIs2m VjE57rorTUeb9vA2epuMmQn5D+G9CSRDExKke0QWaZ4PWcX3qGFcibcA5 DmeE7xo0dxfiGQoOkDzhAIKLcOdf593boV9oexPw6qFxp1q5rJ4tEu2Fd g==; X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="309868735" X-IronPort-AV: E=Sophos;i="5.97,242,1669104000"; d="scan'208";a="309868735" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2023 05:42:45 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="730689680" X-IronPort-AV: E=Sophos;i="5.97,242,1669104000"; d="scan'208";a="730689680" Received: from mulvlfelix.iul.intel.com (HELO localhost) ([172.28.48.92]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2023 05:42:43 -0800 From: Felix Willgerodt To: binutils@sourceware.org Cc: gdb-patches@sourceware.org, Felix Willgerodt , Christoph Rotte 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 Message-Id: <20230124134202.2452845-1-felix.willgerodt@intel.com> X-Mailer: git-send-email 2.34.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 bfd/ChangeLog: 2023-01-24 Felix Willgerodt * 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 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