From patchwork Wed Mar 1 06:22:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyi Liu X-Patchwork-Id: 13155615 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D97CC64EC7 for ; Wed, 1 Mar 2023 06:23:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229493AbjCAGXm (ORCPT ); Wed, 1 Mar 2023 01:23:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjCAGXl (ORCPT ); Wed, 1 Mar 2023 01:23:41 -0500 Received: from AUS01-ME3-obe.outbound.protection.outlook.com (mail-me3aus01olkn2150.outbound.protection.outlook.com [40.92.63.150]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80044EB7B; Tue, 28 Feb 2023 22:23:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CN8NtEZSp0JKqxR7ZfucynchWuqL0oRmQKRIA0eHalIsPgGw1cCIq+1noP8FqPZRvWEpd5NK2IgoWrnLsiNN8nd2IwC5Qkypr6i4BQYhyT0fdTxMpYkgnbPsc1OeHExa+gSP6c4HPKt0CqwEZSLOLAfEMi/lQoRAKAFtPk071ZiLpBaQbkMmFZ3e5edmVEgqcyzCwfKLV4hz0AVJo6KI/rl8kENTqZnHsZZDuV+KR11kf1U8gWrise1dioqtXVG/UapWGzUV/4VFFZi9Rs6VhwqW1mptooIzSu2SM6tHb1qMs5MZCMxWqXN0v4PB1tMPmHxXIHQLUn1o6hYOc4HzFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iC3tAVvI/Z+WmYJP+we926ax8u1Ty2KNZwp4XoYmORU=; b=dGClSGGX04aSMM4OcYJk8kPXKO4qwXYle0VS1XVMm8oVrviRSNdRV7Zr4rUfOhgJ+5j3TDCbQdwwi6yPZMqKzG8CeHdqKOrIU0cUbnSO9jM0HjegTSqlxn7pH/Bp4IyCcv+xsGVNiaHsxBWSTvg5R0tL1xjeDx3UVFbKL9sSBBFq4FYduSWC6uXOrVfKTIrbGtNCCKl/5afTAk7leJJjXH0RDLIjJhxngYD54Imhp5dACgcwV662DgrSHE0GFaPCbY8BR0POu/FoYrCfdw+S9HwD5JTYwBXYAgcu/GbzTe+pgyF5xRoSCIkl8uosTQsxo4hCKg+IL9M6YT2zfYbBrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iC3tAVvI/Z+WmYJP+we926ax8u1Ty2KNZwp4XoYmORU=; b=TbgFQRIVq91fCiKaWtvUSndtk5dQhCaHB4GSkjpcaASc4MBbyWFHWjpqL87rcc5t65TxUS7U6HHGp4g6mAm+lxzCVyPB3xoF7NfdLJJ0t4n08t/umKJE/nHt0gTYnNJy8pq3KQYzjqRMqZ0Fm0Gyufq1vQnllv3S7Clf/H3E7LgRdcE5hTcIpfAZzy3JNJXDYNFcqhhZtsImyCgtpLc7sSLaFv9ylu5wHvyHzS9sx547ZzaMEYMSzNg9556OqBfD2PeTSegO0IrTQsYxSICJRBWxrE+O5pebsPa0LikpobuEdQMNKkJ8rxBhgof4o2sEMov2rC5EmIYJAMeCiOOKCA== Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) by SYBP282MB2253.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:99::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 06:23:35 +0000 Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::637e:ae7f:4307:e5ab]) by SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::637e:ae7f:4307:e5ab%9]) with mapi id 15.20.6156.017; Wed, 1 Mar 2023 06:23:35 +0000 From: Tianyi Liu To: arnd@arndb.de Cc: hjl.tools@gmail.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Tianyi Liu Subject: [PATCH] Discard .note.gnu.property in vmlinux Date: Wed, 1 Mar 2023 14:22:32 +0800 Message-ID: X-Mailer: git-send-email 2.39.2 X-TMN: [9WsfBkK33D7GDnVh1VWQAspsnhWr/um8ZmmcqDRnlIE3zu6sTDEp/A==] X-ClientProxiedBy: SG2PR01CA0171.apcprd01.prod.exchangelabs.com (2603:1096:4:28::27) To SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) X-Microsoft-Original-Message-ID: <20230301062232.2708155-1-i.pear@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY4P282MB1084:EE_|SYBP282MB2253:EE_ X-MS-Office365-Filtering-Correlation-Id: 46010a48-f4e7-413c-5275-08db1a1d7c9c X-MS-Exchange-SLBlob-MailProps: dx7TrgQSB6dAG8fEwqdvu3P4kJ8WfkSHJ/VyhTx8G9lQ63vz0cpjlF0PTPFU90JWrhUDsZh2UrTbxav7ZEEqVMwz6tVouVW6S0jVrctywqGkGCm394seECzmhJO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Pq16caVC6deWew9HDMicbyk7fbDGA1VnC3weSO6wLxJP4oaIcTw0BALnRRKQaCt71DJomdIU+kHb1r/3rr57KSA04Bf2Mx07LuywPH9biUCDqGZ96Gb3tCmm8EXES76pggOOq48SMsvY2SLP7rJrAZmKwGU0N4lWNTyp475CDYAdST0WTU/IFggHom0lLg3/1KXqMggxveG6/Qs528kblzsW/mI8Ahe8WSac1BxvGNRJRpCP4LhGwrxvnVibHrZ0vpfepqYpnkO1g/EIO6NKzdmMssIaAjfRbYFqXyL1WpLYU+89mKnu03QgslzK3fZf8pHixHjzToxQNoWjwjljrFZzVOlrUVFhnwVUjkMIDQuiTvDz5mRxVwEX2Lt5LxTIjyqeHkYeGrYlA4BEkEvqMchOR3PFlP2MgBPb/qOLmhQljzRTXTYZkR1MgUNVuwrrtJnpY1llPFFEpRkYCIOW72lQdr/5049EpJ6MvG9qlzvv8adls1byqiL0JsJEL0bAJ34L4FkfIB4ejWasF2OEI1TnmT8FKmvRWqdN9Br08W8yNRFa2rAY2ssXryVDOLBEz954UQqDAW+6VPEwfg89m+kasypEKYKICJTRQD5GQWcis= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 46010a48-f4e7-413c-5275-08db1a1d7c9c X-MS-Exchange-CrossTenant-AuthSource: SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 06:23:35.1455 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SYBP282MB2253 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org When the kernel image is finally linked, all the notes are packed into a single .notes section, but these notes may have different alignments. binutils above 2.32 adds a ".note.gnu.property" section to the compiled output, which is 4-byte aligned on 32-bit, but 8-byte aligned on 64-bit. At present, the notes generated by both the ELFNOTE macro and the VDSO linker script are 4-byte aligned. So in a 64-bit kernel, packing segments with different alignments will cause LibElf and tools like readelf to crush or to read wrong values [1][2]. This patch discards ".note.gnu.property" from vmlinux. Note that H.J. Lu has submitted a similar patch in the past[3], but it was not merged. [1] https://lore.kernel.org/bpf/57830c30-cd77-40cf-9cd1-3bb608aa602e@app.fastmail.com/ [2] https://lore.kernel.org/linux-arm-kernel/20210428172847.GC4022@arm.com/ [3] https://lore.kernel.org/lkml/20180924201459.35923-1-hjl.tools@gmail.com/ Signed-off-by: Tianyi Liu --- include/asm-generic/vmlinux.lds.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index d1f57e4868ed..6db0f664c7d6 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -891,9 +891,13 @@ /* * Discard .note.GNU-stack, which is emitted as PROGBITS by the compiler. * Otherwise, the type of .notes section would become PROGBITS instead of NOTES. + * + * Discard .note.gnu.property, which is 8-byte aligned and emitted by the + * compiler. Otherwise, the .notes section will be 8-byte aligned and other + * notes cannot be read. */ #define NOTES \ - /DISCARD/ : { *(.note.GNU-stack) } \ + /DISCARD/ : { *(.note.GNU-stack) *(.note.gnu.property) } \ .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \ BOUNDED_SECTION_BY(.note.*, _notes) \ } NOTES_HEADERS \