From patchwork Fri May 3 04:32:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 794718 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2043.outbound.protection.outlook.com [40.107.244.43]) (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 5C38CED9; Fri, 3 May 2024 04:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714710765; cv=fail; b=nsIIg6YzA8CC6jQGtOcFXw/Okp/kavfooJKb5zONsiTMXhjo07oB7u6UBtD8Um8zoRrQCpX2/4WHhS6qQvJ3P/sR01TTnw7Y2ETZtLQrBAbT6McIID+7KUaIAOz+4wHZbHP8k6BRxytoqLbVky7l1q8Sb5Xl9yrBEKkxDRiIkWU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714710765; c=relaxed/simple; bh=5AVOJGVUIkJZdv5qEmcg1ups6cp3fZnQIeLA1DJKjag=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=NgBYsEOfolvd22ycOv5K0zGbAcMa8Cp5XtxVylKAaRlqeiQJqzoKhSwn6I/n+HOIFkTNmG0b/6FCVk3kxuFHQ8/7ADo9Tcg1Q1GOsvAoyyt2CAcHVx1+VygKCVJ/281A77aSRgkYWf9OmZwxWCE3WhykZRo2GHMA7ENlEz8xdYU= 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=A2e9qaj4; arc=fail smtp.client-ip=40.107.244.43 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="A2e9qaj4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AHkkM4UmLxlUHnGXoD0hV27NwOlBsUNaRQ5gRHtM1wOXYkgYKkaFkBfwUFTFXB+qiWhYmAsGL8wDmgaVhi6I0ex8tBNZ/ZEv+kq4PtX+2Lv0EQgMV2eei41kG2XVAw8cKe6GZW0XHzjTeAFfw7QLzImhAq2CNmv1c1fogXioZA3wb78pwa9uPfjnwWYWG+/iIH1WvBrgPuVs+Np08Y5c18hMVKL84xv8yGBZpDtEOI7KpWW60LnmXgzcJiOJOJb6QEu+wAotN3VIb8LC5PJyz5w1k3ExR/9x8pfULv1V7+rmi+2u4se6A0EkPpoFNHbH1aTcc/aN7nJwKev6U1eVgw== 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=3DC2wnzQ/f2mJu4jlaSGosw848j4sbSY7P4kUBMFKJU=; b=GJYIPHPTKVNQ38gbBMxM8HvskFT9YCqK+0k3RW5KKALI5J0E4YYneUmZn6VhuD0r4Q74XcVU5BpDG+GvPqc0OHzUhHwcDdd3dfFVg7dY9CCVDhbrRjkIFuB8lwMJLa/D8PrL+N6NmXsVPZk9kRf+Iurv3XPrCdmk9mG0z7WcX0D/h5Z1jugsVU1cSXyllYunoyXBOH561j7ptlb4Czfr+f+4eMOczUylxdFYDHDPunDnY9UPiHLZnxUcsk7yVmQ8DVpsdmQXrpJFoUVeC6vbhjLEM3iXyPJOwonjars7KMhYcFzyOHe+o1lA2PYYAWfVIAP+VCy2RcvaK8jDU7isBA== 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=3DC2wnzQ/f2mJu4jlaSGosw848j4sbSY7P4kUBMFKJU=; b=A2e9qaj412m5uzOYwHGIKZJQmonxlYyZW96XMdDlfip7XfUMifFxyqO0uISB92ke8q/gRwrqbKt84jteMe1DBXRJcCOH4/Wzlkxm/wDlKO1V+Ee0ZbLWB3bkKOu5BlayNJsZcbRwM9+CW7tZJoIH3Krn6+o5/iKCeq8/4rSDVwW+ojyI67NpJGLyA6i4xO3mC7Fy2DsMVNNG8Ci+yc2hiGHhLxLiGQVjHLoGLfnLAOXzmaKEvB7EjZ+ZF0AbpwcaDrL0/c621rBZ7npjutnZGzgaDYD9q36UU+eJK90GoLswX6TEN5kpmtb34uaP97ScYt7l2cwe0QO5wpxEUjhETg== 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 DS7PR12MB8321.namprd12.prod.outlook.com (2603:10b6:8:ec::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.30; Fri, 3 May 2024 04:32:40 +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.7519.035; Fri, 3 May 2024 04:32:39 +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] selftests/vDSO: fix clang build errors and warnings Date: Thu, 2 May 2024 21:32:36 -0700 Message-ID: <20240503043236.101330-1-jhubbard@nvidia.com> X-Mailer: git-send-email 2.45.0 X-NVConfidentiality: public X-ClientProxiedBy: BY5PR17CA0065.namprd17.prod.outlook.com (2603:10b6:a03:167::42) 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_|DS7PR12MB8321:EE_ X-MS-Office365-Filtering-Correlation-Id: 83ee5438-327c-4fc9-f17e-08dc6b2a10b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|366007; X-Microsoft-Antispam-Message-Info: fnBYm2ZMVVUA66gZCzN9TlXZ7ziCuubSGU6ymP8f+7gQRwA/HG3cKow2FI6YkvvRGPUJGQYc3orvShkiWH4NQLhN7mRa6WEOYR6qgbikkEDH1geFM0qwI1Kz7KXQ2sRdUudLqEBMjRjMA4Mev8LOee/lXIreUA6FBGlM7mUhhAnHhEhxc+4lFE5Ns81Qo7O92gaMrnPNn7tlRR0JOUTDZovNi4kyroQFYEQga8qgYv5X+cc4of7WOWm47kGn2ookeCerlHr9pB3bdCIQiTT5c0axDs+33nCGk/zQwFCc6HnXjpkeBibLBt3c5CkJ2qysjEPdbeY6lwB7GhNX/CoUPzVb+Pbx+RAG/26vbpgnV84rPOSA9yc2ca4oorI6+CZDOTTj0ug1scp9a2useLV5fOwrMwsK86is4+7HAR3Yor5icc4J7nvWmpvtoF5KJyODNPHNxWgKJaKCpQpoa9Rcg2sb0NtHhTotf9Q8PaKN5mWLf9XFC+kD4RxUeb3gzNK6CHwrxJdSRSK916rmPR8mWaU8FEagtTH2nYBQet9ZPtsISEFvQML7xONQgSXSO+/GHMOwmOndbgYiGc+fUosdqTW+tV3R5q+fdRXxduSIV7feJp3GPO9EBwl0e/jtxUYEN+O0QJFXaWTFSSWFfyW7kqiRNCOpIeKvd+XDzZdbLeIw/8Nsajbr8HYYkWD0iHTHgS4xKNc7Ryg8R9uAvvFLAoI2do7i1NJGIdupLX0hk02c1bPNoybGzmZAiSKy/kudIn5007NNs2eBT42Lnnp9bvwgAfUNsbCiPEFR4yotYeyNXaddXycBHzDkOcK75NFKzZEXkow7Mk9ADQZFGwmpIBJl2VDZv9cNLZZJmBDW4auk6Pi3UJVsbI847gk2lEie9ijr1JVY2KPzwrzMlzVnf2LwmJ982ycVAsabO2rhcg9B5IFUCQ/dDsW5XWKpaBA2TcLRrnTwsCcrzTGW4vlye5HEbxpavuiWDG7x5EL0IvB/SF92tH3x6eLPjz69ow/LiLYkWLclprbeeO6afx6LGsZZuq0kf0xh6Rk5LjxjeN8bDDXIwiLzzbipyph1dj31M9vP9Mw8DAeRl/qTgJGrpwiXWdsy8OhckAG1TbfIyepYL5M0ppSZN3IO/tgnArhlmTY9ORs3KH8udw/jlSQRd6vFljL8T7J3jyp2vP5uGioS3Bqs6HpQdx6l5GtF1Hv8JUggfj3SAVkShINHeOoUw5N0yI81M11XaxVyUlIG7RaUzXecKWOjGWysh1hn3dY7ewby0kFeUF1YIONpbbSKBQ== 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)(1800799015)(376005)(366007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HcrHModZbeQ9SxKwwLmiOLBxxn7Zjua/Ed+UUxDmBlH6chf769YmC4WUyNn2LE5gU9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0m5Unuz4vpHAO/mnS1mLqoiqognX3Ra82eRh7245M5ATKnv2j6tHagT4/Mdec8rCv/f7NFxMoSNUjdmK4aQCrlBxZE/qhycf6Hox7tABryIuc/kDq3l8lSpXc6jIB33uieBYVHgN8Fsdgi0DDaMquYNpI6xFhAFDIQzClTWTOYWFRJfWqdR8qyFFUIJ++igHnq9fsKemedbCXcpVuR9B519uRiCZ4Kaj5Fmm4Pob1PC/W+DmL7j6m6BGDzoy5Yx0ecZTxCc3d3Pxbsxj+f8nEYY5eTQyiuZbul7ZO2UupB3nzkPffIYPmn1xf9P3Skr8+3uCNXLyeR0pT2W5gJE8zMx/TTrh3Exis83gUF0Vy7BMKQOHU+wyA55/+XwOF0ttdhALH/0xGN5x4DO0FRkibFDsPNg+q+warzNisxCyOKz+BqRXbA15FyRjnoE X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83ee5438-327c-4fc9-f17e-08dc6b2a10b4 X-MS-Exchange-CrossTenant-AuthSource: BY5PR12MB4130.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2024 04:32:39.3731 (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: HAa+HXO8YDGFB3Z7X6qEEdLHzemHeB03w/GD3Hqp6BoPzza9NSd5VGLnNCibxDiKFRaXZsFgmaKWOBWVSwt3LQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8321 First of all, in order to build with clang at all, one must first apply Valentin Obst's build fix for LLVM [1]. Once that is done, then 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 --- 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: f03359bca01bf4372cf2c118cd9a987a5951b1c8 prerequisite-patch-id: b901ece2a5b78503e2fb5480f20e304d36a0ea27 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;