From patchwork Tue Jan 24 13:42:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Willgerodt X-Patchwork-Id: 47709 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2154078wrn; Tue, 24 Jan 2023 05:42:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXud5J5B6rQDgjvKkqOOTaTIaOBnpcwwl0MugC3MfpFChDqeuRWwnKAqc7AsHEN1ahgg9ofq X-Received: by 2002:a17:907:7da0:b0:871:89ac:decb with SMTP id oz32-20020a1709077da000b0087189acdecbmr40105563ejc.76.1674567777082; Tue, 24 Jan 2023 05:42:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674567777; cv=none; d=google.com; s=arc-20160816; b=Caid5Z9HnawZ7XJmRboGusQX6hfeiath3nyXbBTOTLutjCt+dgIcYXeL+/sL0erTdI c4jn21sqdtKkWAGD4h04gIsXg1VwoodWr5DZS2HUOYvIfLaK6WGMW7KvaN77L7TehNX/ wIC/MPkpjpkEjDuGGzlFWhkIoHrL0h1w8uwj4cTJ+Js9fmu7aUAJAeMRkhabUd2hu7Dv +WMGFVh5pRgQ79QD97+ZKZ4dsVb9uyJ5F2cO9tKPQbcovO/ILW3LKGtYDw5nczWMZ6Qm FyChp1cEQ8fMLyJQStk+yXSAZbhF4NKmsNYKnVcxwxgsTtHRULnihBoI2bmCX47A2LaV 0o4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=aUcgeQD9LABfRcCKX32NZw6ldN2PwU1z8nY5nblE+RA=; b=WdReYvEsiOKmrMgChUvgmMUf4i2MAQ2qVOC3C0CkZ0qwkrF4/U6TCqdMKqztyEuMIr pOdP92X+gYfpmaFGO13Ynv80fBT7v/bLJTLFyQYccYA1Y9z0KLVRM12dKb9cHHhoe4Ng bdvIia99X6ArC2wQWE62Z+n3gRzxqqC+H37lXEN+jMoxQBpAS3BOZX1ouaAW4TiyW2b8 tOfmwOrFjjAzjfpSuoiNjR9ROBsZC9KMZN9EAbCQTNG/HjqHczUnLOIDL4Fo4/yX8uNn nllHFSuuh8fIQlMSYDBo10JIbrw6CrGok6equtRkYRMOtlDA96VOpw5Dn/09v4vrkLFg 4G6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=WmXDi0cC; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bp24-20020a170907919800b0086fcc2f95c1si2371154ejb.854.2023.01.24.05.42.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 05:42:57 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=WmXDi0cC; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5165D3858423 for ; Tue, 24 Jan 2023 13:42:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5165D3858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674567775; bh=aUcgeQD9LABfRcCKX32NZw6ldN2PwU1z8nY5nblE+RA=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=WmXDi0cCM3Kc7kjU/lbZvVsTbFUc4I8UekbVNH02EYPvDPI5yvu3UBKngQJu37Bsu 74gi15DHhHa0IjOkzOJBRj2PorH+nsHVf2C4Epmqx1zg8ThGWsGtCWPsLKLIhQzcAV 640ddxiLbA2GmjasN8V4aIn2PslFpD5nojwDr5Fw= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 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 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 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Felix Willgerodt via Binutils From: Felix Willgerodt Reply-To: Felix Willgerodt Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755911581360078609?= X-GMAIL-MSGID: =?utf-8?q?1755911581360078609?= 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);