Skip to content

Commit d78b357

Browse files
johnhubbardgregkh
authored andcommitted
selftests/vDSO: fix clang build errors and warnings
[ Upstream commit 73810cd ] 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> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8f0b9b1 commit d78b357

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

tools/testing/selftests/vDSO/parse_vdso.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,20 @@ static struct vdso_info
5555
ELF(Verdef) *verdef;
5656
} vdso_info;
5757

58-
/* Straight from the ELF specification. */
59-
static unsigned long elf_hash(const unsigned char *name)
58+
/*
59+
* Straight from the ELF specification...and then tweaked slightly, in order to
60+
* avoid a few clang warnings.
61+
*/
62+
static unsigned long elf_hash(const char *name)
6063
{
6164
unsigned long h = 0, g;
62-
while (*name)
65+
const unsigned char *uch_name = (const unsigned char *)name;
66+
67+
while (*uch_name)
6368
{
64-
h = (h << 4) + *name++;
65-
if (g = h & 0xf0000000)
69+
h = (h << 4) + *uch_name++;
70+
g = h & 0xf0000000;
71+
if (g)
6672
h ^= g >> 24;
6773
h &= ~g;
6874
}

tools/testing/selftests/vDSO/vdso_standalone_test_x86.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "parse_vdso.h"
2020

21-
/* We need a libc functions... */
21+
/* We need some libc functions... */
2222
int strcmp(const char *a, const char *b)
2323
{
2424
/* This implementation is buggy: it never returns -1. */
@@ -34,6 +34,20 @@ int strcmp(const char *a, const char *b)
3434
return 0;
3535
}
3636

37+
/*
38+
* The clang build needs this, although gcc does not.
39+
* Stolen from lib/string.c.
40+
*/
41+
void *memcpy(void *dest, const void *src, size_t count)
42+
{
43+
char *tmp = dest;
44+
const char *s = src;
45+
46+
while (count--)
47+
*tmp++ = *s++;
48+
return dest;
49+
}
50+
3751
/* ...and two syscalls. This is x86-specific. */
3852
static inline long x86_syscall3(long nr, long a0, long a1, long a2)
3953
{
@@ -70,7 +84,7 @@ void to_base10(char *lastdig, time_t n)
7084
}
7185
}
7286

73-
__attribute__((externally_visible)) void c_main(void **stack)
87+
void c_main(void **stack)
7488
{
7589
/* Parse the stack */
7690
long argc = (long)*stack;

0 commit comments

Comments
 (0)