From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 60EA71A08C3; Tue, 16 Jul 2024 18:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721154891; cv=none; b=TenOl+0dyrPe1/zldEJLtqUjbAKzJCce2nCy5YB93Qo1EiV545weOCd7DqQfSnOrBx6J2Fw+dFWg/WUJY4E4Uq/Sp4oohY7kR2ye/pWFfeuE0RqmG9ZdzqpKEH1yvenGp9wWigvinCXCH8wkxgwMl2xXQ54xeqQmZDxUnZch+uY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721154891; c=relaxed/simple; bh=2K0g1t7SFFmyFpHBYCQZgT7kd2mByMFkUCTErHVQcs8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rA/u8IOCNMJ5ou73t5rK4sGxtfd06suBYUdxijO7+iiKl2nKxbr7tHt8nsX8lHaWI0zWLp0W1+yOBr6LrMX4OMzTNq4ChSBQXKe4UqGm696u8rGuM3XnPAwsvg6gZYPQdaQwF7Mo7hV5ubwBGJKEhEqDk6qtWgibrDKlKzXL9JI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JwfI7Evt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JwfI7Evt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8B81C4AF0D; Tue, 16 Jul 2024 18:34:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721154890; bh=2K0g1t7SFFmyFpHBYCQZgT7kd2mByMFkUCTErHVQcs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JwfI7EvtbenLuH1S4pOkktFg/uL6rlc6QkJKJ0/KLYJt2HbDFMZFJv4MYoDpSqND2 aZ7YUI0qE2U7u2fW5XqsBeka82g5SPJ5VoOJEHMczhdauWDnQOblqyf2MjF+GotJy4 CwoDdcsC6VY8FILb4Z4dvGUBiaettBfUZhz0VMKP1IVwNX1OcPzzMoGvv/sSuZXr9H HsSiGyR+zxwFhcNDAxjr3SMLdXOfPr+7S9eZb+nizJW9Thmq1IU8IB4O0ZLrYNyCME HcSnuRkvWSFsuvU/j43T7YStCmgh1ovz7pZhLocZLCF1jHLiYkoRrZFQKGlMFjhEfT 3SMh6kYi1hjqQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: John Hubbard , Carlos Llamas , Edward Liaw , Muhammad Usama Anjum , Shuah Khan , Sasha Levin , shuah@kernel.org, nathan@kernel.org, linux-kselftest@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH AUTOSEL 5.10 2/4] selftests/vDSO: fix clang build errors and warnings Date: Tue, 16 Jul 2024 14:34:37 -0400 Message-ID: <20240716183443.2814769-2-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716183443.2814769-1-sashal@kernel.org> References: <20240716183443.2814769-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.221 Content-Transfer-Encoding: 8bit From: John Hubbard [ Upstream commit 73810cd45b99c6c418e1c6a487b52c1e74edb20d ] 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. Reviewed-by: Carlos Llamas Reviewed-by: Edward Liaw Reviewed-by: Muhammad Usama Anjum Tested-by: Muhammad Usama Anjum Signed-off-by: John Hubbard Signed-off-by: Shuah Khan Signed-off-by: Sasha Levin --- tools/testing/selftests/vDSO/parse_vdso.c | 16 +++++++++++----- .../selftests/vDSO/vdso_standalone_test_x86.c | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/vDSO/parse_vdso.c b/tools/testing/selftests/vDSO/parse_vdso.c index 413f75620a35b..4ae417372e9eb 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 8a44ff973ee17..27f6fdf119691 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; -- 2.43.0