Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp579755lqp; Wed, 12 Jun 2024 09:51:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWdFY2JE7Fc/Djd0uM+4iIEqtQBrBFhCwBYVifb8MHRoeeBqnoIN+6NjtljJZxm2mOtkdUJzACcCNUMEIJhvBhpKAGyX1VaaLaaGahaQA== X-Google-Smtp-Source: AGHT+IEheHLOPr3HnJzUA9VC6PiriqDi8nGHrs+98bo0r6cgRoR7XOI2HUUuQ/PFlCgvbliLIcGS X-Received: by 2002:aa7:84d4:0:b0:705:c9f5:a808 with SMTP id d2e1a72fcca58-705c9f5aab9mr9718b3a.2.1718211094947; Wed, 12 Jun 2024 09:51:34 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e9f7c575b4si7350874a12.716.2024.06.12.09.51.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 09:51:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211916-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@garyguo.net header.s=selector1 header.b=auijZpC8; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-211916-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211916-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 14DD9B2C9F6 for ; Wed, 12 Jun 2024 16:27:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B410183066; Wed, 12 Jun 2024 16:26:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b="auijZpC8" Received: from GBR01-LO4-obe.outbound.protection.outlook.com (mail-lo4gbr01on2093.outbound.protection.outlook.com [40.107.122.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A21CF1822ED; Wed, 12 Jun 2024 16:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.122.93 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718209589; cv=fail; b=fgsbb4i64hZGJUpkekp24V3lOnMMU/o9a+Ew6LyyKmGWPB6tmWuwRaHI5ElUxmilnzH71RSre1VeE/yKg4EBAMhO/+2hpg0XYMLAuM0ztEwA/KaQRKHibj+m2io+cIuOHGVntN/b4jxu7FYkS6Rw7t2+N+kiZxm2rrSqaVFops0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718209589; c=relaxed/simple; bh=MBFu4J9+OxZubq8gfcMp9FsYuDVq9pnlAH0AAvK8mPo=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=iycEyNzleKFvCKTkToK4RFRWNJm0jWn8iFn37w8xeoMCTwWGQlnTMkrwBd7vqsoCf8o+vtrQ+iXHGv+6XcTIwAsTXW+g7eibYfifbT/wvH8+jr7h1tE6OGjtx683V8rn8hBW7FO/HTXJVZmeeRT8i6xEf5zWglx+1RteiVpBpT8= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b=auijZpC8; arc=fail smtp.client-ip=40.107.122.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JeO9Vss6Cu8VBT9X8iFsrZs7ua6lRlNvVfJh6XGICbOy7OqMmjd3XQoOS6LzLy50gyJuVgwjADrTYlBGHqz+QDued646sITNsX1YYKI8xJEsM03A70HApNn5XYu2rvuoajwZxqB/fbCISveEeeQbCr94/yalZsq+HM1tvpm4G0flygNXTPtibEMsmQWigpN+V6IvskVEU/wuu+02Hn7nYSBvN5gXMPCMNs2lcT0CjbjwnzI8ThzqPhnsH7hVlFk7+UhX1jGJvmssMpNNZXmK8PRaZScW/sIk4oSKkbfYtB3dCtuoTw/Hlp9DfvRbQ+mtPhV6HqusAcjkmALsQjQaag== 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=MBFu4J9+OxZubq8gfcMp9FsYuDVq9pnlAH0AAvK8mPo=; b=IIg/mkPnP3Ev5ippvQw3GgluKQuy8+oNtw8d3srhMxdI+dq7N68nVT21CV2L6Kxf+lUkF0jY7NkVBcg24uUSaYmNYqr+WuXY5NOCP9yMVOofDyY959Qn2tTk8acYPzuGpJuF3gHBd2tUdyiXaWjfu04JkhymTZG2S9YCm8IlqWPuN1XGPHGjpTobLTixiKBLFPgO2O1oZ41gwuZogCPZVZLcql5tyq8iHFeZ5810fuTAyQfAFu/cR0SvqrIz02JJC1T2rM3wWcmPiY99Ry4SyX3+GjglWixIHJbxKjDyr53VlQYf/ZNvcu6jW8SCv6rEi8FI+6wOzfKp1ZOzGn8d2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MBFu4J9+OxZubq8gfcMp9FsYuDVq9pnlAH0AAvK8mPo=; b=auijZpC8OYH4l7GyQIVDUTpd8zSaw5+mSHC85BNumInsu86oTdYZftitWQ+28UNtXrMB7rNkY9y7gP4Lc5oeuvGmXvG1og4K+QLO8Ve2cWubdVIKQ3bwjivOSl8ssyN/grQh4CBiKK93cGUMacyeQK6h/+5yhkMik1qGrUgi4KY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) by CWLP265MB5866.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1a3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.20; Wed, 12 Jun 2024 16:26:25 +0000 Received: from LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::1818:a2bf:38a7:a1e7]) by LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM ([fe80::1818:a2bf:38a7:a1e7%5]) with mapi id 15.20.7677.019; Wed, 12 Jun 2024 16:26:25 +0000 Date: Wed, 12 Jun 2024 17:26:22 +0100 From: Gary Guo To: Matthew Maurer Cc: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , =?UTF-8?B?QmrDtnJu?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [RFC PATCH 2/2] kbuild: rust: provide an option to inline C helpers into Rust Message-ID: <20240612172623.5876d0ad@eugeo> In-Reply-To: References: <20240529202817.3641974-1-gary@garyguo.net> <20240529202817.3641974-3-gary@garyguo.net> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LNXP265CA0009.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5e::21) To LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:253::10) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LO2P265MB5183:EE_|CWLP265MB5866:EE_ X-MS-Office365-Filtering-Correlation-Id: 5667fda9-ab82-4b94-405f-08dc8afc6756 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230034|7416008|366010|376008|1800799018; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?U9FJoHf6T0Lq4y2n1LMbx0/wXY0fKwf1lp6zHvINIhY4UQTyKqrUwKkohJoi?= =?us-ascii?Q?XqK2D7GH6n1NdYdJFTFk5eZJUYMIE4g+irH611foKOLSoMEZqn/+4nyvmQQN?= =?us-ascii?Q?D5HmGGP3qJ6cPYj1223Li4mArPx2zIuNubFKnTF1JF6wGlH4m3QKdmuG4rnH?= =?us-ascii?Q?ouAS/Ah5xsajeYac+C32ZNImKwENGRxC/pQSpwiXcyb+DQ5Ggv33S/4D6UvK?= =?us-ascii?Q?GuHjepb6LYAXBwKoKVu+3KyEnA9x3h71nglJiOlDxbqGZ8uredwPLml9po14?= =?us-ascii?Q?Fhold2TjSQ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=?us-ascii?Q?v8OJEtwAnjwpUm0yCef2gbYmxDstAZdCD8RjaIAALcTQq1xi58RrDKTlwj8j?= =?us-ascii?Q?azUNNdDDrQ5NhW94RndpHNa232MIbaZ8aSEIXOyUD0W6/N2J1wSo8mDpbjHT?= =?us-ascii?Q?ZexZGn5PT9fylWFe8SjhxNW/?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230034)(7416008)(366010)(376008)(1800799018);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?G00p+Ka9p+5WUlHg25Or4f2qraxx2Tzxowxct3+RoKjGAnuoZ5jgtjnf5OI8?= =?us-ascii?Q?YyRRG+coZxVllxWUhtSR/MLT/uiDwGz1GHgc8lIE9OiW552sfsHTyECJ157B?= =?us-ascii?Q?cdAuS0bfCuFifnoul+c2WspK4T4djIWdXzCgSTUusAr+PgFpV4K+9vdZbniv?= =?us-ascii?Q?fnL1xkd7LhdeVmUgFg5RQrAO+awZJ9u0UeDgivcqqGSeuvtng2BVxkhzUZA2?= =?us-ascii?Q?BbW+/Ki32LWn9cWfG7PoOhYpIi8DItQ3tF6ThVgm2hifwTxMirqBMjQpKesu?= =?us-ascii?Q?OXOjMTjxUlCkr82K4oInn0A3XRprndMfTCubFZRD2PrTRMRJgEo2vNB9+dvt?= =?us-ascii?Q?066BlM1xxqaRfndeVzU5rYTGz2R81QS+U6walZZ+16pvSdCkZjRBOqQx7BVB?= =?us-ascii?Q?+2DRPnXaDTYNld2gM3J9OFJ5GByH54SrHsrB5knoxBpkoFJu5kn3C3Glmqqp?= =?us-ascii?Q?VOzdw11lA/uQ+izCh93q/I1kF0GjrvfCm6o1EjUFUWBs3+W5Dt/1fZ/6apfX?= =?us-ascii?Q?Fyxv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H3q?= =?us-ascii?Q?+wkTlrfKe2JbhL7+uPfr7Sa5ZizdaX1HjTle6eXVm7zC4lsPTpKrxGKkEoN+?= =?us-ascii?Q?0+k9qnr5lXojy0Ky3FuFuaPdMj2BllbmWa4ZTV+V+onYVymx2g7hn5evpzV2?= =?us-ascii?Q?MkKAoazXsgNI6EXq57L7d26l63qZGsNjTCFfFgcO?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 5667fda9-ab82-4b94-405f-08dc8afc6756 X-MS-Exchange-CrossTenant-AuthSource: LO2P265MB5183.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2024 16:26:25.1134 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2sJlvZX0YWrcnTREky5JpAXWfm+Uz5bDEWiQntfEnJ1duUNmQ6rHl0Lb3R+OsJJPYJmUUmR9L7+ZOT9wRxuHAw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB5866 On Fri, 7 Jun 2024 07:40:45 -0700 Matthew Maurer wrote: > The LLVM `.ll` textual bitcode representation may change from version > to version, which makes using `sed` to edit it potentially fragile. > Would it be possible to attach similar attributes without this? (Or > other attributes that can accomplish something similar, see the second > part.) I agree that text editing is fragile and should be avoided, but I'm not aware of a way to achieve this without text editing. > Would it be possible to use a Rust-only-LTO (actual LTO) flag rather > than a `llvm-link`? It seems likely that someone that wants to use a > synced `clang` and `rustc` to allow helpers to be inlined would be > unlikely to object to thin LTO of Rust. This would avoid introducing a > new tool. There's no way for rustc to actually perform the LTO, since the crate type that we use is rlib rather than staticlibs or cdylibs, Rust does not take care of the linking. > As one possible route around editing the `.ll` file, we could consider > *not* hiding these symbols, just marking them as "good idea to inline > if possible", and then masking any symbol that ends up in the final > `.o` via `objcopy --localize-symbol=blah`. If we're doing full-kernel > LTO rather than rust-only LTO, we'd need to use `llvm-objcopy` > instead, but the same process would follow - a postprocessing step on > the final crate object that localizes the symbol, with LTO giving the > compiler the option (but not requirement) to inline these functions if > it seems like a good idea. This was one of the approach that I considered, but IIUC objcopy require you to supply it a list of exact-match symbols rather than patterns, so we have to get all helper symbols and then feed it to objcopy. I really want to avoid having a script or host program to do this step. Best, Gary