mbox series

[00/16] selftests: vDSO: parse_vdso: Make compatible with nolibc

Message ID 20250203-parse_vdso-nolibc-v1-0-9cb6268d77be@linutronix.de (mailing list archive)
Headers show
Series selftests: vDSO: parse_vdso: Make compatible with nolibc | expand

Message

Thomas Weißschuh Feb. 3, 2025, 9:05 a.m. UTC
For testing the functionality of the vDSO, it is necessary to build
userspace programs for multiple different architectures.
It is additional work to acquire matching userspace cross-compilers with
full C libraries and then building root images out of those.
The kernel tree already contains nolibc, a small, header-only C library.
By using it, it is possible to build userspace programs without any
additional dependencies.
For example the kernel.org crosstools or multi-target clang can be used
to build test programs for a multitude of architectures.
While nolibc is very limited, it is enough for many selftests.
With some minor adjustments it is possible to make parse_vdso.c
compatible with nolibc.
As an example, vdso_standalone_test_x86 is now built from the same C
code as the regular vdso_test_gettimeofday, while still being completely
standalone.

This should probably go through the kselftest tree.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (16):
      MAINTAINERS: Add vDSO selftests
      elf, uapi: Add definition for STN_UNDEF
      elf, uapi: Add definition for DT_GNU_HASH
      elf, uapi: Add definitions for VER_FLG_BASE and VER_FLG_WEAK
      elf, uapi: Add type ElfXX_Versym
      elf, uapi: Add types ElfXX_Verdef and ElfXX_Veraux
      tools/include: Add uapi/linux/elf.h
      selftests: Add headers target
      selftests: vDSO: vdso_standalone_test_x86: Use vdso_init_form_sysinfo_ehdr
      selftests: vDSO: parse_vdso: Drop vdso_init_from_auxv()
      selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
      selftests: vDSO: parse_vdso: Test __SIZEOF_LONG__ instead of ULONG_MAX
      selftests: vDSO: parse_vdso: Make compatible with nolibc
      selftests: vDSO: vdso_test_gettimeofday: Clean up includes
      selftests: vDSO: vdso_test_gettimeofday: Make compatible with nolibc
      selftests: vDSO: vdso_standalone_test_x86: Switch to nolibc

 MAINTAINERS                                        |   1 +
 include/uapi/linux/elf.h                           |  38 ++
 tools/include/uapi/linux/elf.h                     | 524 +++++++++++++++++++++
 tools/testing/selftests/lib.mk                     |   5 +-
 tools/testing/selftests/vDSO/Makefile              |  11 +-
 tools/testing/selftests/vDSO/parse_vdso.c          |  21 +-
 tools/testing/selftests/vDSO/parse_vdso.h          |   1 -
 .../selftests/vDSO/vdso_standalone_test_x86.c      | 143 +-----
 .../selftests/vDSO/vdso_test_gettimeofday.c        |   4 +-
 9 files changed, 584 insertions(+), 164 deletions(-)
---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20241017-parse_vdso-nolibc-e069baa7ff48

Best regards,

Comments

Christophe Leroy Feb. 3, 2025, 11:23 a.m. UTC | #1
Le 03/02/2025 à 10:05, Thomas Weißschuh a écrit :
> For testing the functionality of the vDSO, it is necessary to build
> userspace programs for multiple different architectures.
> It is additional work to acquire matching userspace cross-compilers with
> full C libraries and then building root images out of those.
> The kernel tree already contains nolibc, a small, header-only C library.
> By using it, it is possible to build userspace programs without any
> additional dependencies.
> For example the kernel.org crosstools or multi-target clang can be used
> to build test programs for a multitude of architectures.
> While nolibc is very limited, it is enough for many selftests.
> With some minor adjustments it is possible to make parse_vdso.c
> compatible with nolibc.
> As an example, vdso_standalone_test_x86 is now built from the same C
> code as the regular vdso_test_gettimeofday, while still being completely
> standalone.
> 
> This should probably go through the kselftest tree.

Not sure what are the expectations with this series.

I gave it a try with vdso_test_gettimeofday and get the following:

$ powerpc64-linux-gcc -nostdlib -nostdinc -ffreestanding 
-fno-asynchronous-unwind-tables -fno-stack-protector -include 
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/nolibc.h 
-I/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/ 
-isystem 
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../usr/include 
-std=gnu99 -O2 -D_GNU_SOURCE= -isystem 
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/uapi 
    vdso_test_gettimeofday.c parse_vdso.c  -o 
/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_gettimeofday

make: Entering directory 
'/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO'
powerpc64-linux-gcc -nostdlib -nostdinc -ffreestanding 
-fno-asynchronous-unwind-tables -fno-stack-protector -include 
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/nolibc.h 
-I/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/ 
-isystem 
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../usr/include 
-std=gnu99 -O2 -D_GNU_SOURCE= -isystem 
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/uapi 
    vdso_test_gettimeofday.c parse_vdso.c  -o 
/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_gettimeofday
parse_vdso.c:38:34: error: unknown type name 'Elf64_Versym'
    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
       |                                  ^~~
parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
       |                                 ^~~~~~~~~~~~~~~
parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
       |                ^~~~~~~~~~~~~~
parse_vdso.c:63:9: note: in expansion of macro 'ELF'
    63 |         ELF(Versym) *versym;
       |         ^~~
parse_vdso.c:38:34: error: unknown type name 'Elf64_Verdef'
    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
       |                                  ^~~
parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
       |                                 ^~~~~~~~~~~~~~~
parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
       |                ^~~~~~~~~~~~~~
parse_vdso.c:64:9: note: in expansion of macro 'ELF'
    64 |         ELF(Verdef) *verdef;
       |         ^~~
parse_vdso.c: In function 'vdso_init_from_sysinfo_ehdr':
parse_vdso.c:38:34: error: 'Elf64_Versym' undeclared (first use in this 
function); did you mean 'Elf64_Sym'?
    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
       |                                  ^~~
parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
       |                                 ^~~~~~~~~~~~~~~
parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
       |                ^~~~~~~~~~~~~~
parse_vdso.c:150:45: note: in expansion of macro 'ELF'
   150 |                         vdso_info.versym = (ELF(Versym) *)
       |                                             ^~~
parse_vdso.c:38:34: note: each undeclared identifier is reported only 
once for each function it appears in
    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
       |                                  ^~~
parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
       |                                 ^~~~~~~~~~~~~~~
parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
       |                ^~~~~~~~~~~~~~
parse_vdso.c:150:45: note: in expansion of macro 'ELF'
   150 |                         vdso_info.versym = (ELF(Versym) *)
       |                                             ^~~
parse_vdso.c:150:58: error: expected expression before ')' token
   150 |                         vdso_info.versym = (ELF(Versym) *)
       |                                                          ^
parse_vdso.c:38:34: error: 'Elf64_Verdef' undeclared (first use in this 
function); did you mean 'Elf64_Word'?
    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
       |                                  ^~~
parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
       |                                 ^~~~~~~~~~~~~~~
parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
       |                ^~~~~~~~~~~~~~
parse_vdso.c:155:45: note: in expansion of macro 'ELF'
   155 |                         vdso_info.verdef = (ELF(Verdef) *)
       |                                             ^~~
parse_vdso.c:155:58: error: expected expression before ')' token
   155 |                         vdso_info.verdef = (ELF(Verdef) *)
       |                                                          ^
parse_vdso.c: At top level:
parse_vdso.c:38:34: error: unknown type name 'Elf64_Versym'; did you 
mean 'Elf64_Sym'?
    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
       |                                  ^~~
parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
       |                                 ^~~~~~~~~~~~~~~
parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
       |                ^~~~~~~~~~~~~~
parse_vdso.c:177:32: note: in expansion of macro 'ELF'
   177 | static bool vdso_match_version(ELF(Versym) ver,
       |                                ^~~
parse_vdso.c: In function 'vdso_sym':
parse_vdso.c:224:25: error: 'STN_UNDEF' undeclared (first use in this 
function); did you mean 'SHN_UNDEF'?
   224 |         for (; chain != STN_UNDEF; chain = 
vdso_info.chain[chain]) {
       |                         ^~~~~~~~~
       |                         SHN_UNDEF
parse_vdso.c:240:25: warning: implicit declaration of function 
'vdso_match_version' [-Wimplicit-function-declaration]
   240 |                     && !vdso_match_version(vdso_info.versym[chain],
       |                         ^~~~~~~~~~~~~~~~~~
make: *** [../lib.mk:222: 
/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_gettimeofday] 
Error 1
make: Leaving directory 
'/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO'

Christophe

> 
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> Thomas Weißschuh (16):
>        MAINTAINERS: Add vDSO selftests
>        elf, uapi: Add definition for STN_UNDEF
>        elf, uapi: Add definition for DT_GNU_HASH
>        elf, uapi: Add definitions for VER_FLG_BASE and VER_FLG_WEAK
>        elf, uapi: Add type ElfXX_Versym
>        elf, uapi: Add types ElfXX_Verdef and ElfXX_Veraux
>        tools/include: Add uapi/linux/elf.h
>        selftests: Add headers target
>        selftests: vDSO: vdso_standalone_test_x86: Use vdso_init_form_sysinfo_ehdr
>        selftests: vDSO: parse_vdso: Drop vdso_init_from_auxv()
>        selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
>        selftests: vDSO: parse_vdso: Test __SIZEOF_LONG__ instead of ULONG_MAX
>        selftests: vDSO: parse_vdso: Make compatible with nolibc
>        selftests: vDSO: vdso_test_gettimeofday: Clean up includes
>        selftests: vDSO: vdso_test_gettimeofday: Make compatible with nolibc
>        selftests: vDSO: vdso_standalone_test_x86: Switch to nolibc
> 
>   MAINTAINERS                                        |   1 +
>   include/uapi/linux/elf.h                           |  38 ++
>   tools/include/uapi/linux/elf.h                     | 524 +++++++++++++++++++++
>   tools/testing/selftests/lib.mk                     |   5 +-
>   tools/testing/selftests/vDSO/Makefile              |  11 +-
>   tools/testing/selftests/vDSO/parse_vdso.c          |  21 +-
>   tools/testing/selftests/vDSO/parse_vdso.h          |   1 -
>   .../selftests/vDSO/vdso_standalone_test_x86.c      | 143 +-----
>   .../selftests/vDSO/vdso_test_gettimeofday.c        |   4 +-
>   9 files changed, 584 insertions(+), 164 deletions(-)
> ---
> base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
> change-id: 20241017-parse_vdso-nolibc-e069baa7ff48
> 
> Best regards,
Thomas Weißschuh Feb. 3, 2025, 1:50 p.m. UTC | #2
On Mon, Feb 03, 2025 at 12:23:29PM +0100, Christophe Leroy wrote:
> Le 03/02/2025 à 10:05, Thomas Weißschuh a écrit :
> > For testing the functionality of the vDSO, it is necessary to build
> > userspace programs for multiple different architectures.
> > It is additional work to acquire matching userspace cross-compilers with
> > full C libraries and then building root images out of those.
> > The kernel tree already contains nolibc, a small, header-only C library.
> > By using it, it is possible to build userspace programs without any
> > additional dependencies.
> > For example the kernel.org crosstools or multi-target clang can be used
> > to build test programs for a multitude of architectures.
> > While nolibc is very limited, it is enough for many selftests.
> > With some minor adjustments it is possible to make parse_vdso.c
> > compatible with nolibc.
> > As an example, vdso_standalone_test_x86 is now built from the same C
> > code as the regular vdso_test_gettimeofday, while still being completely
> > standalone.
> > 
> > This should probably go through the kselftest tree.
> 
> Not sure what are the expectations with this series.

In general it should also work for PPC,
thanks for testing it.

> I gave it a try with vdso_test_gettimeofday and get the following:
> 
> $ powerpc64-linux-gcc -nostdlib -nostdinc -ffreestanding
> -fno-asynchronous-unwind-tables -fno-stack-protector -include /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/nolibc.h -I/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/
> -isystem
> /home/chleroy/linux-powerpc/tools/testing/selftests/../../../usr/include
> -std=gnu99 -O2 -D_GNU_SOURCE= -isystem /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/uapi
> vdso_test_gettimeofday.c parse_vdso.c  -o /home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_gettimeofday
> 
> make: Entering directory
> '/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO'
> powerpc64-linux-gcc -nostdlib -nostdinc -ffreestanding
> -fno-asynchronous-unwind-tables -fno-stack-protector -include /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/nolibc.h -I/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/
> -isystem
> /home/chleroy/linux-powerpc/tools/testing/selftests/../../../usr/include
> -std=gnu99 -O2 -D_GNU_SOURCE= -isystem /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/uapi
> vdso_test_gettimeofday.c parse_vdso.c  -o /home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_gettimeofday

This log is confusing. It contains traces of "make" output but no "make"
invocation. I'm also not sure if there were two different compilations
or only one. Can you give the full commandline?
For your testing it should be enough to enable
"vdso_test_standalone_x86" in the Makefile for PPC.

> parse_vdso.c:38:34: error: unknown type name 'Elf64_Versym'
>    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
>       |                                  ^~~
> parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
>    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
>       |                                 ^~~~~~~~~~~~~~~
> parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
>    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
>       |                ^~~~~~~~~~~~~~
> parse_vdso.c:63:9: note: in expansion of macro 'ELF'
>    63 |         ELF(Versym) *versym;
>       |         ^~~
> parse_vdso.c:38:34: error: unknown type name 'Elf64_Verdef'
>    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
>       |                                  ^~~
> parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
>    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
>       |                                 ^~~~~~~~~~~~~~~
> parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
>    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
>       |                ^~~~~~~~~~~~~~
> parse_vdso.c:64:9: note: in expansion of macro 'ELF'
>    64 |         ELF(Verdef) *verdef;
>       |         ^~~
> parse_vdso.c: In function 'vdso_init_from_sysinfo_ehdr':
> parse_vdso.c:38:34: error: 'Elf64_Versym' undeclared (first use in this
> function); did you mean 'Elf64_Sym'?
>    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
>       |                                  ^~~
> parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
>    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
>       |                                 ^~~~~~~~~~~~~~~
> parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
>    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
>       |                ^~~~~~~~~~~~~~
> parse_vdso.c:150:45: note: in expansion of macro 'ELF'
>   150 |                         vdso_info.versym = (ELF(Versym) *)
>       |                                             ^~~
> parse_vdso.c:38:34: note: each undeclared identifier is reported only once
> for each function it appears in
>    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
>       |                                  ^~~
> parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
>    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
>       |                                 ^~~~~~~~~~~~~~~
> parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
>    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
>       |                ^~~~~~~~~~~~~~
> parse_vdso.c:150:45: note: in expansion of macro 'ELF'
>   150 |                         vdso_info.versym = (ELF(Versym) *)
>       |                                             ^~~
> parse_vdso.c:150:58: error: expected expression before ')' token
>   150 |                         vdso_info.versym = (ELF(Versym) *)
>       |                                                          ^
> parse_vdso.c:38:34: error: 'Elf64_Verdef' undeclared (first use in this
> function); did you mean 'Elf64_Word'?
>    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
>       |                                  ^~~
> parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
>    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
>       |                                 ^~~~~~~~~~~~~~~
> parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
>    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
>       |                ^~~~~~~~~~~~~~
> parse_vdso.c:155:45: note: in expansion of macro 'ELF'
>   155 |                         vdso_info.verdef = (ELF(Verdef) *)
>       |                                             ^~~
> parse_vdso.c:155:58: error: expected expression before ')' token
>   155 |                         vdso_info.verdef = (ELF(Verdef) *)
>       |                                                          ^
> parse_vdso.c: At top level:
> parse_vdso.c:38:34: error: unknown type name 'Elf64_Versym'; did you mean
> 'Elf64_Sym'?
>    38 | #define ELF_BITS_XFORM2(bits, x) Elf##bits##_##x
>       |                                  ^~~
> parse_vdso.c:39:33: note: in expansion of macro 'ELF_BITS_XFORM2'
>    39 | #define ELF_BITS_XFORM(bits, x) ELF_BITS_XFORM2(bits, x)
>       |                                 ^~~~~~~~~~~~~~~
> parse_vdso.c:40:16: note: in expansion of macro 'ELF_BITS_XFORM'
>    40 | #define ELF(x) ELF_BITS_XFORM(ELF_BITS, x)
>       |                ^~~~~~~~~~~~~~
> parse_vdso.c:177:32: note: in expansion of macro 'ELF'
>   177 | static bool vdso_match_version(ELF(Versym) ver,
>       |                                ^~~
> parse_vdso.c: In function 'vdso_sym':
> parse_vdso.c:224:25: error: 'STN_UNDEF' undeclared (first use in this
> function); did you mean 'SHN_UNDEF'?
>   224 |         for (; chain != STN_UNDEF; chain = vdso_info.chain[chain]) {
>       |                         ^~~~~~~~~
>       |                         SHN_UNDEF
> parse_vdso.c:240:25: warning: implicit declaration of function
> 'vdso_match_version' [-Wimplicit-function-declaration]
>   240 |                     && !vdso_match_version(vdso_info.versym[chain],
>       |                         ^~~~~~~~~~~~~~~~~~
> make: *** [../lib.mk:222: /home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_gettimeofday]
> Error 1
> make: Leaving directory
> '/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO'
> 
> Christophe
> 
> > 
> > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> > ---
> > Thomas Weißschuh (16):
> >        MAINTAINERS: Add vDSO selftests
> >        elf, uapi: Add definition for STN_UNDEF
> >        elf, uapi: Add definition for DT_GNU_HASH
> >        elf, uapi: Add definitions for VER_FLG_BASE and VER_FLG_WEAK
> >        elf, uapi: Add type ElfXX_Versym
> >        elf, uapi: Add types ElfXX_Verdef and ElfXX_Veraux
> >        tools/include: Add uapi/linux/elf.h
> >        selftests: Add headers target
> >        selftests: vDSO: vdso_standalone_test_x86: Use vdso_init_form_sysinfo_ehdr
> >        selftests: vDSO: parse_vdso: Drop vdso_init_from_auxv()
> >        selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
> >        selftests: vDSO: parse_vdso: Test __SIZEOF_LONG__ instead of ULONG_MAX
> >        selftests: vDSO: parse_vdso: Make compatible with nolibc
> >        selftests: vDSO: vdso_test_gettimeofday: Clean up includes
> >        selftests: vDSO: vdso_test_gettimeofday: Make compatible with nolibc
> >        selftests: vDSO: vdso_standalone_test_x86: Switch to nolibc
> > 
> >   MAINTAINERS                                        |   1 +
> >   include/uapi/linux/elf.h                           |  38 ++
> >   tools/include/uapi/linux/elf.h                     | 524 +++++++++++++++++++++
> >   tools/testing/selftests/lib.mk                     |   5 +-
> >   tools/testing/selftests/vDSO/Makefile              |  11 +-
> >   tools/testing/selftests/vDSO/parse_vdso.c          |  21 +-
> >   tools/testing/selftests/vDSO/parse_vdso.h          |   1 -
> >   .../selftests/vDSO/vdso_standalone_test_x86.c      | 143 +-----
> >   .../selftests/vDSO/vdso_test_gettimeofday.c        |   4 +-
> >   9 files changed, 584 insertions(+), 164 deletions(-)
> > ---
> > base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
> > change-id: 20241017-parse_vdso-nolibc-e069baa7ff48
> > 
> > Best regards,
>
Christophe Leroy Feb. 3, 2025, 3:43 p.m. UTC | #3
Le 03/02/2025 à 14:50, Thomas Weißschuh a écrit :
> On Mon, Feb 03, 2025 at 12:23:29PM +0100, Christophe Leroy wrote:
>> Le 03/02/2025 à 10:05, Thomas Weißschuh a écrit :
>>> For testing the functionality of the vDSO, it is necessary to build
>>> userspace programs for multiple different architectures.
>>> It is additional work to acquire matching userspace cross-compilers with
>>> full C libraries and then building root images out of those.
>>> The kernel tree already contains nolibc, a small, header-only C library.
>>> By using it, it is possible to build userspace programs without any
>>> additional dependencies.
>>> For example the kernel.org crosstools or multi-target clang can be used
>>> to build test programs for a multitude of architectures.
>>> While nolibc is very limited, it is enough for many selftests.
>>> With some minor adjustments it is possible to make parse_vdso.c
>>> compatible with nolibc.
>>> As an example, vdso_standalone_test_x86 is now built from the same C
>>> code as the regular vdso_test_gettimeofday, while still being completely
>>> standalone.
>>>
>>> This should probably go through the kselftest tree.
>>
>> Not sure what are the expectations with this series.
> 
> In general it should also work for PPC,
> thanks for testing it.
> 
>> I gave it a try with vdso_test_gettimeofday and get the following:
>>
>> $ powerpc64-linux-gcc -nostdlib -nostdinc -ffreestanding
>> -fno-asynchronous-unwind-tables -fno-stack-protector -include /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/nolibc.h -I/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/
>> -isystem
>> /home/chleroy/linux-powerpc/tools/testing/selftests/../../../usr/include
>> -std=gnu99 -O2 -D_GNU_SOURCE= -isystem /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/uapi
>> vdso_test_gettimeofday.c parse_vdso.c  -o /home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_gettimeofday
>>
>> make: Entering directory
>> '/home/chleroy/linux-powerpc/tools/testing/selftests/vDSO'
>> powerpc64-linux-gcc -nostdlib -nostdinc -ffreestanding
>> -fno-asynchronous-unwind-tables -fno-stack-protector -include /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/nolibc.h -I/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/nolibc/
>> -isystem
>> /home/chleroy/linux-powerpc/tools/testing/selftests/../../../usr/include
>> -std=gnu99 -O2 -D_GNU_SOURCE= -isystem /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/include/uapi
>> vdso_test_gettimeofday.c parse_vdso.c  -o /home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_gettimeofday
> 
> This log is confusing. It contains traces of "make" output but no "make"
> invocation. I'm also not sure if there were two different compilations
> or only one. Can you give the full commandline?
> For your testing it should be enough to enable
> "vdso_test_standalone_x86" in the Makefile for PPC.

Well, yes I copied/pasted too much.

I made some hacky modifications to the Makefile but I forgot the '| 
header' pattern. With it added it works as expected.

Do you have any plan to get it work with nolibc for all test programs in 
selftests/vDSO, not only the standalone x86 test ?

Christophe
Thomas Weißschuh Feb. 3, 2025, 4:14 p.m. UTC | #4
On Mon, Feb 03, 2025 at 04:43:22PM +0100, Christophe Leroy wrote:
<snip>

> Do you have any plan to get it work with nolibc for all test programs in
> selftests/vDSO, not only the standalone x86 test ?

Not directly as next step. I am focussing on some other work which will
integrate (vDSO) selftests with nolibc slightly differently.
However if you have interest in converting the tests now, that would be
great and will also be useful for my future changes.
The current issues I see:
* Missing architecture support in nolibc (should be fairly easy to implement)
* Missing kselftest_harness.h support in nolibc (I'm working on that)
* Maybe some users want to stick with their regular libc
  (Nothing should prevent that, but the mechanism may need some discussion)


Thomas