From patchwork Mon May 27 21:16:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 13675840 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2080.outbound.protection.outlook.com [40.107.101.80]) (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 80EC7DDC1; Mon, 27 May 2024 21:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716844612; cv=fail; b=rlSkkvwjlUMZUNhyC/fCP9nhR1P0oMzZJQm8wOzsNRYOgfmovhDyMk1h0H+0ec99Au/6FdLIo4gHBZJuvI8n0GavBZPvM7L8HP3+esTBKx/nmCHO1G6CWk4USgNVAN130k/bmVc9b68wvL5RlVlXhe/dM19LsufIdex3IVKb/fA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716844612; c=relaxed/simple; bh=5pksoOG09hDgo7rxeccmSrs+8KVMX/TW4s/IMkqnvr0=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=E3ruO+5zUhV19qmsslThPMGR7kEtkxAu1cZDGlOSwJG0QCdN8kp5+Nm65SzFnBoEBGIIXvJHv+HDLTYtWJVwFpI//WbpF8MpfwOb3gyzJPZifDZqkJCeD+3LCRk19E8Qm8kQ2onEMdKV1kqHxkAgzZzbUOU9VHTl9A5I6fzkDvo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Zag8FdRG; arc=fail smtp.client-ip=40.107.101.80 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Zag8FdRG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=brB6XPm+r43sXGEuM6Alb7La7DWASgnub5oSjZ2bGfrwAXat04Yi8P/6DnECx3BDlXOikfWGfdn46gu2Y1Gp6qS3QVDwzpUCC9OUYl6N1Pf03/Zp3FckOWoa12mPmtUAw5+gGf68S0ZuDOm35XsD54V6nzrS/x8dCvXhkaiPtdaBR+Gwhu5mTeGOuu79O0Ia5bcBBH4j8QXKJj1gZa93gCzcbqTXf8/5ImyhY1p2729AjFiTQhW8L12cecrUmWd8vpuoGg0WGGR8ESfJsqslrlCISZsxgfHLnnyGnkSnBCAiO56nvLvNtH1EUF+mTTtqFJAqJo5Ar+y18lcKnQrdXA== 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=28qpJeU5/KOChtq/m7spbUDPhoJrz89c74dQA+hjBVE=; b=jTc8k7cGoMJuDt+lTG+U0XdfusqdKf20DZpdLuUqn5I63odVlWSQFZAPKRZ5BIqFBY796voF0AXl1yRga4Il0QfyMf1+X20lpcAAOSgnGr7Qsd1X8UGa7XLELOW75bIcpy5ikdLkGDovMAWsUuk5ed/FrQOlG5lBtBZDYX21vj/k7ONZzeKlC5xPqlfw2DHV5gIuDxajdMB3UmUJDDVmMScK4HNde+kjYGw3XYmimGpiU7o4uGGGpOkNXmzUp2F3q6HENH3ARYGkOdSuwIrK2WZK8OylWQS4Qsj+wXnolL5YxipRwbTQ5bnWpkso/XMmr0KbnwTmCocoMbqFhrDHUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=28qpJeU5/KOChtq/m7spbUDPhoJrz89c74dQA+hjBVE=; b=Zag8FdRG3cCeuUtyCDtYCQ9j3PEMSdEIiJgpvTmQFWfLpKzeOy/wZEzgsPQu6KI1fzuH1xJnO9UcLA2I589j/NR0GI4nDWQ1opxInmohrdYfOjiZHIeWUL1lPmWbUY3H9JsjRMmeXuJa7sp+zJLZqkYCM4WulrlIoecs8VZ+ox88aqi7IVgDhATCMR27ejbQb9HxnBJzR2LCquqlsEIReWgAa+uva63wkqVhmkltRLtPZMdzslVTyIMarzGzz1MkMZOjDvK/eg9wXRCtCa1uBPg5+o2881b7vLwpk5W6LSVtDpodoczk/ZvvS2NCcgM0KfTeSUHrTmOgUdLm1cHsPA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BY5PR12MB4130.namprd12.prod.outlook.com (2603:10b6:a03:20b::16) by CY8PR12MB8193.namprd12.prod.outlook.com (2603:10b6:930:71::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Mon, 27 May 2024 21:16:46 +0000 Received: from BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::2cf4:5198:354a:cd07]) by BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::2cf4:5198:354a:cd07%4]) with mapi id 15.20.7611.030; Mon, 27 May 2024 21:16:45 +0000 From: John Hubbard To: Shuah Khan Cc: Mark Brown , Vincenzo Frascino , Colin Ian King , Valentin Obst , linux-kselftest@vger.kernel.org, LKML , llvm@lists.linux.dev, John Hubbard Subject: [PATCH v2] selftests/vDSO: fix clang build errors and warnings Date: Mon, 27 May 2024 14:16:22 -0700 Message-ID: <20240527211622.290635-1-jhubbard@nvidia.com> X-Mailer: git-send-email 2.45.1 X-NVConfidentiality: public X-ClientProxiedBy: SJ0PR03CA0032.namprd03.prod.outlook.com (2603:10b6:a03:33e::7) To BY5PR12MB4130.namprd12.prod.outlook.com (2603:10b6:a03:20b::16) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR12MB4130:EE_|CY8PR12MB8193:EE_ X-MS-Office365-Filtering-Correlation-Id: 906ed397-548d-498d-6fc9-08dc7e925048 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|366007|1800799015; X-Microsoft-Antispam-Message-Info: FxoCFIaACYQ/anvkNYwWoi+YMRpwGBYw2XR5ugk0yCz4/3sB+wANgD7zorBHck9y6Cz4mMbP6MeeMB/k0F15WlLnAxKXeTxfp9mA+UWLFluFAOQ7m/+RkKiqpGRlTZh4DiyS5EoebiDmVCu44Zl88hIGtz7xnRvKdtXcAVb+bm0CEKOMxETSUCoadhVe7LCI98PXbFnTaQ61INS8/57g1hoAaTiW0T0gIlYQvt20FTILvasCZmrUJ489xfgBKFofZ+kGYxu7kq3sRUCtqBuAvWNtnhmsE8tH5i5PXzyP+9tUkb/3d0OIh8ujLokoiQF8QhrtsJ5auNlHgGo6sRKXEN+trzOTtm2W468URk3sw2o1Tl3tqt3+Qs6YIQWMrRPVF1FwQ1XSnS6O/d93uEtlmli7coanK7h+maMCLZO5zoRdd6ugdO17l9hD3OU3Ns3+Hd0IQEaPoOyJEWSUvTUYIxriaCtkHabNuDJ9Y0FrYLAbF7XicDdY11Ac205KzBml3iLA7MXfSeVE7ZAG/X09ys8/6RjME5EfqqZf0e11D+5OvKB9ZxekZcCg0vilKnC8TPkG0xN8uzbYFuwFxpgjOQLvpb4obY2qJcVBn82BMiHBgG6izxizk95vtUXWewbhURZTjPdc5fuT5W2Bwqq7fzUwyYn1vstOFi7AxAaHd2bBfLvWDFaJwVVHldEGC/+rsgKz3M0ObJDIl14Jj5W/Vcig8jZO4pJVGtDlRzrWhFlc71dcVZAmmiRNtvks1u/iuDrDv0iWRqnZ6rJo8+z3nm27QPgLMz0WNwnjtCn2CkGYFyzeIjZcbZQLp1fzma/jACptNmlFpWFM3Q52yy4mq+hLwAeXJLG3Gw1dm7iYiV0FU/YGsHoBAlfQqX2masbCS/qli4iozUpD8ZhG9B4/03kDufaIGQ9QYwDWwfuJGBpqbpqN0oVEAO7/2WvcLi867EQsJ5j6rWOcpbUQE+GhIwFSOYhpGT2NzR11pM9Yjg0J7k9l2XJsH70x2jiVY0flGzAnp4KUPpCaF8/M6h50bea4xw8Rg2qLbupQouBnSkQ6KbYijRkSZqYYE3vRQgpNkrLjnBc4Oext/YZrE2qSWkdvuUavb+5z9eU4OzQMh4tootzQ0UTNDWDhKGT2B0Esc1QRUwyP028/kjOkXD9x70Q48rZgWhPjfDL2ip3ShlzcYwx9zrkiEyCkIRO+0xbk7a0iUO7DoyolZW3T3DLoFMUyAbULBEdm+QGCu7vB9DdsZbqF+eay4Xg2W/UEPKoy3Kf5b9wn07T1VZamQ9tb6Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR12MB4130.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(366007)(1800799015);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wwU7ZyXADQoBghcV+SZowXa3MCklCLN9H/PhBEZXkuzwR0BCL6BJK36xTczokxUaR1SW3+YoAhzLbo4OYvml0kN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UvF6rZBrPtZDb2c7W7ELkcQHVdYi8d23v7aGWikspw79jNM4OLl9xbMot33ELJ4TqBbwf6dh0cxWGAjYlXDoaHUMdoXMPlz79RrZYt6IMWPk5SyUh/G+E++UBa7L9XyYxD2VSP9531j5gmlFHpztzTfnrM01n5qC61nViEzlJTR4uzY5S9dI6K+z4PMnvXjKr05ncHsjl4p/z3DSG7cIaCEYrDn6XCRQ7JnZW1EUF6Oph6LYzwT1eXE3YA9vr06OaU0cmCnplTwZMqGbZ2OyeIJhtns0AaIac6jpgTt1zmMfQWF3HlWZkaVpnZ+pDipjGiR5OYe8uacuOOpekRWi7q553U1HNFJrxHcEwW4fAoiFJYXbSm+k9a0AoKKtA1q7wnjMeipqGZxPHOv5FRCh/hHQwmeRIXgfdYM65i6Rr0OxRQHpnC6J56c6X9GWV3gOEPA== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 906ed397-548d-498d-6fc9-08dc7e925048 X-MS-Exchange-CrossTenant-AuthSource: BY5PR12MB4130.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2024 21:16:45.7707 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VwsukZfIFyT5UyBHeGORuzT5OgSCMoTSLbuZ8RREgsmCAxVPeKHWVnsGdF91t+iXh0aLemJSHBz0Dh8PrI8buw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8193 When building with clang, via: make LLVM=1 -C tools/testing/selftests ...there are several warnings, and an error. This fixes all of those and allows these tests to run and pass. 1. Fix linker error (undefined reference to memcpy) by providing a local version of memcpy. 2. clang complains about using this form: if (g = h & 0xf0000000) ...so factor out the assignment into a separate step. 3. The code is passing a signed const char* to elf_hash(), which expects a const unsigned char *. There are several callers, so fix this at the source by allowing the function to accept a signed argument, and then converting to unsigned operations, once inside the function. 4. clang doesn't have __attribute__((externally_visible)) and generates a warning to that effect. Fortunately, gcc 12 and gcc 13 do not seem to require that attribute in order to build, run and pass tests here, so remove it. [1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c49f@valentinobst.de/ Signed-off-by: John Hubbard Reviewed-by: Muhammad Usama Anjum Tested-by: Muhammad Usama Anjum Reviewed-by: Edward Liaw Reviewed-by: Carlos Llamas --- Changes since the first version: 1) Rebased onto Linux 6.10-rc1 thanks, John Hubbard tools/testing/selftests/vDSO/parse_vdso.c | 16 +++++++++++----- .../selftests/vDSO/vdso_standalone_test_x86.c | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) base-commit: 2bfcfd584ff5ccc8bb7acde19b42570414bf880b diff --git a/tools/testing/selftests/vDSO/parse_vdso.c b/tools/testing/selftests/vDSO/parse_vdso.c index 413f75620a35..4ae417372e9e 100644 --- a/tools/testing/selftests/vDSO/parse_vdso.c +++ b/tools/testing/selftests/vDSO/parse_vdso.c @@ -55,14 +55,20 @@ static struct vdso_info ELF(Verdef) *verdef; } vdso_info; -/* Straight from the ELF specification. */ -static unsigned long elf_hash(const unsigned char *name) +/* + * Straight from the ELF specification...and then tweaked slightly, in order to + * avoid a few clang warnings. + */ +static unsigned long elf_hash(const char *name) { unsigned long h = 0, g; - while (*name) + const unsigned char *uch_name = (const unsigned char *)name; + + while (*uch_name) { - h = (h << 4) + *name++; - if (g = h & 0xf0000000) + h = (h << 4) + *uch_name++; + g = h & 0xf0000000; + if (g) h ^= g >> 24; h &= ~g; } diff --git a/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c b/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c index 8a44ff973ee1..27f6fdf11969 100644 --- a/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c +++ b/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c @@ -18,7 +18,7 @@ #include "parse_vdso.h" -/* We need a libc functions... */ +/* We need some libc functions... */ int strcmp(const char *a, const char *b) { /* This implementation is buggy: it never returns -1. */ @@ -34,6 +34,20 @@ int strcmp(const char *a, const char *b) return 0; } +/* + * The clang build needs this, although gcc does not. + * Stolen from lib/string.c. + */ +void *memcpy(void *dest, const void *src, size_t count) +{ + char *tmp = dest; + const char *s = src; + + while (count--) + *tmp++ = *s++; + return dest; +} + /* ...and two syscalls. This is x86-specific. */ static inline long x86_syscall3(long nr, long a0, long a1, long a2) { @@ -70,7 +84,7 @@ void to_base10(char *lastdig, time_t n) } } -__attribute__((externally_visible)) void c_main(void **stack) +void c_main(void **stack) { /* Parse the stack */ long argc = (long)*stack;