llvm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Shuah Khan <shuah@kernel.org>
Cc: "Jason A . Donenfeld" <Jason@zx2c4.com>,
	Andy Lutomirski <luto@kernel.org>,
	Mark Brown <broonie@kernel.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Colin Ian King <colin.i.king@gmail.com>,
	Valentin Obst <kernel@valentinobst.de>,
	<linux-kselftest@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>, <llvm@lists.linux.dev>,
	Carlos Llamas <cmllamas@google.com>,
	Edward Liaw <edliaw@google.com>,
	Muhammad Usama Anjum <usama.anjum@collabora.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH v3 1/3] selftests/vDSO: fix clang build errors and warnings
Date: Fri, 14 Jun 2024 16:38:47 -0700	[thread overview]
Message-ID: <ab6124eb-88a7-441b-add9-b12176308155@nvidia.com> (raw)
In-Reply-To: <20240614233105.265009-2-jhubbard@nvidia.com>

Also Cc'ing Thomas Gleixner on this one, sorry for the omission.

On 6/14/24 4:31 PM, John Hubbard wrote:
> 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 <cmllamas@google.com>
> Reviewed-by: Edward Liaw <edliaw@google.com>
> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> Tested-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
> ---
>   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 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;

thanks,
-- 
John Hubbard
NVIDIA


  reply	other threads:[~2024-06-14 23:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-14 23:31 [PATCH v3 0/3] selftests/vDSO: fix clang build errors, and Makefile cleanup John Hubbard
2024-06-14 23:31 ` [PATCH v3 1/3] selftests/vDSO: fix clang build errors and warnings John Hubbard
2024-06-14 23:38   ` John Hubbard [this message]
2024-07-02 18:12   ` Edward Liaw
2024-07-02 18:25     ` John Hubbard
2024-07-02 18:49       ` Edward Liaw
2024-07-02 19:24         ` John Hubbard
2024-06-14 23:31 ` [PATCH v3 2/3] selftests/mm: remove partially duplicated "all:" target in Makefile John Hubbard
2024-06-14 23:31 ` [PATCH v3 3/3] selftests/vDSO: remove duplicate compiler invocations from Makefile John Hubbard
2024-06-14 23:34 ` [PATCH v3 0/3] selftests/vDSO: fix clang build errors, and Makefile cleanup John Hubbard
2024-06-17 20:15   ` Shuah, Andy L: " John Hubbard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ab6124eb-88a7-441b-add9-b12176308155@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=Jason@zx2c4.com \
    --cc=broonie@kernel.org \
    --cc=cmllamas@google.com \
    --cc=colin.i.king@gmail.com \
    --cc=edliaw@google.com \
    --cc=kernel@valentinobst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=luto@kernel.org \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=usama.anjum@collabora.com \
    --cc=vincenzo.frascino@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).