selftests: vDSO: parse_vdso: Make compatible with nolibc
Subsystems (5)
v2 cover selftests: vDSO: parse_vdso: Make compatible with nolibc
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.
Also drop the dependency of parse_vdso.c on the elf.h header from libc and only use the one from the kernel's UAPI.
While this series is useful on its own now, it will also integrate with the kunit UAPI framework currently under development:
https://lore.kernel.org/lkml/[email protected]/
---
Changes in v2:
- Provide a limits.h header in nolibc
- Pick up Reviewed-by tags from Kees
- Link to v1: https://lore.kernel.org/r/[email protected]
---
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
tools/nolibc: add limits.h shim header
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: 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/nolibc/Makefile | 1 + tools/include/nolibc/limits.h | 7 + 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 | 19 +- tools/testing/selftests/vDSO/parse_vdso.h | 1 - .../selftests/vDSO/vdso_standalone_test_x86.c | 143 +----- .../selftests/vDSO/vdso_test_gettimeofday.c | 4 +- 11 files changed, 590 insertions(+), 164 deletions(-)
---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20241017-parse_vdso-nolibc-e069baa7ff48
Best regards,
Signature · 1 line
Thomas Weißschuh <[email protected]>
PATCH v2 1/16 MAINTAINERS: Add vDSO selftests
These currently have no maintainer besides the default kselftest ones. Add the general vDSO maintainers, too.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -9777,6 +9777,7 @@ F: include/asm-generic/vdso/vsyscall.h F: include/vdso/ F: kernel/time/vsyscall.c F: lib/vdso/ +F: tools/testing/selftests/vDSO/ GENWQE (IBM Generic Workqueue Card) M: Frank Haverkamp <[email protected]>
Signature · 1 line
2.48.1
Re: [PATCH v2 01/16] MAINTAINERS: Add vDSO selftests
Quoted 14 lines · Thomas Weißschuh
These currently have no maintainer besides the default kselftest ones. Add the general vDSO maintainers, too.
Signed-off-by Thomas Weißschuh <[email protected]>--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)MAINTAINERS +0
-0
MAINTAINERS F: include/asm-generic/vdso/vsyscall.h · line 9783
Quoted 7 lines
MAINTAINERS +1
-0@@ -9777,6 +9777,7 @@ F: include/asm-generic/vdso/vsyscall.h F: include/vdso/ F: kernel/time/vsyscall.c F: lib/vdso/ +F: tools/testing/selftests/vDSO/ GENWQE (IBM Generic Workqueue Card) M: Frank Haverkamp <[email protected]>
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] MAINTAINERS: Add vDSO selftests
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: ba2e35644d09af730880bb404bb6dd84685dcd7e Gitweb: https://git.kernel.org/tip/ba2e35644d09af730880bb404bb6dd84685dcd7e Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:40 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:11 +01:00
MAINTAINERS: Add vDSO selftests
These currently have no maintainer besides the default kselftest ones. Add the general vDSO maintainers, too.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -9777,6 +9777,7 @@ F: include/asm-generic/vdso/vsyscall.h F: include/vdso/ F: kernel/time/vsyscall.c F: lib/vdso/ +F: tools/testing/selftests/vDSO/ GENWQE (IBM Generic Workqueue Card) M: Frank Haverkamp <[email protected]>
PATCH v2 2/16 elf, uapi: Add definition for STN_UNDEF
In reply to Thomas WeißschuhThe definition is used by tools/testing/selftests/vDSO/parse_vdso.c. To be able to build the vDSO selftests without a libc dependency, add the definition to the kernels own UAPI headers.
--- include/uapi/linux/elf.h | 2 ++ 1 file changed, 2 insertions(+)
include/uapi/linux/elf.h +2 -0
@@ -125,6 +125,8 @@ typedef __s64 Elf64_Sxword;#define STB_GLOBAL 1#define STB_WEAK 2 +#define STN_UNDEF 0 +#define STT_NOTYPE 0#define STT_OBJECT 1#define STT_FUNC 2
Signature · 1 line
2.48.1
Re: [PATCH v2 02/16] elf, uapi: Add definition for STN_UNDEF
Quoted 17 lines · Thomas Weißschuh
The definition is used by
tools/testing/selftests/vDSO/parse_vdso.c. To be able to build the vDSO selftests without a libc dependency, add the definition to the kernels own UAPI headers.Reviewed-by Kees Cook <[email protected]>Signed-off-by Thomas Weißschuh <[email protected]>--- include/uapi/linux/elf.h | 2 ++ 1 file changed, 2 insertions(+)include/uapi/linux/elf.h +0
-0
include/uapi/linux/elf.h typedef __s64 Elf64_Sxword; · line 132
Quoted 8 lines
include/uapi/linux/elf.h +2
-0@@ -125,6 +125,8 @@ typedef __s64 Elf64_Sxword;#define STB_GLOBAL 1#define STB_WEAK 2 +#define STN_UNDEF 0 +#define STT_NOTYPE 0#define STT_OBJECT 1#define STT_FUNC 2
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] elf, uapi: Add definition for STN_UNDEF
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: c4131140961b93883e69a01b09f8ed4bcebefaf1 Gitweb: https://git.kernel.org/tip/c4131140961b93883e69a01b09f8ed4bcebefaf1 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:41 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:11 +01:00
elf, uapi: Add definition for STN_UNDEF
The definition is used by tools/testing/selftests/vDSO/parse_vdso.c.
To be able to build the vDSO selftests without a libc dependency, add the definition to the kernels own UAPI headers.
--- include/uapi/linux/elf.h | 2 ++ 1 file changed, 2 insertions(+)
include/uapi/linux/elf.h +2 -0
@@ -125,6 +125,8 @@ typedef __s64 Elf64_Sxword;#define STB_GLOBAL 1#define STB_WEAK 2 +#define STN_UNDEF 0 +#define STT_NOTYPE 0#define STT_OBJECT 1#define STT_FUNC 2
PATCH v2 3/16 elf, uapi: Add definition for DT_GNU_HASH
In reply to Thomas WeißschuhThe definition is used by tools/testing/selftests/vDSO/parse_vdso.c. To be able to build the vDSO selftests without a libc dependency, add the define to the kernels own UAPI headers.
--- include/uapi/linux/elf.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/elf.h +1 -0
@@ -107,6 +107,7 @@ typedef __s64 Elf64_Sxword;#define DT_VALRNGLO 0x6ffffd00#define DT_VALRNGHI 0x6ffffdff#define DT_ADDRRNGLO 0x6ffffe00 +#define DT_GNU_HASH 0x6ffffef5#define DT_ADDRRNGHI 0x6ffffeff#define DT_VERSYM 0x6ffffff0#define DT_RELACOUNT 0x6ffffff9
Signature · 1 line
2.48.1
Re: [PATCH v2 03/16] elf, uapi: Add definition for DT_GNU_HASH
Quoted 17 lines · Thomas Weißschuh
The definition is used by
tools/testing/selftests/vDSO/parse_vdso.c. To be able to build the vDSO selftests without a libc dependency, add the define to the kernels own UAPI headers.Reviewed-by Kees Cook <[email protected]>Signed-off-by Thomas Weißschuh <[email protected]>--- include/uapi/linux/elf.h | 1 + 1 file changed, 1 insertion(+)include/uapi/linux/elf.h +0
-0
include/uapi/linux/elf.h typedef __s64 Elf64_Sxword; · line 113
Quoted 7 lines
include/uapi/linux/elf.h +1
-0@@ -107,6 +107,7 @@ typedef __s64 Elf64_Sxword;#define DT_VALRNGLO 0x6ffffd00#define DT_VALRNGHI 0x6ffffdff#define DT_ADDRRNGLO 0x6ffffe00 +#define DT_GNU_HASH 0x6ffffef5#define DT_ADDRRNGHI 0x6ffffeff#define DT_VERSYM 0x6ffffff0#define DT_RELACOUNT 0x6ffffff9
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] elf, uapi: Add definition for DT_GNU_HASH
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 50881d1469cf35eec690d863276cf257c391eec5 Gitweb: https://git.kernel.org/tip/50881d1469cf35eec690d863276cf257c391eec5 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:42 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:11 +01:00
elf, uapi: Add definition for DT_GNU_HASH
The definition is used by tools/testing/selftests/vDSO/parse_vdso.c.
To be able to build the vDSO selftests without a libc dependency, add the define to the kernels own UAPI headers.
--- include/uapi/linux/elf.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/elf.h +1 -0
@@ -107,6 +107,7 @@ typedef __s64 Elf64_Sxword;#define DT_VALRNGLO 0x6ffffd00#define DT_VALRNGHI 0x6ffffdff#define DT_ADDRRNGLO 0x6ffffe00 +#define DT_GNU_HASH 0x6ffffef5#define DT_ADDRRNGHI 0x6ffffeff#define DT_VERSYM 0x6ffffff0#define DT_RELACOUNT 0x6ffffff9
PATCH v2 4/16 elf, uapi: Add definitions for VER_FLG_BASE and VER_FLG_WEAK
In reply to Thomas WeißschuhThe definitions are used by tools/testing/selftests/vDSO/parse_vdso.c. To be able to build the vDSO selftests without a libc dependency, add the definitions to the kernels own UAPI headers.
--- include/uapi/linux/elf.h | 3 +++ 1 file changed, 3 insertions(+)
include/uapi/linux/elf.h +3 -0
@@ -136,6 +136,9 @@ typedef __s64 Elf64_Sxword;#define STT_COMMON 5#define STT_TLS 6 +#define VER_FLG_BASE 0x1 +#define VER_FLG_WEAK 0x2 +#define ELF_ST_BIND (x) ((x) >> 4)#define ELF_ST_TYPE (x) ((x) & 0xf)#define ELF32_ST_BIND (x) ELF_ST_BIND(x)
Signature · 1 line
2.48.1
Re: [PATCH v2 04/16] elf, uapi: Add definitions for VER_FLG_BASE and VER_FLG_WEAK
Quoted 17 lines · Thomas Weißschuh
The definitions are used by
tools/testing/selftests/vDSO/parse_vdso.c. To be able to build the vDSO selftests without a libc dependency, add the definitions to the kernels own UAPI headers.Reviewed-by Kees Cook <[email protected]>Signed-off-by Thomas Weißschuh <[email protected]>--- include/uapi/linux/elf.h | 3 +++ 1 file changed, 3 insertions(+)include/uapi/linux/elf.h +0
-0
include/uapi/linux/elf.h typedef __s64 Elf64_Sxword; · line 144
Quoted 9 lines
include/uapi/linux/elf.h +3
-0@@ -136,6 +136,9 @@ typedef __s64 Elf64_Sxword;#define STT_COMMON 5#define STT_TLS 6 +#define VER_FLG_BASE 0x1 +#define VER_FLG_WEAK 0x2 +#define ELF_ST_BIND (x) ((x) >> 4)#define ELF_ST_TYPE (x) ((x) & 0xf)#define ELF32_ST_BIND (x) ELF_ST_BIND(x)
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] elf, uapi: Add definitions for VER_FLG_BASE and VER_FLG_WEAK
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 049d19bb3807e10902d41125c9d511025389718f Gitweb: https://git.kernel.org/tip/049d19bb3807e10902d41125c9d511025389718f Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:43 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:11 +01:00
elf, uapi: Add definitions for VER_FLG_BASE and VER_FLG_WEAK
The definitions are used by tools/testing/selftests/vDSO/parse_vdso.c.
To be able to build the vDSO selftests without a libc dependency, add the definitions to the kernels own UAPI headers.
--- include/uapi/linux/elf.h | 3 +++ 1 file changed, 3 insertions(+)
include/uapi/linux/elf.h +3 -0
@@ -136,6 +136,9 @@ typedef __s64 Elf64_Sxword;#define STT_COMMON 5#define STT_TLS 6 +#define VER_FLG_BASE 0x1 +#define VER_FLG_WEAK 0x2 +#define ELF_ST_BIND (x) ((x) >> 4)#define ELF_ST_TYPE (x) ((x) & 0xf)#define ELF32_ST_BIND (x) ELF_ST_BIND(x)
PATCH v2 5/16 elf, uapi: Add type ElfXX_Versym
In reply to Thomas WeißschuhThe types are used by tools/testing/selftests/vDSO/parse_vdso.c. To be able to build the vDSO selftests without a libc dependency, add the types to the kernels own UAPI headers.
As documented by elf(5).
--- include/uapi/linux/elf.h | 2 ++ 1 file changed, 2 insertions(+)
include/uapi/linux/elf.h +2 -0
@@ -11,6 +11,7 @@ typedef __u16 Elf32_Half;typedef __u32 Elf32_Off ;typedef __s32 Elf32_Sword ;typedef __u32 Elf32_Word ; +typedef __u16 Elf32_Versym ;/* 64-bit ELF base types. */ typedef __u64 Elf64_Addr ;
@@ -21,6 +22,7 @@ typedef __s32 Elf64_Sword;typedef __u32 Elf64_Word ;typedef __u64 Elf64_Xword ;typedef __s64 Elf64_Sxword ; +typedef __u16 Elf64_Versym ;/* These constants are for the segment types stored in the image headers */ #define PT_NULL 0
Signature · 1 line
2.48.1
Re: [PATCH v2 05/16] elf, uapi: Add type ElfXX_Versym
Quoted 26 lines · Thomas Weißschuh
The types are used by
tools/testing/selftests/vDSO/parse_vdso.c. To be able to build the vDSO selftests without a libc dependency, add the types to the kernels own UAPI headers.As documented by elf(5).
Reviewed-by Kees Cook <[email protected]>Signed-off-by Thomas Weißschuh <[email protected]>--- include/uapi/linux/elf.h | 2 ++ 1 file changed, 2 insertions(+)include/uapi/linux/elf.h +1
-0@@ -11,6 +11,7 @@ typedef __u16 Elf32_Half;typedef __u32 Elf32_Off ;typedef __s32 Elf32_Sword ;typedef __u32 Elf32_Word ; +typedef __u16 Elf32_Versym ;/* 64-bit ELF base types. */ typedef __u64 Elf64_Addr ;
include/uapi/linux/elf.h typedef __s32 Elf64_Sword; · line 28
Quoted 7 lines
include/uapi/linux/elf.h +1
-0@@ -21,6 +22,7 @@ typedef __s32 Elf64_Sword;typedef __u32 Elf64_Word ;typedef __u64 Elf64_Xword ;typedef __s64 Elf64_Sxword ; +typedef __u16 Elf64_Versym ;/* These constants are for the segment types stored in the image headers */ #define PT_NULL 0
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] elf, uapi: Add type ElfXX_Versym
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 2c86f604f85def1be0b7889c18e055ed63591018 Gitweb: https://git.kernel.org/tip/2c86f604f85def1be0b7889c18e055ed63591018 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:44 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:11 +01:00
elf, uapi: Add type ElfXX_Versym
The type is used by tools/testing/selftests/vDSO/parse_vdso.c.
To be able to build the vDSO selftests without a libc dependency, add the type to the kernels own UAPI headers. As documented by elf(5).
--- include/uapi/linux/elf.h | 2 ++ 1 file changed, 2 insertions(+)
include/uapi/linux/elf.h +2 -0
@@ -11,6 +11,7 @@ typedef __u16 Elf32_Half;typedef __u32 Elf32_Off ;typedef __s32 Elf32_Sword ;typedef __u32 Elf32_Word ; +typedef __u16 Elf32_Versym ;/* 64-bit ELF base types. */ typedef __u64 Elf64_Addr ;
@@ -21,6 +22,7 @@ typedef __s32 Elf64_Sword;typedef __u32 Elf64_Word ;typedef __u64 Elf64_Xword ;typedef __s64 Elf64_Sxword ; +typedef __u16 Elf64_Versym ;/* These constants are for the segment types stored in the image headers */ #define PT_NULL 0
PATCH v2 6/16 elf, uapi: Add types ElfXX_Verdef and ElfXX_Veraux
In reply to Thomas WeißschuhThe types are used by tools/testing/selftests/vDSO/parse_vdso.c. To be able to build the vDSO selftests without a libc dependency, add the types to the kernels own UAPI headers.
--- include/uapi/linux/elf.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
include/uapi/linux/elf.h +30 -0
@@ -491,4 +491,34 @@ typedef struct elf64_note {/* Bits for GNU_PROPERTY_AARCH64_FEATURE_1_BTI */ #define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) +typedef struct { +Elf32_Half vd_version; +Elf32_Half vd_flags; +Elf32_Half vd_ndx; +Elf32_Half vd_cnt; +Elf32_Word vd_hash; +Elf32_Word vd_aux; +Elf32_Word vd_next; +}Elf32_Verdef ; + +typedef struct { +Elf64_Half vd_version; +Elf64_Half vd_flags; +Elf64_Half vd_ndx; +Elf64_Half vd_cnt; +Elf64_Word vd_hash; +Elf64_Word vd_aux; +Elf64_Word vd_next; +}Elf64_Verdef ; + +typedef struct { +Elf32_Word vda_name; +Elf32_Word vda_next; +}Elf32_Verdaux ; + +typedef struct { +Elf64_Word vda_name; +Elf64_Word vda_next; +}Elf64_Verdaux ; +#endif /* _UAPI_LINUX_ELF_H */
Signature · 1 line
2.48.1
Re: [PATCH v2 06/16] elf, uapi: Add types ElfXX_Verdef and ElfXX_Veraux
Quoted 41 lines · Thomas Weißschuh
The types are used by
tools/testing/selftests/vDSO/parse_vdso.c. To be able to build the vDSO selftests without a libc dependency, add the types to the kernels own UAPI headers.Reviewed-by Kees Cook <[email protected]>Signed-off-by Thomas Weißschuh <[email protected]>--- include/uapi/linux/elf.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)include/uapi/linux/elf.h +21
-0@@ -491,4 +491,34 @@ typedef struct elf64_note {/* Bits for GNU_PROPERTY_AARCH64_FEATURE_1_BTI */ #define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) +typedef struct { +Elf32_Half vd_version; +Elf32_Half vd_flags; +Elf32_Half vd_ndx; +Elf32_Half vd_cnt; +Elf32_Word vd_hash; +Elf32_Word vd_aux; +Elf32_Word vd_next; +}Elf32_Verdef ; + +typedef struct { +Elf64_Half vd_version; +Elf64_Half vd_flags; +Elf64_Half vd_ndx; +Elf64_Half vd_cnt; +Elf64_Word vd_hash; +Elf64_Word vd_aux; +Elf64_Word vd_next; +}Elf64_Verdef ; + +typedef struct {
include/uapi/linux/elf.h typedef struct elf64_note { · line 524
Quoted 10 lines
include/uapi/linux/elf.h +9
-0+Elf32_Word vda_name; + Elf32_Word vda_next; +} Elf32_Verdaux; + +typedef struct { +Elf64_Word vda_name; +Elf64_Word vda_next; +}Elf64_Verdaux ; +#endif /* _UAPI_LINUX_ELF_H */
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] elf, uapi: Add types ElfXX_Verdef and ElfXX_Veraux
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: e0d15896f5dc90f4bd36ab79c958f6eff3f7f403 Gitweb: https://git.kernel.org/tip/e0d15896f5dc90f4bd36ab79c958f6eff3f7f403 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:45 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:12 +01:00
elf, uapi: Add types ElfXX_Verdef and ElfXX_Veraux
The types are used by tools/testing/selftests/vDSO/parse_vdso.c.
To be able to build the vDSO selftests without a libc dependency, add the types to the kernels own UAPI headers.
--- include/uapi/linux/elf.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
include/uapi/linux/elf.h +30 -0
@@ -491,4 +491,34 @@ typedef struct elf64_note {/* Bits for GNU_PROPERTY_AARCH64_FEATURE_1_BTI */ #define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) +typedef struct { +Elf32_Half vd_version; +Elf32_Half vd_flags; +Elf32_Half vd_ndx; +Elf32_Half vd_cnt; +Elf32_Word vd_hash; +Elf32_Word vd_aux; +Elf32_Word vd_next; +}Elf32_Verdef ; + +typedef struct { +Elf64_Half vd_version; +Elf64_Half vd_flags; +Elf64_Half vd_ndx; +Elf64_Half vd_cnt; +Elf64_Word vd_hash; +Elf64_Word vd_aux; +Elf64_Word vd_next; +}Elf64_Verdef ; + +typedef struct { +Elf32_Word vda_name; +Elf32_Word vda_next; +}Elf32_Verdaux ; + +typedef struct { +Elf64_Word vda_name; +Elf64_Word vda_next; +}Elf64_Verdaux ; +#endif /* _UAPI_LINUX_ELF_H */
PATCH v2 7/16 tools/include: Add uapi/linux/elf.h
In reply to Thomas WeißschuhIt will be used by the vDSO selftests.
--- tools/include/uapi/linux/elf.h | 524 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 524 insertions(+)
tools/include/uapi/linux/elf.h new file +524 -0
@@ -0,0 +1,524 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_ELF_H +#define _LINUX_ELF_H + +#include <linux/types.h> +#include <linux/elf-em.h> + +/* 32-bit ELF base types. */ +typedef __u32 Elf32_Addr ; +typedef __u16 Elf32_Half ; +typedef __u32 Elf32_Off ; +typedef __s32 Elf32_Sword ; +typedef __u32 Elf32_Word ; +typedef __u16 Elf32_Versym ; + +/* 64-bit ELF base types. */ +typedef __u64 Elf64_Addr ; +typedef __u16 Elf64_Half ; +typedef __s16 Elf64_SHalf ; +typedef __u64 Elf64_Off ; +typedef __s32 Elf64_Sword ; +typedef __u32 Elf64_Word ; +typedef __u64 Elf64_Xword ; +typedef __s64 Elf64_Sxword ; +typedef __u16 Elf64_Versym ; + +/* These constants are for the segment types stored in the image headers */ +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +#define PT_INTERP 3 +#define PT_NOTE 4 +#define PT_SHLIB 5 +#define PT_PHDR 6 +#define PT_TLS 7/* Thread local storage segment */ +#define PT_LOOS 0x60000000/* OS-specific */ +#define PT_HIOS 0x6fffffff/* OS-specific */ +#define PT_LOPROC 0x70000000 +#define PT_HIPROC 0x7fffffff +#define PT_GNU_EH_FRAME (PT_LOOS + 0x474e550) +#define PT_GNU_STACK (PT_LOOS + 0x474e551) +#define PT_GNU_RELRO (PT_LOOS + 0x474e552) +#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) + + +/* ARM MTE memory tag segment type */ +#define PT_AARCH64_MEMTAG_MTE (PT_LOPROC + 0x2) + +/* +* Extended Numbering +* +* If the real number of program header table entries is larger than +* or equal to PN_XNUM(0xffff), it is set to sh_info field of the +* section header at index 0, and PN_XNUM is set to e_phnum +* field. Otherwise, the section header at index 0 is zero +* initialized, if it exists. +* +* Specifications are available in: +* +* - Oracle: Linker and Libraries. +* Part No: 817–1984–19, August 2011. +* https://docs.oracle.com/cd/E18752_01/pdf/817-1984.pdf +* +* - System V ABI AMD64 Architecture Processor Supplement +* Draft Version 0.99.4, +* January 13, 2010. +* http://www.cs.washington.edu/education/courses/cse351/12wi/supp-docs/abi.pdf +*/ +#define PN_XNUM 0xffff + +/* These constants define the different elf file types */ +#define ET_NONE 0 +#define ET_REL 1 +#define ET_EXEC 2 +#define ET_DYN 3 +#define ET_CORE 4 +#define ET_LOPROC 0xff00 +#define ET_HIPROC 0xffff + +/* This is the info that is needed to parse the dynamic section of the file */ +#define DT_NULL 0 +#define DT_NEEDED 1 +#define DT_PLTRELSZ 2 +#define DT_PLTGOT 3 +#define DT_HASH 4 +#define DT_STRTAB 5 +#define DT_SYMTAB 6 +#define DT_RELA 7 +#define DT_RELASZ 8 +#define DT_RELAENT 9 +#define DT_STRSZ 10 +#define DT_SYMENT 11 +#define DT_INIT 12 +#define DT_FINI 13 +#define DT_SONAME 14 +#define DT_RPATH 15 +#define DT_SYMBOLIC 16 +#define DT_REL 17 +#define DT_RELSZ 18 +#define DT_RELENT 19 +#define DT_PLTREL 20 +#define DT_DEBUG 21 +#define DT_TEXTREL 22 +#define DT_JMPREL 23 +#define DT_ENCODING 32 +#define OLD_DT_LOOS 0x60000000 +#define DT_LOOS 0x6000000d +#define DT_HIOS 0x6ffff000 +#define DT_VALRNGLO 0x6ffffd00 +#define DT_VALRNGHI 0x6ffffdff +#define DT_ADDRRNGLO 0x6ffffe00 +#define DT_GNU_HASH 0x6ffffef5 +#define DT_ADDRRNGHI 0x6ffffeff +#define DT_VERSYM 0x6ffffff0 +#define DT_RELACOUNT 0x6ffffff9 +#define DT_RELCOUNT 0x6ffffffa +#define DT_FLAGS_1 0x6ffffffb +#define DT_VERDEF 0x6ffffffc +#define DT_VERDEFNUM 0x6ffffffd +#define DT_VERNEED 0x6ffffffe +#define DT_VERNEEDNUM 0x6fffffff +#define OLD_DT_HIOS 0x6fffffff +#define DT_LOPROC 0x70000000 +#define DT_HIPROC 0x7fffffff + +/* This info is needed when parsing the symbol table */ +#define STB_LOCAL 0 +#define STB_GLOBAL 1 +#define STB_WEAK 2 + +#define STN_UNDEF 0 + +#define STT_NOTYPE 0 +#define STT_OBJECT 1 +#define STT_FUNC 2 +#define STT_SECTION 3 +#define STT_FILE 4 +#define STT_COMMON 5 +#define STT_TLS 6 + +#define VER_FLG_BASE 0x1 +#define VER_FLG_WEAK 0x2 + +#define ELF_ST_BIND (x) ((x) >> 4) +#define ELF_ST_TYPE (x) ((x) & 0xf) +#define ELF32_ST_BIND (x) ELF_ST_BIND(x) +#define ELF32_ST_TYPE (x) ELF_ST_TYPE(x) +#define ELF64_ST_BIND (x) ELF_ST_BIND(x) +#define ELF64_ST_TYPE (x) ELF_ST_TYPE(x) + +typedef struct { +Elf32_Sword d_tag; +union { +Elf32_Sword d_val; +Elf32_Addr d_ptr; + } d_un; +}Elf32_Dyn ; + +typedef struct { +Elf64_Sxword d_tag;/* entry tag value */ +union { +Elf64_Xword d_val; +Elf64_Addr d_ptr; + } d_un; +}Elf64_Dyn ; + +/* The following are used with relocations */ +#define ELF32_R_SYM (x) ((x) >> 8) +#define ELF32_R_TYPE (x) ((x) & 0xff) + +#define ELF64_R_SYM (i) ((i) >> 32) +#define ELF64_R_TYPE (i) ((i) & 0xffffffff) + +typedef struct elf32_rel { +Elf32_Addr r_offset; +Elf32_Word r_info; +}Elf32_Rel ; + +typedef struct elf64_rel { +Elf64_Addr r_offset;/* Location at which to apply the action */ +Elf64_Xword r_info;/* index and type of relocation */ +}Elf64_Rel ; + +typedef struct elf32_rela { +Elf32_Addr r_offset; +Elf32_Word r_info; +Elf32_Sword r_addend; +}Elf32_Rela ; + +typedef struct elf64_rela { +Elf64_Addr r_offset;/* Location at which to apply the action */ +Elf64_Xword r_info;/* index and type of relocation */ +Elf64_Sxword r_addend;/* Constant addend used to compute value */ +}Elf64_Rela ; + +typedef struct elf32_sym { +Elf32_Word st_name; +Elf32_Addr st_value; +Elf32_Word st_size; +unsigned char st_info; +unsigned char st_other; +Elf32_Half st_shndx; +}Elf32_Sym ; + +typedef struct elf64_sym { +Elf64_Word st_name;/* Symbol name, index in string tbl */ +unsigned char st_info;/* Type and binding attributes */ +unsigned char st_other;/* No defined meaning, 0 */ +Elf64_Half st_shndx;/* Associated section index */ +Elf64_Addr st_value;/* Value of the symbol */ +Elf64_Xword st_size;/* Associated symbol size */ +}Elf64_Sym ; + + +#define EI_NIDENT 16 + +typedef struct elf32_hdr { +unsigned char e_ident[EI_NIDENT ]; +Elf32_Half e_type; +Elf32_Half e_machine; +Elf32_Word e_version; +Elf32_Addr e_entry;/* Entry point */ +Elf32_Off e_phoff; +Elf32_Off e_shoff; +Elf32_Word e_flags; +Elf32_Half e_ehsize; +Elf32_Half e_phentsize; +Elf32_Half e_phnum; +Elf32_Half e_shentsize; +Elf32_Half e_shnum; +Elf32_Half e_shstrndx; +}Elf32_Ehdr ; + +typedef struct elf64_hdr { +unsigned char e_ident[EI_NIDENT ];/* ELF "magic number" */ +Elf64_Half e_type; +Elf64_Half e_machine; +Elf64_Word e_version; +Elf64_Addr e_entry;/* Entry point virtual address */ +Elf64_Off e_phoff;/* Program header table file offset */ +Elf64_Off e_shoff;/* Section header table file offset */ +Elf64_Word e_flags; +Elf64_Half e_ehsize; +Elf64_Half e_phentsize; +Elf64_Half e_phnum; +Elf64_Half e_shentsize; +Elf64_Half e_shnum; +Elf64_Half e_shstrndx; +}Elf64_Ehdr ; + +/* These constants define the permissions on sections in the program +header, p_flags. */ +#define PF_R 0x4 +#define PF_W 0x2 +#define PF_X 0x1 + +typedef struct elf32_phdr { +Elf32_Word p_type; +Elf32_Off p_offset; +Elf32_Addr p_vaddr; +Elf32_Addr p_paddr; +Elf32_Word p_filesz; +Elf32_Word p_memsz; +Elf32_Word p_flags; +Elf32_Word p_align; +}Elf32_Phdr ; + +typedef struct elf64_phdr { +Elf64_Word p_type; +Elf64_Word p_flags; +Elf64_Off p_offset;/* Segment file offset */ +Elf64_Addr p_vaddr;/* Segment virtual address */ +Elf64_Addr p_paddr;/* Segment physical address */ +Elf64_Xword p_filesz;/* Segment size in file */ +Elf64_Xword p_memsz;/* Segment size in memory */ +Elf64_Xword p_align;/* Segment alignment, file & memory */ +}Elf64_Phdr ; + +/* sh_type */ +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_NUM 12 +#define SHT_LOPROC 0x70000000 +#define SHT_HIPROC 0x7fffffff +#define SHT_LOUSER 0x80000000 +#define SHT_HIUSER 0xffffffff + +/* sh_flags */ +#define SHF_WRITE 0x1 +#define SHF_ALLOC 0x2 +#define SHF_EXECINSTR 0x4 +#define SHF_RELA_LIVEPATCH 0x00100000 +#define SHF_RO_AFTER_INIT 0x00200000 +#define SHF_MASKPROC 0xf0000000 + +/* special section indexes */ +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xff00 +#define SHN_LOPROC 0xff00 +#define SHN_HIPROC 0xff1f +#define SHN_LIVEPATCH 0xff20 +#define SHN_ABS 0xfff1 +#define SHN_COMMON 0xfff2 +#define SHN_HIRESERVE 0xffff + +typedef struct elf32_shdr { +Elf32_Word sh_name; +Elf32_Word sh_type; +Elf32_Word sh_flags; +Elf32_Addr sh_addr; +Elf32_Off sh_offset; +Elf32_Word sh_size; +Elf32_Word sh_link; +Elf32_Word sh_info; +Elf32_Word sh_addralign; +Elf32_Word sh_entsize; +}Elf32_Shdr ; + +typedef struct elf64_shdr { +Elf64_Word sh_name;/* Section name, index in string tbl */ +Elf64_Word sh_type;/* Type of section */ +Elf64_Xword sh_flags;/* Miscellaneous section attributes */ +Elf64_Addr sh_addr;/* Section virtual addr at execution */ +Elf64_Off sh_offset;/* Section file offset */ +Elf64_Xword sh_size;/* Size of section in bytes */ +Elf64_Word sh_link;/* Index of another section */ +Elf64_Word sh_info;/* Additional section information */ +Elf64_Xword sh_addralign;/* Section alignment */ +Elf64_Xword sh_entsize;/* Entry size if section holds table */ +}Elf64_Shdr ; + +#define EI_MAG0 0/* e_ident[] indexes */ +#define EI_MAG1 1 +#define EI_MAG2 2 +#define EI_MAG3 3 +#define EI_CLASS 4 +#define EI_DATA 5 +#define EI_VERSION 6 +#define EI_OSABI 7 +#define EI_PAD 8 + +#define ELFMAG0 0x7f/* EI_MAG */ +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' +#define ELFMAG "\177ELF" +#define SELFMAG 4 + +#define ELFCLASSNONE 0/* EI_CLASS */ +#define ELFCLASS32 1 +#define ELFCLASS64 2 +#define ELFCLASSNUM 3 + +#define ELFDATANONE 0/* e_ident[EI_DATA] */ +#define ELFDATA2LSB 1 +#define ELFDATA2MSB 2 + +#define EV_NONE 0/* e_version, EI_VERSION */ +#define EV_CURRENT 1 +#define EV_NUM 2 + +#define ELFOSABI_NONE 0 +#define ELFOSABI_LINUX 3 + +#ifndef ELF_OSABI +#define ELF_OSABI ELFOSABI_NONE +#endif + +/* +* Notes used in ET_CORE. Architectures export some of the arch register sets +* using the corresponding note types via the PTRACE_GETREGSET and +* PTRACE_SETREGSET requests. +* The note name for these types is "LINUX", except NT_PRFPREG that is named +* "CORE". +*/ +#define NT_PRSTATUS 1 +#define NT_PRFPREG 2 +#define NT_PRPSINFO 3 +#define NT_TASKSTRUCT 4 +#define NT_AUXV 6 +/* +* Note to userspace developers: size of NT_SIGINFO note may increase +* in the future to accomodate more fields, don't assume it is fixed! +*/ +#define NT_SIGINFO 0x53494749 +#define NT_FILE 0x46494c45 +#define NT_PRXFPREG 0x46e62b7f/* copied from gdb5.1/include/elf/common.h */ +#define NT_PPC_VMX 0x100/* PowerPC Altivec/VMX registers */ +#define NT_PPC_SPE 0x101/* PowerPC SPE/EVR registers */ +#define NT_PPC_VSX 0x102/* PowerPC VSX registers */ +#define NT_PPC_TAR 0x103/* Target Address Register */ +#define NT_PPC_PPR 0x104/* Program Priority Register */ +#define NT_PPC_DSCR 0x105/* Data Stream Control Register */ +#define NT_PPC_EBB 0x106/* Event Based Branch Registers */ +#define NT_PPC_PMU 0x107/* Performance Monitor Registers */ +#define NT_PPC_TM_CGPR 0x108/* TM checkpointed GPR Registers */ +#define NT_PPC_TM_CFPR 0x109/* TM checkpointed FPR Registers */ +#define NT_PPC_TM_CVMX 0x10a/* TM checkpointed VMX Registers */ +#define NT_PPC_TM_CVSX 0x10b/* TM checkpointed VSX Registers */ +#define NT_PPC_TM_SPR 0x10c/* TM Special Purpose Registers */ +#define NT_PPC_TM_CTAR 0x10d/* TM checkpointed Target Address Register */ +#define NT_PPC_TM_CPPR 0x10e/* TM checkpointed Program Priority Register */ +#define NT_PPC_TM_CDSCR 0x10f/* TM checkpointed Data Stream Control Register */ +#define NT_PPC_PKEY 0x110/* Memory Protection Keys registers */ +#define NT_PPC_DEXCR 0x111/* PowerPC DEXCR registers */ +#define NT_PPC_HASHKEYR 0x112/* PowerPC HASHKEYR register */ +#define NT_386_TLS 0x200/* i386 TLS slots (struct user_desc) */ +#define NT_386_IOPERM 0x201/* x86 io permission bitmap (1=deny) */ +#define NT_X86_XSTATE 0x202/* x86 extended state using xsave */ +/* Old binutils treats 0x203 as a CET state */ +#define NT_X86_SHSTK 0x204/* x86 SHSTK state */ +#define NT_X86_XSAVE_LAYOUT 0x205/* XSAVE layout description */ +#define NT_S390_HIGH_GPRS 0x300/* s390 upper register halves */ +#define NT_S390_TIMER 0x301/* s390 timer register */ +#define NT_S390_TODCMP 0x302/* s390 TOD clock comparator register */ +#define NT_S390_TODPREG 0x303/* s390 TOD programmable register */ +#define NT_S390_CTRS 0x304/* s390 control registers */ +#define NT_S390_PREFIX 0x305/* s390 prefix register */ +#define NT_S390_LAST_BREAK 0x306/* s390 breaking event address */ +#define NT_S390_SYSTEM_CALL 0x307/* s390 system call restart data */ +#define NT_S390_TDB 0x308/* s390 transaction diagnostic block */ +#define NT_S390_VXRS_LOW 0x309/* s390 vector registers 0-15 upper half */ +#define NT_S390_VXRS_HIGH 0x30a/* s390 vector registers 16-31 */ +#define NT_S390_GS_CB 0x30b/* s390 guarded storage registers */ +#define NT_S390_GS_BC 0x30c/* s390 guarded storage broadcast control block */ +#define NT_S390_RI_CB 0x30d/* s390 runtime instrumentation */ +#define NT_S390_PV_CPU_DATA 0x30e/* s390 protvirt cpu dump data */ +#define NT_ARM_VFP 0x400/* ARM VFP/NEON registers */ +#define NT_ARM_TLS 0x401/* ARM TLS register */ +#define NT_ARM_HW_BREAK 0x402/* ARM hardware breakpoint registers */ +#define NT_ARM_HW_WATCH 0x403/* ARM hardware watchpoint registers */ +#define NT_ARM_SYSTEM_CALL 0x404/* ARM system call number */ +#define NT_ARM_SVE 0x405/* ARM Scalable Vector Extension registers */ +#define NT_ARM_PAC_MASK 0x406/* ARM pointer authentication code masks */ +#define NT_ARM_PACA_KEYS 0x407/* ARM pointer authentication address keys */ +#define NT_ARM_PACG_KEYS 0x408/* ARM pointer authentication generic key */ +#define NT_ARM_TAGGED_ADDR_CTRL 0x409/* arm64 tagged address control (prctl()) */ +#define NT_ARM_PAC_ENABLED_KEYS 0x40a/* arm64 ptr auth enabled keys (prctl()) */ +#define NT_ARM_SSVE 0x40b/* ARM Streaming SVE registers */ +#define NT_ARM_ZA 0x40c/* ARM SME ZA registers */ +#define NT_ARM_ZT 0x40d/* ARM SME ZT registers */ +#define NT_ARM_FPMR 0x40e/* ARM floating point mode register */ +#define NT_ARM_POE 0x40f/* ARM POE registers */ +#define NT_ARM_GCS 0x410/* ARM GCS state */ +#define NT_ARC_V2 0x600/* ARCv2 accumulator/extra registers */ +#define NT_VMCOREDD 0x700/* Vmcore Device Dump Note */ +#define NT_MIPS_DSP 0x800/* MIPS DSP ASE registers */ +#define NT_MIPS_FP_MODE 0x801/* MIPS floating-point mode */ +#define NT_MIPS_MSA 0x802/* MIPS SIMD registers */ +#define NT_RISCV_CSR 0x900/* RISC-V Control and Status Registers */ +#define NT_RISCV_VECTOR 0x901/* RISC-V vector registers */ +#define NT_RISCV_TAGGED_ADDR_CTRL 0x902/* RISC-V tagged address control (prctl()) */ +#define NT_LOONGARCH_CPUCFG 0xa00/* LoongArch CPU config registers */ +#define NT_LOONGARCH_CSR 0xa01/* LoongArch control and status registers */ +#define NT_LOONGARCH_LSX 0xa02/* LoongArch Loongson SIMD Extension registers */ +#define NT_LOONGARCH_LASX 0xa03/* LoongArch Loongson Advanced SIMD Extension registers */ +#define NT_LOONGARCH_LBT 0xa04/* LoongArch Loongson Binary Translation registers */ +#define NT_LOONGARCH_HW_BREAK 0xa05/* LoongArch hardware breakpoint registers */ +#define NT_LOONGARCH_HW_WATCH 0xa06/* LoongArch hardware watchpoint registers */ + +/* Note types with note name "GNU" */ +#define NT_GNU_PROPERTY_TYPE_0 5 + +/* Note header in a PT_NOTE section */ +typedef struct elf32_note { +Elf32_Word n_namesz;/* Name size */ +Elf32_Word n_descsz;/* Content size */ +Elf32_Word n_type;/* Content type */ +}Elf32_Nhdr ; + +/* Note header in a PT_NOTE section */ +typedef struct elf64_note { +Elf64_Word n_namesz;/* Name size */ +Elf64_Word n_descsz;/* Content size */ +Elf64_Word n_type;/* Content type */ +}Elf64_Nhdr ; + +/* .note.gnu.property types for EM_AARCH64: */ +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 + +/* Bits for GNU_PROPERTY_AARCH64_FEATURE_1_BTI */ +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) + +typedef struct { +Elf32_Half vd_version; +Elf32_Half vd_flags; +Elf32_Half vd_ndx; +Elf32_Half vd_cnt; +Elf32_Word vd_hash; +Elf32_Word vd_aux; +Elf32_Word vd_next; +}Elf32_Verdef ; + +typedef struct { +Elf64_Half vd_version; +Elf64_Half vd_flags; +Elf64_Half vd_ndx; +Elf64_Half vd_cnt; +Elf64_Word vd_hash; +Elf64_Word vd_aux; +Elf64_Word vd_next; +}Elf64_Verdef ; + +typedef struct { +Elf32_Word vda_name; +Elf32_Word vda_next; +}Elf32_Verdaux ; + +typedef struct { +Elf64_Word vda_name; +Elf64_Word vda_next; +}Elf64_Verdaux ; + +#endif /* _LINUX_ELF_H */
Signature · 1 line
2.48.1
Re: [PATCH v2 07/16] tools/include: Add uapi/linux/elf.h
Quoted 3 lines · Thomas Weißschuh
It will be used by the vDSO selftests.
Signed-off-by Thomas Weißschuh <[email protected]>
Quoted 535 lines
--- tools/include/uapi/linux/elf.h | 524 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 524 insertions(+)tools/include/uapi/linux/elf.h new file +524
-0@@ -0,0 +1,524 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_ELF_H +#define _LINUX_ELF_H + +#include <linux/types.h> +#include <linux/elf-em.h> + +/* 32-bit ELF base types. */ +typedef __u32 Elf32_Addr ; +typedef __u16 Elf32_Half ; +typedef __u32 Elf32_Off ; +typedef __s32 Elf32_Sword ; +typedef __u32 Elf32_Word ; +typedef __u16 Elf32_Versym ; + +/* 64-bit ELF base types. */ +typedef __u64 Elf64_Addr ; +typedef __u16 Elf64_Half ; +typedef __s16 Elf64_SHalf ; +typedef __u64 Elf64_Off ; +typedef __s32 Elf64_Sword ; +typedef __u32 Elf64_Word ; +typedef __u64 Elf64_Xword ; +typedef __s64 Elf64_Sxword ; +typedef __u16 Elf64_Versym ; + +/* These constants are for the segment types stored in the image headers */ +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +#define PT_INTERP 3 +#define PT_NOTE 4 +#define PT_SHLIB 5 +#define PT_PHDR 6 +#define PT_TLS 7/* Thread local storage segment */ +#define PT_LOOS 0x60000000/* OS-specific */ +#define PT_HIOS 0x6fffffff/* OS-specific */ +#define PT_LOPROC 0x70000000 +#define PT_HIPROC 0x7fffffff +#define PT_GNU_EH_FRAME (PT_LOOS + 0x474e550) +#define PT_GNU_STACK (PT_LOOS + 0x474e551) +#define PT_GNU_RELRO (PT_LOOS + 0x474e552) +#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) + + +/* ARM MTE memory tag segment type */ +#define PT_AARCH64_MEMTAG_MTE (PT_LOPROC + 0x2) + +/* +* Extended Numbering +* +* If the real number of program header table entries is larger than +* or equal to PN_XNUM(0xffff), it is set to sh_info field of the +* section header at index 0, and PN_XNUM is set to e_phnum +* field. Otherwise, the section header at index 0 is zero +* initialized, if it exists. +* +* Specifications are available in: +* +* - Oracle: Linker and Libraries. +* Part No: 817–1984–19, August 2011. +* https://docs.oracle.com/cd/E18752_01/pdf/817-1984.pdf +* +* - System V ABI AMD64 Architecture Processor Supplement +* Draft Version 0.99.4, +* January 13, 2010. +* http://www.cs.washington.edu/education/courses/cse351/12wi/supp-docs/abi.pdf +*/ +#define PN_XNUM 0xffff + +/* These constants define the different elf file types */ +#define ET_NONE 0 +#define ET_REL 1 +#define ET_EXEC 2 +#define ET_DYN 3 +#define ET_CORE 4 +#define ET_LOPROC 0xff00 +#define ET_HIPROC 0xffff + +/* This is the info that is needed to parse the dynamic section of the file */ +#define DT_NULL 0 +#define DT_NEEDED 1 +#define DT_PLTRELSZ 2 +#define DT_PLTGOT 3 +#define DT_HASH 4 +#define DT_STRTAB 5 +#define DT_SYMTAB 6 +#define DT_RELA 7 +#define DT_RELASZ 8 +#define DT_RELAENT 9 +#define DT_STRSZ 10 +#define DT_SYMENT 11 +#define DT_INIT 12 +#define DT_FINI 13 +#define DT_SONAME 14 +#define DT_RPATH 15 +#define DT_SYMBOLIC 16 +#define DT_REL 17 +#define DT_RELSZ 18 +#define DT_RELENT 19 +#define DT_PLTREL 20 +#define DT_DEBUG 21 +#define DT_TEXTREL 22 +#define DT_JMPREL 23 +#define DT_ENCODING 32 +#define OLD_DT_LOOS 0x60000000 +#define DT_LOOS 0x6000000d +#define DT_HIOS 0x6ffff000 +#define DT_VALRNGLO 0x6ffffd00 +#define DT_VALRNGHI 0x6ffffdff +#define DT_ADDRRNGLO 0x6ffffe00 +#define DT_GNU_HASH 0x6ffffef5 +#define DT_ADDRRNGHI 0x6ffffeff +#define DT_VERSYM 0x6ffffff0 +#define DT_RELACOUNT 0x6ffffff9 +#define DT_RELCOUNT 0x6ffffffa +#define DT_FLAGS_1 0x6ffffffb +#define DT_VERDEF 0x6ffffffc +#define DT_VERDEFNUM 0x6ffffffd +#define DT_VERNEED 0x6ffffffe +#define DT_VERNEEDNUM 0x6fffffff +#define OLD_DT_HIOS 0x6fffffff +#define DT_LOPROC 0x70000000 +#define DT_HIPROC 0x7fffffff + +/* This info is needed when parsing the symbol table */ +#define STB_LOCAL 0 +#define STB_GLOBAL 1 +#define STB_WEAK 2 + +#define STN_UNDEF 0 + +#define STT_NOTYPE 0 +#define STT_OBJECT 1 +#define STT_FUNC 2 +#define STT_SECTION 3 +#define STT_FILE 4 +#define STT_COMMON 5 +#define STT_TLS 6 + +#define VER_FLG_BASE 0x1 +#define VER_FLG_WEAK 0x2 + +#define ELF_ST_BIND (x) ((x) >> 4) +#define ELF_ST_TYPE (x) ((x) & 0xf) +#define ELF32_ST_BIND (x) ELF_ST_BIND(x) +#define ELF32_ST_TYPE (x) ELF_ST_TYPE(x) +#define ELF64_ST_BIND (x) ELF_ST_BIND(x) +#define ELF64_ST_TYPE (x) ELF_ST_TYPE(x) + +typedef struct { +Elf32_Sword d_tag; +union { +Elf32_Sword d_val; +Elf32_Addr d_ptr; + } d_un; +}Elf32_Dyn ; + +typedef struct { +Elf64_Sxword d_tag;/* entry tag value */ +union { +Elf64_Xword d_val; +Elf64_Addr d_ptr; + } d_un; +}Elf64_Dyn ; + +/* The following are used with relocations */ +#define ELF32_R_SYM (x) ((x) >> 8) +#define ELF32_R_TYPE (x) ((x) & 0xff) + +#define ELF64_R_SYM (i) ((i) >> 32) +#define ELF64_R_TYPE (i) ((i) & 0xffffffff) + +typedef struct elf32_rel { +Elf32_Addr r_offset; +Elf32_Word r_info; +}Elf32_Rel ; + +typedef struct elf64_rel { +Elf64_Addr r_offset;/* Location at which to apply the action */ +Elf64_Xword r_info;/* index and type of relocation */ +}Elf64_Rel ; + +typedef struct elf32_rela { +Elf32_Addr r_offset; +Elf32_Word r_info; +Elf32_Sword r_addend; +}Elf32_Rela ; + +typedef struct elf64_rela { +Elf64_Addr r_offset;/* Location at which to apply the action */ +Elf64_Xword r_info;/* index and type of relocation */ +Elf64_Sxword r_addend;/* Constant addend used to compute value */ +}Elf64_Rela ; + +typedef struct elf32_sym { +Elf32_Word st_name; +Elf32_Addr st_value; +Elf32_Word st_size; +unsigned char st_info; +unsigned char st_other; +Elf32_Half st_shndx; +}Elf32_Sym ; + +typedef struct elf64_sym { +Elf64_Word st_name;/* Symbol name, index in string tbl */ +unsigned char st_info;/* Type and binding attributes */ +unsigned char st_other;/* No defined meaning, 0 */ +Elf64_Half st_shndx;/* Associated section index */ +Elf64_Addr st_value;/* Value of the symbol */ +Elf64_Xword st_size;/* Associated symbol size */ +}Elf64_Sym ; + + +#define EI_NIDENT 16 + +typedef struct elf32_hdr { +unsigned char e_ident[EI_NIDENT ]; +Elf32_Half e_type; +Elf32_Half e_machine; +Elf32_Word e_version; +Elf32_Addr e_entry;/* Entry point */ +Elf32_Off e_phoff; +Elf32_Off e_shoff; +Elf32_Word e_flags; +Elf32_Half e_ehsize; +Elf32_Half e_phentsize; +Elf32_Half e_phnum; +Elf32_Half e_shentsize; +Elf32_Half e_shnum; +Elf32_Half e_shstrndx; +}Elf32_Ehdr ; + +typedef struct elf64_hdr { +unsigned char e_ident[EI_NIDENT ];/* ELF "magic number" */ +Elf64_Half e_type; +Elf64_Half e_machine; +Elf64_Word e_version; +Elf64_Addr e_entry;/* Entry point virtual address */ +Elf64_Off e_phoff;/* Program header table file offset */ +Elf64_Off e_shoff;/* Section header table file offset */ +Elf64_Word e_flags; +Elf64_Half e_ehsize; +Elf64_Half e_phentsize; +Elf64_Half e_phnum; +Elf64_Half e_shentsize; +Elf64_Half e_shnum; +Elf64_Half e_shstrndx; +}Elf64_Ehdr ; + +/* These constants define the permissions on sections in the program +header, p_flags. */ +#define PF_R 0x4 +#define PF_W 0x2 +#define PF_X 0x1 + +typedef struct elf32_phdr { +Elf32_Word p_type; +Elf32_Off p_offset; +Elf32_Addr p_vaddr; +Elf32_Addr p_paddr; +Elf32_Word p_filesz; +Elf32_Word p_memsz; +Elf32_Word p_flags; +Elf32_Word p_align; +}Elf32_Phdr ; + +typedef struct elf64_phdr { +Elf64_Word p_type; +Elf64_Word p_flags; +Elf64_Off p_offset;/* Segment file offset */ +Elf64_Addr p_vaddr;/* Segment virtual address */ +Elf64_Addr p_paddr;/* Segment physical address */ +Elf64_Xword p_filesz;/* Segment size in file */ +Elf64_Xword p_memsz;/* Segment size in memory */ +Elf64_Xword p_align;/* Segment alignment, file & memory */ +}Elf64_Phdr ; + +/* sh_type */ +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_NUM 12 +#define SHT_LOPROC 0x70000000 +#define SHT_HIPROC 0x7fffffff +#define SHT_LOUSER 0x80000000 +#define SHT_HIUSER 0xffffffff + +/* sh_flags */ +#define SHF_WRITE 0x1 +#define SHF_ALLOC 0x2 +#define SHF_EXECINSTR 0x4 +#define SHF_RELA_LIVEPATCH 0x00100000 +#define SHF_RO_AFTER_INIT 0x00200000 +#define SHF_MASKPROC 0xf0000000 + +/* special section indexes */ +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xff00 +#define SHN_LOPROC 0xff00 +#define SHN_HIPROC 0xff1f +#define SHN_LIVEPATCH 0xff20 +#define SHN_ABS 0xfff1 +#define SHN_COMMON 0xfff2 +#define SHN_HIRESERVE 0xffff + +typedef struct elf32_shdr { +Elf32_Word sh_name; +Elf32_Word sh_type; +Elf32_Word sh_flags; +Elf32_Addr sh_addr; +Elf32_Off sh_offset; +Elf32_Word sh_size; +Elf32_Word sh_link; +Elf32_Word sh_info; +Elf32_Word sh_addralign; +Elf32_Word sh_entsize; +}Elf32_Shdr ; + +typedef struct elf64_shdr { +Elf64_Word sh_name;/* Section name, index in string tbl */ +Elf64_Word sh_type;/* Type of section */ +Elf64_Xword sh_flags;/* Miscellaneous section attributes */ +Elf64_Addr sh_addr;/* Section virtual addr at execution */ +Elf64_Off sh_offset;/* Section file offset */ +Elf64_Xword sh_size;/* Size of section in bytes */ +Elf64_Word sh_link;/* Index of another section */ +Elf64_Word sh_info;/* Additional section information */ +Elf64_Xword sh_addralign;/* Section alignment */ +Elf64_Xword sh_entsize;/* Entry size if section holds table */ +}Elf64_Shdr ; + +#define EI_MAG0 0/* e_ident[] indexes */ +#define EI_MAG1 1 +#define EI_MAG2 2 +#define EI_MAG3 3 +#define EI_CLASS 4 +#define EI_DATA 5 +#define EI_VERSION 6 +#define EI_OSABI 7 +#define EI_PAD 8 + +#define ELFMAG0 0x7f/* EI_MAG */ +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' +#define ELFMAG "\177ELF" +#define SELFMAG 4 + +#define ELFCLASSNONE 0/* EI_CLASS */ +#define ELFCLASS32 1 +#define ELFCLASS64 2 +#define ELFCLASSNUM 3 + +#define ELFDATANONE 0/* e_ident[EI_DATA] */ +#define ELFDATA2LSB 1 +#define ELFDATA2MSB 2 + +#define EV_NONE 0/* e_version, EI_VERSION */ +#define EV_CURRENT 1 +#define EV_NUM 2 + +#define ELFOSABI_NONE 0 +#define ELFOSABI_LINUX 3 + +#ifndef ELF_OSABI +#define ELF_OSABI ELFOSABI_NONE +#endif + +/* +* Notes used in ET_CORE. Architectures export some of the arch register sets +* using the corresponding note types via the PTRACE_GETREGSET and +* PTRACE_SETREGSET requests. +* The note name for these types is "LINUX", except NT_PRFPREG that is named +* "CORE". +*/ +#define NT_PRSTATUS 1 +#define NT_PRFPREG 2 +#define NT_PRPSINFO 3 +#define NT_TASKSTRUCT 4 +#define NT_AUXV 6 +/* +* Note to userspace developers: size of NT_SIGINFO note may increase +* in the future to accomodate more fields, don't assume it is fixed! +*/ +#define NT_SIGINFO 0x53494749 +#define NT_FILE 0x46494c45 +#define NT_PRXFPREG 0x46e62b7f/* copied from gdb5.1/include/elf/common.h */ +#define NT_PPC_VMX 0x100/* PowerPC Altivec/VMX registers */ +#define NT_PPC_SPE 0x101/* PowerPC SPE/EVR registers */ +#define NT_PPC_VSX 0x102/* PowerPC VSX registers */ +#define NT_PPC_TAR 0x103/* Target Address Register */ +#define NT_PPC_PPR 0x104/* Program Priority Register */ +#define NT_PPC_DSCR 0x105/* Data Stream Control Register */ +#define NT_PPC_EBB 0x106/* Event Based Branch Registers */ +#define NT_PPC_PMU 0x107/* Performance Monitor Registers */ +#define NT_PPC_TM_CGPR 0x108/* TM checkpointed GPR Registers */ +#define NT_PPC_TM_CFPR 0x109/* TM checkpointed FPR Registers */ +#define NT_PPC_TM_CVMX 0x10a/* TM checkpointed VMX Registers */ +#define NT_PPC_TM_CVSX 0x10b/* TM checkpointed VSX Registers */ +#define NT_PPC_TM_SPR 0x10c/* TM Special Purpose Registers */ +#define NT_PPC_TM_CTAR 0x10d/* TM checkpointed Target Address Register */ +#define NT_PPC_TM_CPPR 0x10e/* TM checkpointed Program Priority Register */ +#define NT_PPC_TM_CDSCR 0x10f/* TM checkpointed Data Stream Control Register */ +#define NT_PPC_PKEY 0x110/* Memory Protection Keys registers */ +#define NT_PPC_DEXCR 0x111/* PowerPC DEXCR registers */ +#define NT_PPC_HASHKEYR 0x112/* PowerPC HASHKEYR register */ +#define NT_386_TLS 0x200/* i386 TLS slots (struct user_desc) */ +#define NT_386_IOPERM 0x201/* x86 io permission bitmap (1=deny) */ +#define NT_X86_XSTATE 0x202/* x86 extended state using xsave */ +/* Old binutils treats 0x203 as a CET state */ +#define NT_X86_SHSTK 0x204/* x86 SHSTK state */ +#define NT_X86_XSAVE_LAYOUT 0x205/* XSAVE layout description */ +#define NT_S390_HIGH_GPRS 0x300/* s390 upper register halves */ +#define NT_S390_TIMER 0x301/* s390 timer register */ +#define NT_S390_TODCMP 0x302/* s390 TOD clock comparator register */ +#define NT_S390_TODPREG 0x303/* s390 TOD programmable register */ +#define NT_S390_CTRS 0x304/* s390 control registers */ +#define NT_S390_PREFIX 0x305/* s390 prefix register */ +#define NT_S390_LAST_BREAK 0x306/* s390 breaking event address */ +#define NT_S390_SYSTEM_CALL 0x307/* s390 system call restart data */ +#define NT_S390_TDB 0x308/* s390 transaction diagnostic block */ +#define NT_S390_VXRS_LOW 0x309/* s390 vector registers 0-15 upper half */ +#define NT_S390_VXRS_HIGH 0x30a/* s390 vector registers 16-31 */ +#define NT_S390_GS_CB 0x30b/* s390 guarded storage registers */ +#define NT_S390_GS_BC 0x30c/* s390 guarded storage broadcast control block */ +#define NT_S390_RI_CB 0x30d/* s390 runtime instrumentation */ +#define NT_S390_PV_CPU_DATA 0x30e/* s390 protvirt cpu dump data */ +#define NT_ARM_VFP 0x400/* ARM VFP/NEON registers */ +#define NT_ARM_TLS 0x401/* ARM TLS register */ +#define NT_ARM_HW_BREAK 0x402/* ARM hardware breakpoint registers */ +#define NT_ARM_HW_WATCH 0x403/* ARM hardware watchpoint registers */ +#define NT_ARM_SYSTEM_CALL 0x404/* ARM system call number */ +#define NT_ARM_SVE 0x405/* ARM Scalable Vector Extension registers */ +#define NT_ARM_PAC_MASK 0x406/* ARM pointer authentication code masks */ +#define NT_ARM_PACA_KEYS 0x407/* ARM pointer authentication address keys */ +#define NT_ARM_PACG_KEYS 0x408/* ARM pointer authentication generic key */ +#define NT_ARM_TAGGED_ADDR_CTRL 0x409/* arm64 tagged address control (prctl()) */ +#define NT_ARM_PAC_ENABLED_KEYS 0x40a/* arm64 ptr auth enabled keys (prctl()) */ +#define NT_ARM_SSVE 0x40b/* ARM Streaming SVE registers */ +#define NT_ARM_ZA 0x40c/* ARM SME ZA registers */ +#define NT_ARM_ZT 0x40d/* ARM SME ZT registers */ +#define NT_ARM_FPMR 0x40e/* ARM floating point mode register */ +#define NT_ARM_POE 0x40f/* ARM POE registers */ +#define NT_ARM_GCS 0x410/* ARM GCS state */ +#define NT_ARC_V2 0x600/* ARCv2 accumulator/extra registers */ +#define NT_VMCOREDD 0x700/* Vmcore Device Dump Note */ +#define NT_MIPS_DSP 0x800/* MIPS DSP ASE registers */ +#define NT_MIPS_FP_MODE 0x801/* MIPS floating-point mode */ +#define NT_MIPS_MSA 0x802/* MIPS SIMD registers */ +#define NT_RISCV_CSR 0x900/* RISC-V Control and Status Registers */ +#define NT_RISCV_VECTOR 0x901/* RISC-V vector registers */ +#define NT_RISCV_TAGGED_ADDR_CTRL 0x902/* RISC-V tagged address control (prctl()) */ +#define NT_LOONGARCH_CPUCFG 0xa00/* LoongArch CPU config registers */ +#define NT_LOONGARCH_CSR 0xa01/* LoongArch control and status registers */ +#define NT_LOONGARCH_LSX 0xa02/* LoongArch Loongson SIMD Extension registers */ +#define NT_LOONGARCH_LASX 0xa03/* LoongArch Loongson Advanced SIMD Extension registers */ +#define NT_LOONGARCH_LBT 0xa04/* LoongArch Loongson Binary Translation registers */ +#define NT_LOONGARCH_HW_BREAK 0xa05/* LoongArch hardware breakpoint registers */ +#define NT_LOONGARCH_HW_WATCH 0xa06/* LoongArch hardware watchpoint registers */ + +/* Note types with note name "GNU" */ +#define NT_GNU_PROPERTY_TYPE_0 5 + +/* Note header in a PT_NOTE section */ +typedef struct elf32_note { +Elf32_Word n_namesz;/* Name size */ +Elf32_Word n_descsz;/* Content size */ +Elf32_Word n_type;/* Content type */ +}Elf32_Nhdr ; + +/* Note header in a PT_NOTE section */ +typedef struct elf64_note { +Elf64_Word n_namesz;/* Name size */ +Elf64_Word n_descsz;/* Content size */ +Elf64_Word n_type;/* Content type */ +}Elf64_Nhdr ; + +/* .note.gnu.property types for EM_AARCH64: */ +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 + +/* Bits for GNU_PROPERTY_AARCH64_FEATURE_1_BTI */ +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) + +typedef struct { +Elf32_Half vd_version; +Elf32_Half vd_flags; +Elf32_Half vd_ndx; +Elf32_Half vd_cnt; +Elf32_Word vd_hash; +Elf32_Word vd_aux; +Elf32_Word vd_next; +}Elf32_Verdef ; + +typedef struct { +Elf64_Half vd_version; +Elf64_Half vd_flags; +Elf64_Half vd_ndx; +Elf64_Half vd_cnt; +Elf64_Word vd_hash; +Elf64_Word vd_aux; +Elf64_Word vd_next; +}Elf64_Verdef ; + +typedef struct { +Elf32_Word vda_name; +Elf32_Word vda_next; +}Elf32_Verdaux ; + +typedef struct { +Elf64_Word vda_name; +Elf64_Word vda_next; +}Elf64_Verdaux ; + +#endif /* _LINUX_ELF_H */
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] tools/include: Add uapi/linux/elf.h
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 626fd35278295fbb21f2da331cd8028e9738d965 Gitweb: https://git.kernel.org/tip/626fd35278295fbb21f2da331cd8028e9738d965 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:46 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:12 +01:00
tools/include: Add uapi/linux/elf.h
It will be used by the vDSO selftests.
--- tools/include/uapi/linux/elf.h | 524 ++++++++++++++++++++++++++++++++- 1 file changed, 524 insertions(+) create mode 100644 tools/include/uapi/linux/elf.h
tools/include/uapi/linux/elf.h new file +524 -0
@@ -0,0 +1,524 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_ELF_H +#define _LINUX_ELF_H + +#include <linux/types.h> +#include <linux/elf-em.h> + +/* 32-bit ELF base types. */ +typedef __u32 Elf32_Addr ; +typedef __u16 Elf32_Half ; +typedef __u32 Elf32_Off ; +typedef __s32 Elf32_Sword ; +typedef __u32 Elf32_Word ; +typedef __u16 Elf32_Versym ; + +/* 64-bit ELF base types. */ +typedef __u64 Elf64_Addr ; +typedef __u16 Elf64_Half ; +typedef __s16 Elf64_SHalf ; +typedef __u64 Elf64_Off ; +typedef __s32 Elf64_Sword ; +typedef __u32 Elf64_Word ; +typedef __u64 Elf64_Xword ; +typedef __s64 Elf64_Sxword ; +typedef __u16 Elf64_Versym ; + +/* These constants are for the segment types stored in the image headers */ +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +#define PT_INTERP 3 +#define PT_NOTE 4 +#define PT_SHLIB 5 +#define PT_PHDR 6 +#define PT_TLS 7/* Thread local storage segment */ +#define PT_LOOS 0x60000000/* OS-specific */ +#define PT_HIOS 0x6fffffff/* OS-specific */ +#define PT_LOPROC 0x70000000 +#define PT_HIPROC 0x7fffffff +#define PT_GNU_EH_FRAME (PT_LOOS + 0x474e550) +#define PT_GNU_STACK (PT_LOOS + 0x474e551) +#define PT_GNU_RELRO (PT_LOOS + 0x474e552) +#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) + + +/* ARM MTE memory tag segment type */ +#define PT_AARCH64_MEMTAG_MTE (PT_LOPROC + 0x2) + +/* +* Extended Numbering +* +* If the real number of program header table entries is larger than +* or equal to PN_XNUM(0xffff), it is set to sh_info field of the +* section header at index 0, and PN_XNUM is set to e_phnum +* field. Otherwise, the section header at index 0 is zero +* initialized, if it exists. +* +* Specifications are available in: +* +* - Oracle: Linker and Libraries. +* Part No: 817–1984–19, August 2011. +* https://docs.oracle.com/cd/E18752_01/pdf/817-1984.pdf +* +* - System V ABI AMD64 Architecture Processor Supplement +* Draft Version 0.99.4, +* January 13, 2010. +* http://www.cs.washington.edu/education/courses/cse351/12wi/supp-docs/abi.pdf +*/ +#define PN_XNUM 0xffff + +/* These constants define the different elf file types */ +#define ET_NONE 0 +#define ET_REL 1 +#define ET_EXEC 2 +#define ET_DYN 3 +#define ET_CORE 4 +#define ET_LOPROC 0xff00 +#define ET_HIPROC 0xffff + +/* This is the info that is needed to parse the dynamic section of the file */ +#define DT_NULL 0 +#define DT_NEEDED 1 +#define DT_PLTRELSZ 2 +#define DT_PLTGOT 3 +#define DT_HASH 4 +#define DT_STRTAB 5 +#define DT_SYMTAB 6 +#define DT_RELA 7 +#define DT_RELASZ 8 +#define DT_RELAENT 9 +#define DT_STRSZ 10 +#define DT_SYMENT 11 +#define DT_INIT 12 +#define DT_FINI 13 +#define DT_SONAME 14 +#define DT_RPATH 15 +#define DT_SYMBOLIC 16 +#define DT_REL 17 +#define DT_RELSZ 18 +#define DT_RELENT 19 +#define DT_PLTREL 20 +#define DT_DEBUG 21 +#define DT_TEXTREL 22 +#define DT_JMPREL 23 +#define DT_ENCODING 32 +#define OLD_DT_LOOS 0x60000000 +#define DT_LOOS 0x6000000d +#define DT_HIOS 0x6ffff000 +#define DT_VALRNGLO 0x6ffffd00 +#define DT_VALRNGHI 0x6ffffdff +#define DT_ADDRRNGLO 0x6ffffe00 +#define DT_GNU_HASH 0x6ffffef5 +#define DT_ADDRRNGHI 0x6ffffeff +#define DT_VERSYM 0x6ffffff0 +#define DT_RELACOUNT 0x6ffffff9 +#define DT_RELCOUNT 0x6ffffffa +#define DT_FLAGS_1 0x6ffffffb +#define DT_VERDEF 0x6ffffffc +#define DT_VERDEFNUM 0x6ffffffd +#define DT_VERNEED 0x6ffffffe +#define DT_VERNEEDNUM 0x6fffffff +#define OLD_DT_HIOS 0x6fffffff +#define DT_LOPROC 0x70000000 +#define DT_HIPROC 0x7fffffff + +/* This info is needed when parsing the symbol table */ +#define STB_LOCAL 0 +#define STB_GLOBAL 1 +#define STB_WEAK 2 + +#define STN_UNDEF 0 + +#define STT_NOTYPE 0 +#define STT_OBJECT 1 +#define STT_FUNC 2 +#define STT_SECTION 3 +#define STT_FILE 4 +#define STT_COMMON 5 +#define STT_TLS 6 + +#define VER_FLG_BASE 0x1 +#define VER_FLG_WEAK 0x2 + +#define ELF_ST_BIND (x) ((x) >> 4) +#define ELF_ST_TYPE (x) ((x) & 0xf) +#define ELF32_ST_BIND (x) ELF_ST_BIND(x) +#define ELF32_ST_TYPE (x) ELF_ST_TYPE(x) +#define ELF64_ST_BIND (x) ELF_ST_BIND(x) +#define ELF64_ST_TYPE (x) ELF_ST_TYPE(x) + +typedef struct { +Elf32_Sword d_tag; +union { +Elf32_Sword d_val; +Elf32_Addr d_ptr; + } d_un; +}Elf32_Dyn ; + +typedef struct { +Elf64_Sxword d_tag;/* entry tag value */ +union { +Elf64_Xword d_val; +Elf64_Addr d_ptr; + } d_un; +}Elf64_Dyn ; + +/* The following are used with relocations */ +#define ELF32_R_SYM (x) ((x) >> 8) +#define ELF32_R_TYPE (x) ((x) & 0xff) + +#define ELF64_R_SYM (i) ((i) >> 32) +#define ELF64_R_TYPE (i) ((i) & 0xffffffff) + +typedef struct elf32_rel { +Elf32_Addr r_offset; +Elf32_Word r_info; +}Elf32_Rel ; + +typedef struct elf64_rel { +Elf64_Addr r_offset;/* Location at which to apply the action */ +Elf64_Xword r_info;/* index and type of relocation */ +}Elf64_Rel ; + +typedef struct elf32_rela { +Elf32_Addr r_offset; +Elf32_Word r_info; +Elf32_Sword r_addend; +}Elf32_Rela ; + +typedef struct elf64_rela { +Elf64_Addr r_offset;/* Location at which to apply the action */ +Elf64_Xword r_info;/* index and type of relocation */ +Elf64_Sxword r_addend;/* Constant addend used to compute value */ +}Elf64_Rela ; + +typedef struct elf32_sym { +Elf32_Word st_name; +Elf32_Addr st_value; +Elf32_Word st_size; +unsigned char st_info; +unsigned char st_other; +Elf32_Half st_shndx; +}Elf32_Sym ; + +typedef struct elf64_sym { +Elf64_Word st_name;/* Symbol name, index in string tbl */ +unsigned char st_info;/* Type and binding attributes */ +unsigned char st_other;/* No defined meaning, 0 */ +Elf64_Half st_shndx;/* Associated section index */ +Elf64_Addr st_value;/* Value of the symbol */ +Elf64_Xword st_size;/* Associated symbol size */ +}Elf64_Sym ; + + +#define EI_NIDENT 16 + +typedef struct elf32_hdr { +unsigned char e_ident[EI_NIDENT ]; +Elf32_Half e_type; +Elf32_Half e_machine; +Elf32_Word e_version; +Elf32_Addr e_entry;/* Entry point */ +Elf32_Off e_phoff; +Elf32_Off e_shoff; +Elf32_Word e_flags; +Elf32_Half e_ehsize; +Elf32_Half e_phentsize; +Elf32_Half e_phnum; +Elf32_Half e_shentsize; +Elf32_Half e_shnum; +Elf32_Half e_shstrndx; +}Elf32_Ehdr ; + +typedef struct elf64_hdr { +unsigned char e_ident[EI_NIDENT ];/* ELF "magic number" */ +Elf64_Half e_type; +Elf64_Half e_machine; +Elf64_Word e_version; +Elf64_Addr e_entry;/* Entry point virtual address */ +Elf64_Off e_phoff;/* Program header table file offset */ +Elf64_Off e_shoff;/* Section header table file offset */ +Elf64_Word e_flags; +Elf64_Half e_ehsize; +Elf64_Half e_phentsize; +Elf64_Half e_phnum; +Elf64_Half e_shentsize; +Elf64_Half e_shnum; +Elf64_Half e_shstrndx; +}Elf64_Ehdr ; + +/* These constants define the permissions on sections in the program +header, p_flags. */ +#define PF_R 0x4 +#define PF_W 0x2 +#define PF_X 0x1 + +typedef struct elf32_phdr { +Elf32_Word p_type; +Elf32_Off p_offset; +Elf32_Addr p_vaddr; +Elf32_Addr p_paddr; +Elf32_Word p_filesz; +Elf32_Word p_memsz; +Elf32_Word p_flags; +Elf32_Word p_align; +}Elf32_Phdr ; + +typedef struct elf64_phdr { +Elf64_Word p_type; +Elf64_Word p_flags; +Elf64_Off p_offset;/* Segment file offset */ +Elf64_Addr p_vaddr;/* Segment virtual address */ +Elf64_Addr p_paddr;/* Segment physical address */ +Elf64_Xword p_filesz;/* Segment size in file */ +Elf64_Xword p_memsz;/* Segment size in memory */ +Elf64_Xword p_align;/* Segment alignment, file & memory */ +}Elf64_Phdr ; + +/* sh_type */ +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_NUM 12 +#define SHT_LOPROC 0x70000000 +#define SHT_HIPROC 0x7fffffff +#define SHT_LOUSER 0x80000000 +#define SHT_HIUSER 0xffffffff + +/* sh_flags */ +#define SHF_WRITE 0x1 +#define SHF_ALLOC 0x2 +#define SHF_EXECINSTR 0x4 +#define SHF_RELA_LIVEPATCH 0x00100000 +#define SHF_RO_AFTER_INIT 0x00200000 +#define SHF_MASKPROC 0xf0000000 + +/* special section indexes */ +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xff00 +#define SHN_LOPROC 0xff00 +#define SHN_HIPROC 0xff1f +#define SHN_LIVEPATCH 0xff20 +#define SHN_ABS 0xfff1 +#define SHN_COMMON 0xfff2 +#define SHN_HIRESERVE 0xffff + +typedef struct elf32_shdr { +Elf32_Word sh_name; +Elf32_Word sh_type; +Elf32_Word sh_flags; +Elf32_Addr sh_addr; +Elf32_Off sh_offset; +Elf32_Word sh_size; +Elf32_Word sh_link; +Elf32_Word sh_info; +Elf32_Word sh_addralign; +Elf32_Word sh_entsize; +}Elf32_Shdr ; + +typedef struct elf64_shdr { +Elf64_Word sh_name;/* Section name, index in string tbl */ +Elf64_Word sh_type;/* Type of section */ +Elf64_Xword sh_flags;/* Miscellaneous section attributes */ +Elf64_Addr sh_addr;/* Section virtual addr at execution */ +Elf64_Off sh_offset;/* Section file offset */ +Elf64_Xword sh_size;/* Size of section in bytes */ +Elf64_Word sh_link;/* Index of another section */ +Elf64_Word sh_info;/* Additional section information */ +Elf64_Xword sh_addralign;/* Section alignment */ +Elf64_Xword sh_entsize;/* Entry size if section holds table */ +}Elf64_Shdr ; + +#define EI_MAG0 0/* e_ident[] indexes */ +#define EI_MAG1 1 +#define EI_MAG2 2 +#define EI_MAG3 3 +#define EI_CLASS 4 +#define EI_DATA 5 +#define EI_VERSION 6 +#define EI_OSABI 7 +#define EI_PAD 8 + +#define ELFMAG0 0x7f/* EI_MAG */ +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' +#define ELFMAG "\177ELF" +#define SELFMAG 4 + +#define ELFCLASSNONE 0/* EI_CLASS */ +#define ELFCLASS32 1 +#define ELFCLASS64 2 +#define ELFCLASSNUM 3 + +#define ELFDATANONE 0/* e_ident[EI_DATA] */ +#define ELFDATA2LSB 1 +#define ELFDATA2MSB 2 + +#define EV_NONE 0/* e_version, EI_VERSION */ +#define EV_CURRENT 1 +#define EV_NUM 2 + +#define ELFOSABI_NONE 0 +#define ELFOSABI_LINUX 3 + +#ifndef ELF_OSABI +#define ELF_OSABI ELFOSABI_NONE +#endif + +/* +* Notes used in ET_CORE. Architectures export some of the arch register sets +* using the corresponding note types via the PTRACE_GETREGSET and +* PTRACE_SETREGSET requests. +* The note name for these types is "LINUX", except NT_PRFPREG that is named +* "CORE". +*/ +#define NT_PRSTATUS 1 +#define NT_PRFPREG 2 +#define NT_PRPSINFO 3 +#define NT_TASKSTRUCT 4 +#define NT_AUXV 6 +/* +* Note to userspace developers: size of NT_SIGINFO note may increase +* in the future to accomodate more fields, don't assume it is fixed! +*/ +#define NT_SIGINFO 0x53494749 +#define NT_FILE 0x46494c45 +#define NT_PRXFPREG 0x46e62b7f/* copied from gdb5.1/include/elf/common.h */ +#define NT_PPC_VMX 0x100/* PowerPC Altivec/VMX registers */ +#define NT_PPC_SPE 0x101/* PowerPC SPE/EVR registers */ +#define NT_PPC_VSX 0x102/* PowerPC VSX registers */ +#define NT_PPC_TAR 0x103/* Target Address Register */ +#define NT_PPC_PPR 0x104/* Program Priority Register */ +#define NT_PPC_DSCR 0x105/* Data Stream Control Register */ +#define NT_PPC_EBB 0x106/* Event Based Branch Registers */ +#define NT_PPC_PMU 0x107/* Performance Monitor Registers */ +#define NT_PPC_TM_CGPR 0x108/* TM checkpointed GPR Registers */ +#define NT_PPC_TM_CFPR 0x109/* TM checkpointed FPR Registers */ +#define NT_PPC_TM_CVMX 0x10a/* TM checkpointed VMX Registers */ +#define NT_PPC_TM_CVSX 0x10b/* TM checkpointed VSX Registers */ +#define NT_PPC_TM_SPR 0x10c/* TM Special Purpose Registers */ +#define NT_PPC_TM_CTAR 0x10d/* TM checkpointed Target Address Register */ +#define NT_PPC_TM_CPPR 0x10e/* TM checkpointed Program Priority Register */ +#define NT_PPC_TM_CDSCR 0x10f/* TM checkpointed Data Stream Control Register */ +#define NT_PPC_PKEY 0x110/* Memory Protection Keys registers */ +#define NT_PPC_DEXCR 0x111/* PowerPC DEXCR registers */ +#define NT_PPC_HASHKEYR 0x112/* PowerPC HASHKEYR register */ +#define NT_386_TLS 0x200/* i386 TLS slots (struct user_desc) */ +#define NT_386_IOPERM 0x201/* x86 io permission bitmap (1=deny) */ +#define NT_X86_XSTATE 0x202/* x86 extended state using xsave */ +/* Old binutils treats 0x203 as a CET state */ +#define NT_X86_SHSTK 0x204/* x86 SHSTK state */ +#define NT_X86_XSAVE_LAYOUT 0x205/* XSAVE layout description */ +#define NT_S390_HIGH_GPRS 0x300/* s390 upper register halves */ +#define NT_S390_TIMER 0x301/* s390 timer register */ +#define NT_S390_TODCMP 0x302/* s390 TOD clock comparator register */ +#define NT_S390_TODPREG 0x303/* s390 TOD programmable register */ +#define NT_S390_CTRS 0x304/* s390 control registers */ +#define NT_S390_PREFIX 0x305/* s390 prefix register */ +#define NT_S390_LAST_BREAK 0x306/* s390 breaking event address */ +#define NT_S390_SYSTEM_CALL 0x307/* s390 system call restart data */ +#define NT_S390_TDB 0x308/* s390 transaction diagnostic block */ +#define NT_S390_VXRS_LOW 0x309/* s390 vector registers 0-15 upper half */ +#define NT_S390_VXRS_HIGH 0x30a/* s390 vector registers 16-31 */ +#define NT_S390_GS_CB 0x30b/* s390 guarded storage registers */ +#define NT_S390_GS_BC 0x30c/* s390 guarded storage broadcast control block */ +#define NT_S390_RI_CB 0x30d/* s390 runtime instrumentation */ +#define NT_S390_PV_CPU_DATA 0x30e/* s390 protvirt cpu dump data */ +#define NT_ARM_VFP 0x400/* ARM VFP/NEON registers */ +#define NT_ARM_TLS 0x401/* ARM TLS register */ +#define NT_ARM_HW_BREAK 0x402/* ARM hardware breakpoint registers */ +#define NT_ARM_HW_WATCH 0x403/* ARM hardware watchpoint registers */ +#define NT_ARM_SYSTEM_CALL 0x404/* ARM system call number */ +#define NT_ARM_SVE 0x405/* ARM Scalable Vector Extension registers */ +#define NT_ARM_PAC_MASK 0x406/* ARM pointer authentication code masks */ +#define NT_ARM_PACA_KEYS 0x407/* ARM pointer authentication address keys */ +#define NT_ARM_PACG_KEYS 0x408/* ARM pointer authentication generic key */ +#define NT_ARM_TAGGED_ADDR_CTRL 0x409/* arm64 tagged address control (prctl()) */ +#define NT_ARM_PAC_ENABLED_KEYS 0x40a/* arm64 ptr auth enabled keys (prctl()) */ +#define NT_ARM_SSVE 0x40b/* ARM Streaming SVE registers */ +#define NT_ARM_ZA 0x40c/* ARM SME ZA registers */ +#define NT_ARM_ZT 0x40d/* ARM SME ZT registers */ +#define NT_ARM_FPMR 0x40e/* ARM floating point mode register */ +#define NT_ARM_POE 0x40f/* ARM POE registers */ +#define NT_ARM_GCS 0x410/* ARM GCS state */ +#define NT_ARC_V2 0x600/* ARCv2 accumulator/extra registers */ +#define NT_VMCOREDD 0x700/* Vmcore Device Dump Note */ +#define NT_MIPS_DSP 0x800/* MIPS DSP ASE registers */ +#define NT_MIPS_FP_MODE 0x801/* MIPS floating-point mode */ +#define NT_MIPS_MSA 0x802/* MIPS SIMD registers */ +#define NT_RISCV_CSR 0x900/* RISC-V Control and Status Registers */ +#define NT_RISCV_VECTOR 0x901/* RISC-V vector registers */ +#define NT_RISCV_TAGGED_ADDR_CTRL 0x902/* RISC-V tagged address control (prctl()) */ +#define NT_LOONGARCH_CPUCFG 0xa00/* LoongArch CPU config registers */ +#define NT_LOONGARCH_CSR 0xa01/* LoongArch control and status registers */ +#define NT_LOONGARCH_LSX 0xa02/* LoongArch Loongson SIMD Extension registers */ +#define NT_LOONGARCH_LASX 0xa03/* LoongArch Loongson Advanced SIMD Extension registers */ +#define NT_LOONGARCH_LBT 0xa04/* LoongArch Loongson Binary Translation registers */ +#define NT_LOONGARCH_HW_BREAK 0xa05/* LoongArch hardware breakpoint registers */ +#define NT_LOONGARCH_HW_WATCH 0xa06/* LoongArch hardware watchpoint registers */ + +/* Note types with note name "GNU" */ +#define NT_GNU_PROPERTY_TYPE_0 5 + +/* Note header in a PT_NOTE section */ +typedef struct elf32_note { +Elf32_Word n_namesz;/* Name size */ +Elf32_Word n_descsz;/* Content size */ +Elf32_Word n_type;/* Content type */ +}Elf32_Nhdr ; + +/* Note header in a PT_NOTE section */ +typedef struct elf64_note { +Elf64_Word n_namesz;/* Name size */ +Elf64_Word n_descsz;/* Content size */ +Elf64_Word n_type;/* Content type */ +}Elf64_Nhdr ; + +/* .note.gnu.property types for EM_AARCH64: */ +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 + +/* Bits for GNU_PROPERTY_AARCH64_FEATURE_1_BTI */ +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0) + +typedef struct { +Elf32_Half vd_version; +Elf32_Half vd_flags; +Elf32_Half vd_ndx; +Elf32_Half vd_cnt; +Elf32_Word vd_hash; +Elf32_Word vd_aux; +Elf32_Word vd_next; +}Elf32_Verdef ; + +typedef struct { +Elf64_Half vd_version; +Elf64_Half vd_flags; +Elf64_Half vd_ndx; +Elf64_Half vd_cnt; +Elf64_Word vd_hash; +Elf64_Word vd_aux; +Elf64_Word vd_next; +}Elf64_Verdef ; + +typedef struct { +Elf32_Word vda_name; +Elf32_Word vda_next; +}Elf32_Verdaux ; + +typedef struct { +Elf64_Word vda_name; +Elf64_Word vda_next; +}Elf64_Verdaux ; + +#endif /* _LINUX_ELF_H */
PATCH v2 8/16 selftests: Add headers target
In reply to Thomas WeißschuhSome selftests need access to a full UAPI headers tree, for example when building with nolibc which heavily relies on UAPI headers.
A reference to such a tree is available in the KHDR_INCLUDES variable, but there is currently no way to populate such a tree automatically.
Provide a target that the tests can depend on to get access to usable UAPI headers.
--- tools/testing/selftests/lib.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/lib.mk +4 -1
@@ -228,4 +228,7 @@ $(OUTPUT)/%:%.S $(LINK.S) $^ $(LDLIBS) -o $@ endif -.PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir +headers: + $(Q)$(MAKE) -C $(top_srcdir) headers + +.PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir headers
Signature · 1 line
2.48.1
Re: [PATCH v2 08/16] selftests: Add headers target
Quoted 9 lines · Thomas Weißschuh
Some selftests need access to a full UAPI headers tree, for example when building with nolibc which heavily relies on UAPI headers.
A reference to such a tree is available in theKHDR_INCLUDESvariable, but there is currently no way to populate such a tree automatically.Provide a target that the tests can depend on to get access to usable UAPI headers.
Signed-off-by Thomas Weißschuh <[email protected]>
Quoted 18 lines
--- tools/testing/selftests/lib.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/testing/selftests/lib.mk +4
-1@@ -228,4 +228,7 @@ $(OUTPUT)/%:%.S $(LINK.S) $^ $(LDLIBS) -o $@ endif -.PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir +headers: + $(Q)$(MAKE) -C $(top_srcdir) headers + +.PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir headers
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] selftests: Add headers target
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 1a59f5d31569c742da3dafbbb5620901de11a245 Gitweb: https://git.kernel.org/tip/1a59f5d31569c742da3dafbbb5620901de11a245 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:47 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:12 +01:00
selftests: Add headers target
Some selftests need access to a full UAPI headers tree, for example when building with nolibc which heavily relies on UAPI headers.
A reference to such a tree is available in the KHDR_INCLUDES variable, but there is currently no way to populate such a tree automatically.
Provide a target that the tests can depend on to get access to usable UAPI headers.
--- tools/testing/selftests/lib.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/lib.mk +4 -1
@@ -228,4 +228,7 @@ $(OUTPUT)/%:%.S $(LINK.S) $^ $(LDLIBS) -o $@ endif -.PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir +headers: + $(Q)$(MAKE) -C $(top_srcdir) headers + +.PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir headers
PATCH v2 9/16 tools/nolibc: add limits.h shim header
In reply to Thomas Weißschuhlimits.h is a widely used standard header.
Missing it from nolibc requires adoption effort to port applications.
Add a shim header which includes the global nolibc.h header. It makes all nolibc symbols available.
--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/limits.h | 7 +++++++ 2 files changed, 8 insertions(+)
tools/include/nolibc/Makefile +1 -0
@@ -30,6 +30,7 @@ all_files := \ crt.h \ ctype.h \ errno.h \ + limits.h \ nolibc.h \ signal.h \ stackprotector.h \
tools/include/nolibc/limits.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* Shim limits.h header for NOLIBC. +* Copyright (C) 2025 Thomas Weißschuh <[email protected]> +*/ + +#include "nolibc.h"
Signature · 1 line
2.48.1
Re: [PATCH v2 09/16] tools/nolibc: add limits.h shim header
Quoted 7 lines · Thomas Weißschuh
limits.his a widely used standard header.
Missing it from nolibc requires adoption effort to port applications.Add a shim header which includes the global
nolibc.hheader. It makes all nolibc symbols available.Signed-off-by Thomas Weißschuh <[email protected]>
Quoted 31 lines
--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/limits.h | 7 +++++++ 2 files changed, 8 insertions(+)tools/include/nolibc/Makefile +1
-0@@ -30,6 +30,7 @@ all_files := \ crt.h \ ctype.h \ errno.h \ + limits.h \ nolibc.h \ signal.h \ stackprotector.h \tools/include/nolibc/limits.h new file +7
-0@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* Shim limits.h header for NOLIBC. +* Copyright (C) 2025 Thomas Weißschuh <[email protected]> +*/ + +#include "nolibc.h"
Signature · 2 lines
Regards, Vincenzo
Re: [PATCH v2 09/16] tools/nolibc: add limits.h shim header
In reply to Thomas WeißschuhQuoted 7 lines · Thomas Weißschuh
limits.his a widely used standard header.
Missing it from nolibc requires adoption effort to port applications.Add a shim header which includes the global
nolibc.hheader. It makes all nolibc symbols available.Signed-off-by Thomas Weißschuh <[email protected]>
Works fine here. Pick any combination you'd like of those below ;-)
Thanks!
Willy
[tip: timers/vdso] tools/nolibc: add limits.h shim header
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 5caaa0aa7c61513a2f606fd6d00fc29ae475ce9e Gitweb: https://git.kernel.org/tip/5caaa0aa7c61513a2f606fd6d00fc29ae475ce9e Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:48 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:12 +01:00
tools/nolibc: add limits.h shim header
limits.h is a widely used standard header. Missing it from nolibc requires adoption effort to port applications.
Add a shim header which includes the global nolibc.h header. It makes all nolibc symbols available.
--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/limits.h | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 tools/include/nolibc/limits.h
tools/include/nolibc/Makefile +1 -0
@@ -30,6 +30,7 @@ all_files := \ crt.h \ ctype.h \ errno.h \ + limits.h \ nolibc.h \ signal.h \ stackprotector.h \
tools/include/nolibc/limits.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* +* Shim limits.h header for NOLIBC. +* Copyright (C) 2025 Thomas Weißschuh <[email protected]> +*/ + +#include "nolibc.h"
PATCH v2 10/16 selftests: vDSO: vdso_standalone_test_x86: Use vdso_init_form_sysinfo_ehdr
In reply to Thomas Weißschuhvdso_standalone_test_x86 is the only user of vdso_init_from_auxv(). Instead of combining the parsing the aux vector with the parsing of the vDSO, split them apart into getauxval() and the regular vdso_init_from_sysinfo_ehdr().
The implementation of getauxval() is taken fromtools/include/nolibc/stdlib.h.
---
All of this code will be deleted later again.
--- .../selftests/vDSO/vdso_standalone_test_x86.c | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
tools/testing/selftests/vDSO/vdso_standalone_test_x86.c +26 -1
@@ -15,6 +15,7 @@#include <sys/time.h> #include <unistd.h> #include <stdint.h> +#include <linux/auxvec.h> #include "parse_vdso.h"
@@ -84,6 +85,30 @@ void to_base10(char *lastdig, time_t n) } } +unsigned long getauxval (const unsigned long *auxv,unsigned long type) +{ +unsigned long ret; + +if (!auxv) +return 0 ; + +while (1 ) { +if (!auxv[0 ] && !auxv[1 ]) { + ret =0 ; +break ; + } + +if (auxv[0 ] == type) { + ret = auxv[1 ]; +break ; + } + + auxv +=2 ; + } + +return ret; +} +void c_main (void **stack) {/* Parse the stack */
@@ -96,7 +121,7 @@ void c_main(void **stack) stack++;/* Now we're pointing at auxv. Initialize the vDSO parser. */ -vdso_init_from_auxv ((void *)stack); +vdso_init_from_sysinfo_ehdr (getauxval ((unsigned long *)stack,AT_SYSINFO_EHDR ));/* Find gettimeofday. */ typedef long (*gtod_t )(struct timeval *tv,struct timezone *tz);
Signature · 1 line
2.48.1
Re: [PATCH v2 10/16] selftests: vDSO: vdso_standalone_test_x86: Use vdso_init_form_sysinfo_ehdr
Quoted 10 lines · Thomas Weißschuh
vdso_standalone_test_x86is the only user ofvdso_init_from_auxv(). Instead of combining the parsing the aux vector with the parsing of the vDSO, split them apart intogetauxval()and the regularvdso_init_from_sysinfo_ehdr().The implementation of
getauxval()is taken fromtools/include/nolibc/stdlib.h.Signed-off-by Thomas Weißschuh <[email protected]>
Quoted 59 lines
---
All of this code will be deleted later again.--- .../selftests/vDSO/vdso_standalone_test_x86.c | 27 +++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)tools/testing/selftests/vDSO/vdso_standalone_test_x86.c +26
-1@@ -15,6 +15,7 @@#include <sys/time.h> #include <unistd.h> #include <stdint.h> +#include <linux/auxvec.h> #include "parse_vdso.h" @@ -84,6 +85,30 @@ void to_base10(char *lastdig, time_t n) } } +unsigned long getauxval (const unsigned long *auxv,unsigned long type) +{ +unsigned long ret; + +if (!auxv) +return 0 ; + +while (1 ) { +if (!auxv[0 ] && !auxv[1 ]) { + ret =0 ; +break ; + } + +if (auxv[0 ] == type) { + ret = auxv[1 ]; +break ; + } + + auxv +=2 ; + } + +return ret; +} +void c_main (void **stack) {/* Parse the stack */ @@ -96,7 +121,7 @@ void c_main(void **stack) stack++;/* Now we're pointing at auxv. Initialize the vDSO parser. */ -vdso_init_from_auxv ((void *)stack); +vdso_init_from_sysinfo_ehdr (getauxval ((unsigned long *)stack,AT_SYSINFO_EHDR ));/* Find gettimeofday. */ typedef long (*gtod_t )(struct timeval *tv,struct timezone *tz);
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] selftests: vDSO: vdso_standalone_test_x86: Use vdso_init_form_sysinfo_ehdr
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 05c204acf5131740f5f4e193c9749b92da4bcb16 Gitweb: https://git.kernel.org/tip/05c204acf5131740f5f4e193c9749b92da4bcb16 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:49 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:12 +01:00
selftests: vDSO: vdso_standalone_test_x86: Use vdso_init_form_sysinfo_ehdr
vdso_standalone_test_x86 is the only user of vdso_init_from_auxv(). Instead of combining the parsing the aux vector with the parsing of the vDSO, split them apart into getauxval() and the regular vdso_init_from_sysinfo_ehdr().
The implementation of getauxval() is taken fromtools/include/nolibc/stdlib.h.
--- tools/testing/selftests/vDSO/vdso_standalone_test_x86.c | 27 +++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
tools/testing/selftests/vDSO/vdso_standalone_test_x86.c +26 -1
@@ -15,6 +15,7 @@#include <sys/time.h> #include <unistd.h> #include <stdint.h> +#include <linux/auxvec.h> #include "parse_vdso.h"
@@ -84,6 +85,30 @@ void to_base10(char *lastdig, time_t n) } } +unsigned long getauxval (const unsigned long *auxv,unsigned long type) +{ +unsigned long ret; + +if (!auxv) +return 0 ; + +while (1 ) { +if (!auxv[0 ] && !auxv[1 ]) { + ret =0 ; +break ; + } + +if (auxv[0 ] == type) { + ret = auxv[1 ]; +break ; + } + + auxv +=2 ; + } + +return ret; +} +void c_main (void **stack) {/* Parse the stack */
@@ -96,7 +121,7 @@ void c_main(void **stack) stack++;/* Now we're pointing at auxv. Initialize the vDSO parser. */ -vdso_init_from_auxv ((void *)stack); +vdso_init_from_sysinfo_ehdr (getauxval ((unsigned long *)stack,AT_SYSINFO_EHDR ));/* Find gettimeofday. */ typedef long (*gtod_t )(struct timeval *tv,struct timezone *tz);
PATCH v2 11/16 selftests: vDSO: parse_vdso: Drop vdso_init_from_auxv()
In reply to Thomas WeißschuhThere are no users left.
This also removes the usage of ElfXX_auxv_t,
which is not formally standardized.
--- tools/testing/selftests/vDSO/parse_vdso.c | 14 -------------- tools/testing/selftests/vDSO/parse_vdso.h | 1 - 2 files changed, 15 deletions(-)
tools/testing/selftests/vDSO/parse_vdso.c +0 -14
@@ -297,17 +297,3 @@ void *vdso_sym(const char *version, const char *name)return 0 ; } - -void vdso_init_from_auxv (void *auxv) -{ -ELF (auxv_t) *elf_auxv = auxv; -for (int i =0 ; elf_auxv[i].a_type !=AT_NULL ; i++) - { -if (elf_auxv[i].a_type ==AT_SYSINFO_EHDR ) { -vdso_init_from_sysinfo_ehdr (elf_auxv[i].a_un.a_val); -return ; - } - } - - vdso_info.valid = false; -}
tools/testing/selftests/vDSO/parse_vdso.h +0 -1
@@ -26,6 +26,5 @@*/ void *vdso_sym (const char *version,const char *name);void vdso_init_from_sysinfo_ehdr (uintptr_t base); -void vdso_init_from_auxv (void *auxv);#endif
Signature · 1 line
2.48.1
Re: [PATCH v2 11/16] selftests: vDSO: parse_vdso: Drop vdso_init_from_auxv()
Quoted 6 lines · Thomas Weißschuh
There are no users left.
This also removes the usage of
ElfXX_auxv_t,
which is not formally standardized.Signed-off-by Thomas Weißschuh <[email protected]>
Quoted 39 lines
--- tools/testing/selftests/vDSO/parse_vdso.c | 14 -------------- tools/testing/selftests/vDSO/parse_vdso.h | 1 - 2 files changed, 15 deletions(-)tools/testing/selftests/vDSO/parse_vdso.c +0
-14@@ -297,17 +297,3 @@ void *vdso_sym(const char *version, const char *name)return 0 ; } - -void vdso_init_from_auxv (void *auxv) -{ -ELF (auxv_t) *elf_auxv = auxv; -for (int i =0 ; elf_auxv[i].a_type !=AT_NULL ; i++) - { -if (elf_auxv[i].a_type ==AT_SYSINFO_EHDR ) { -vdso_init_from_sysinfo_ehdr (elf_auxv[i].a_un.a_val); -return ; - } - } - - vdso_info.valid = false; -}tools/testing/selftests/vDSO/parse_vdso.h +0
-1@@ -26,6 +26,5 @@*/ void *vdso_sym (const char *version,const char *name);void vdso_init_from_sysinfo_ehdr (uintptr_t base); -void vdso_init_from_auxv (void *auxv);#endif
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] selftests: vDSO: parse_vdso: Drop vdso_init_from_auxv()
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 09dcec64707df85f5def668d4724fce832114d91 Gitweb: https://git.kernel.org/tip/09dcec64707df85f5def668d4724fce832114d91 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:50 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:12 +01:00
selftests: vDSO: parse_vdso: Drop vdso_init_from_auxv()
There are no users left.
This also removes the usage of ElfXX_auxv_t, which is not formally standardized.
--- tools/testing/selftests/vDSO/parse_vdso.c | 14 -------------- tools/testing/selftests/vDSO/parse_vdso.h | 1 - 2 files changed, 15 deletions(-)
tools/testing/selftests/vDSO/parse_vdso.c +0 -14
@@ -297,17 +297,3 @@ void *vdso_sym(const char *version, const char *name)return 0 ; } - -void vdso_init_from_auxv (void *auxv) -{ -ELF (auxv_t) *elf_auxv = auxv; -for (int i =0 ; elf_auxv[i].a_type !=AT_NULL ; i++) - { -if (elf_auxv[i].a_type ==AT_SYSINFO_EHDR ) { -vdso_init_from_sysinfo_ehdr (elf_auxv[i].a_un.a_val); -return ; - } - } - - vdso_info.valid = false; -}
tools/testing/selftests/vDSO/parse_vdso.h +0 -1
@@ -26,6 +26,5 @@*/ void *vdso_sym (const char *version,const char *name);void vdso_init_from_sysinfo_ehdr (uintptr_t base); -void vdso_init_from_auxv (void *auxv);#endif
PATCH v2 12/16 selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
In reply to Thomas WeißschuhTo allow the usage of parse_vdso.c together with a limited libc like nolibc, use the kernels own elf.h and auxvec.h headers.
--- tools/testing/selftests/vDSO/Makefile | 3 +++ tools/testing/selftests/vDSO/parse_vdso.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)
tools/testing/selftests/vDSO/Makefile +3 -0
@@ -19,6 +19,9 @@ LDLIBS += -lgcc_s endif include ../lib.mk + +CFLAGS += $(TOOLS_INCLUDES) + $(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c $(OUTPUT)/vdso_test_getcpu: parse_vdso.c vdso_test_getcpu.c $(OUTPUT)/vdso_test_abi: parse_vdso.c vdso_test_abi.c
tools/testing/selftests/vDSO/parse_vdso.c +2 -1
@@ -19,7 +19,8 @@#include <stdint.h> #include <string.h> #include <limits.h> -#include <elf.h> +#include <linux/auxvec.h> +#include <linux/elf.h> #include "parse_vdso.h"
Signature · 1 line
2.48.1
Re: [PATCH v2 12/16] selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
Quoted 4 lines · Thomas Weißschuh
To allow the usage of
parse_vdso.ctogether with a limited libc like nolibc, use the kernels ownelf.handauxvec.hheaders.Signed-off-by Thomas Weißschuh <[email protected]>
Quoted 34 lines
--- tools/testing/selftests/vDSO/Makefile | 3 +++ tools/testing/selftests/vDSO/parse_vdso.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)tools/testing/selftests/vDSO/Makefile +3
-0@@ -19,6 +19,9 @@ LDLIBS += -lgcc_s endif include ../lib.mk + +CFLAGS += $(TOOLS_INCLUDES) + $(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c $(OUTPUT)/vdso_test_getcpu: parse_vdso.c vdso_test_getcpu.c $(OUTPUT)/vdso_test_abi: parse_vdso.c vdso_test_abi.ctools/testing/selftests/vDSO/parse_vdso.c +2
-1@@ -19,7 +19,8 @@#include <stdint.h> #include <string.h> #include <limits.h> -#include <elf.h> +#include <linux/auxvec.h> +#include <linux/elf.h> #include "parse_vdso.h"
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: c9fbaa879508ea36f5be0b3f1125b8f9f11b4945 Gitweb: https://git.kernel.org/tip/c9fbaa879508ea36f5be0b3f1125b8f9f11b4945 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:51 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:12 +01:00
selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
To allow the usage of parse_vdso.c together with a limited libc like nolibc, use the kernels own elf.h and auxvec.h headers.
--- tools/testing/selftests/vDSO/Makefile | 3 +++ tools/testing/selftests/vDSO/parse_vdso.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)
tools/testing/selftests/vDSO/Makefile +3 -0
@@ -19,6 +19,9 @@ LDLIBS += -lgcc_s endif include ../lib.mk + +CFLAGS += $(TOOLS_INCLUDES) + $(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c $(OUTPUT)/vdso_test_getcpu: parse_vdso.c vdso_test_getcpu.c $(OUTPUT)/vdso_test_abi: parse_vdso.c vdso_test_abi.c
tools/testing/selftests/vDSO/parse_vdso.c +2 -1
@@ -19,7 +19,8 @@#include <stdint.h> #include <string.h> #include <limits.h> -#include <elf.h> +#include <linux/auxvec.h> +#include <linux/elf.h> #include "parse_vdso.h"
Re: [PATCH v2 12/16] selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
In reply to Thomas WeißschuhQuoted 2 lines · Thomas Weißschuh
To allow the usage of
parse_vdso.ctogether with a limited libc like nolibc, use the kernels ownelf.handauxvec.hheaders.
The vDSO selftests currently fail build for at least arm64 in -next:
CC vdso_test_gettimeofday CC vdso_test_getcpu CC vdso_test_abi CC vdso_test_clock_getres CC vdso_test_correctness CC vdso_test_getrandom CC vdso_test_chacha
/build/stage/linux/tools/include/uapi/linux/types.h: Assembler messages:
/build/stage/linux/tools/include/uapi/linux/types.h:9: Error: unknown mnemonic typedef' -- typedef __u16 __le16' /build/stage/linux/tools/include/uapi/linux/types.h:10: Error: unknown mnemonic typedef' -- typedef __u16 __be16' /build/stage/linux/tools/include/uapi/linux/types.h:11: Error: unknown mnemonic typedef' -- typedef __u32 __le32' /build/stage/linux/tools/include/uapi/linux/types.h:12: Error: unknown mnemonic typedef' -- typedef __u32 __be32' /build/stage/linux/tools/include/uapi/linux/types.h:13: Error: unknown mnemonic typedef' -- typedef __u64 __le64' /build/stage/linux/tools/include/uapi/linux/types.h:14: Error: unknown mnemonic typedef' -- typedef __u64 __be64' /build/stage/linux/tools/include/uapi/linux/types.h:16: Error: unknown mnemonic typedef' -- typedef __u16 __sum16' /build/stage/linux/tools/include/uapi/linux/types.h:17: Error: unknown mnemonic typedef' -- typedef __u32 __wsum'
a bisect points at this patch, it looks like that's due to the switch to use TOOLS_INCLUDES but I didn't dig into the specifics.
Re: [PATCH v2 12/16] selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
Quoted 5 lines · Mark Brown
Quoted 2 lines · Thomas Weißschuh
To allow the usage of
parse_vdso.ctogether with a limited libc like nolibc, use the kernels ownelf.handauxvec.hheaders.The vDSO selftests currently fail build for at least arm64 in -next:
...
Quoted 2 lines
a bisect points at this patch, it looks like that's due to the switch to use
TOOLS_INCLUDESbut I didn't dig into the specifics.
This bug is now in mainline. A fix was posted by Thomas the day after the original report:
https://lore.kernel.org/r/[email protected]
but it has apparently slipped through the cracks.
Re: [PATCH v2 12/16] selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
Quoted 12 lines · Mark Brown
Quoted 5 lines · Mark Brown
Quoted 2 lines · Thomas Weißschuh
To allow the usage of
parse_vdso.ctogether with a limited libc like nolibc, use the kernels ownelf.handauxvec.hheaders.The vDSO selftests currently fail build for at least arm64 in -next:
...
Quoted 2 lines
a bisect points at this patch, it looks like that's due to the switch to use
TOOLS_INCLUDESbut I didn't dig into the specifics.
Quoted 6 lines
This bug is now in mainline. A fix was posted by Thomas the day after the original report:
https://lore.kernel.org/r/[email protected]but it has apparently slipped through the cracks.
If this is going through tip
Otherwise, I can send this up
thanks,
-- Shuah
Re: [PATCH v2 12/16] selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
Quoted 7 lines · Shuah Khan
Quoted 4 lines · Mark Brown
This bug is now in mainline. A fix was posted by Thomas the day after the original report:
https://lore.kernel.org/r/[email protected]
Quoted 7 lines
Quoted 1 line
but it has apparently slipped through the cracks.
If this is going through tip
Acked-by Shuah Khan <[email protected]>Otherwise, I can send this up
Given that this hasn't had a response from tip for several weeks it's probably as well for you to pick it up - I was considering sending it directly to Linus myself.
Re: [PATCH v2 12/16] selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers
Quoted 11 lines · Mark Brown
Quoted 5 lines · Shuah Khan
If this is going through tip
Acked-by Shuah Khan <[email protected]>Otherwise, I can send this up
Given that this hasn't had a response from tip for several weeks it's probably as well for you to pick it up - I was considering sending it directly to Linus myself.
I tried sending a copy to Linus but he didn't respond yet, could you send it as part of a kselftest pull request? It'd be unfortunate to have a broken -rc1.
PATCH v2 13/16 selftests: vDSO: parse_vdso: Test __SIZEOF_LONG__ instead of ULONG_MAX
In reply to Thomas WeißschuhAccording to limits.h(2) ULONG_MAX is only guaranteed to expand to an expression, not a symbolic constant which can be evaluated by the preprocessor.
Specifically the definition of ULONG_MAX from nolibc can no be evaluated by the preprocessor. To provide compatibility with nolibc, check with __SIZEOF_LONG__ instead, with is provided directly by the preprocessor and therefore always a symbolic constant.
--- tools/testing/selftests/vDSO/parse_vdso.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/vDSO/parse_vdso.c +1 -1
@@ -26,7 +26,7 @@/* And here's the code. */ #ifndef ELF_BITS -# if ULONG_MAX >0xffffffffUL +# if __SIZEOF_LONG__ >=8 # define ELF_BITS 64# else # define ELF_BITS 32
Signature · 1 line
2.48.1
Re: [PATCH v2 13/16] selftests: vDSO: parse_vdso: Test __SIZEOF_LONG__ instead of ULONG_MAX
Quoted 9 lines · Thomas Weißschuh
According to
limits.h(2)ULONG_MAXis only guaranteed to expand to an expression, not a symbolic constant which can be evaluated by the preprocessor.
Specifically the definition ofULONG_MAXfrom nolibc can no be evaluated by the preprocessor. To provide compatibility with nolibc, check with__SIZEOF_LONG__instead, with is provided directly by the preprocessor and therefore always a symbolic constant.Signed-off-by Thomas Weißschuh <[email protected]>
Quoted 18 lines
--- tools/testing/selftests/vDSO/parse_vdso.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/vDSO/parse_vdso.c +1
-1@@ -26,7 +26,7 @@/* And here's the code. */ #ifndef ELF_BITS -# if ULONG_MAX >0xffffffffUL +# if __SIZEOF_LONG__ >=8 # define ELF_BITS 64# else # define ELF_BITS 32
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] selftests: vDSO: parse_vdso: Test __SIZEOF_LONG__ instead of ULONG_MAX
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 032e871686483ec1bac27ce73e7094692fc76268 Gitweb: https://git.kernel.org/tip/032e871686483ec1bac27ce73e7094692fc76268 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:52 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:13 +01:00
selftests: vDSO: parse_vdso: Test __SIZEOF_LONG__ instead of ULONG_MAX
According to limits.h(2) ULONG_MAX is only guaranteed to expand to an expression, not a symbolic constant which can be evaluated by the preprocessor.
Specifically the definition of ULONG_MAX from nolibc can not be evaluated by the preprocessor. To provide compatibility with nolibc, check with __SIZEOF_LONG__ instead, with is provided directly by the preprocessor and therefore always a symbolic constant.
--- tools/testing/selftests/vDSO/parse_vdso.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/vDSO/parse_vdso.c +1 -1
@@ -26,7 +26,7 @@/* And here's the code. */ #ifndef ELF_BITS -# if ULONG_MAX >0xffffffffUL +# if __SIZEOF_LONG__ >=8 # define ELF_BITS 64# else # define ELF_BITS 32
PATCH v2 14/16 selftests: vDSO: vdso_test_gettimeofday: Clean up includes
In reply to Thomas WeißschuhSome unnecessary headers are included, remove them.
--- tools/testing/selftests/vDSO/vdso_test_gettimeofday.c | 2 -- 1 file changed, 2 deletions(-)
tools/testing/selftests/vDSO/vdso_test_gettimeofday.c +0 -2
@@ -10,8 +10,6 @@* Tested on x86, 32-bit and 64-bit. It may work on other architectures, too. */ -#include <stdint.h> -#include <elf.h> #include <stdio.h> #include <sys/auxv.h> #include <sys/time.h>
Signature · 1 line
2.48.1
Re: [PATCH v2 14/16] selftests: vDSO: vdso_test_gettimeofday: Clean up includes
Quoted 3 lines · Thomas Weißschuh
Some unnecessary headers are included, remove them.
Signed-off-by Thomas Weißschuh <[email protected]>
Quoted 18 lines
--- tools/testing/selftests/vDSO/vdso_test_gettimeofday.c | 2 -- 1 file changed, 2 deletions(-)tools/testing/selftests/vDSO/vdso_test_gettimeofday.c +0
-2@@ -10,8 +10,6 @@* Tested on x86, 32-bit and 64-bit. It may work on other architectures, too. */ -#include <stdint.h> -#include <elf.h> #include <stdio.h> #include <sys/auxv.h> #include <sys/time.h>
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] selftests: vDSO: vdso_test_gettimeofday: Clean up includes
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 97a88141241fcf3d1e54a120afefea04fbd1a484 Gitweb: https://git.kernel.org/tip/97a88141241fcf3d1e54a120afefea04fbd1a484 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:53 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:13 +01:00
selftests: vDSO: vdso_test_gettimeofday: Clean up includes
Some unnecessary headers are included, remove them.
--- tools/testing/selftests/vDSO/vdso_test_gettimeofday.c | 2 -- 1 file changed, 2 deletions(-)
tools/testing/selftests/vDSO/vdso_test_gettimeofday.c +0 -2
@@ -10,8 +10,6 @@* Tested on x86, 32-bit and 64-bit. It may work on other architectures, too. */ -#include <stdint.h> -#include <elf.h> #include <stdio.h> #include <sys/auxv.h> #include <sys/time.h>
PATCH v2 15/16 selftests: vDSO: vdso_test_gettimeofday: Make compatible with nolibc
In reply to Thomas Weißschuhnolibc does not provide sys/time.h and sys/auxv.h, instead their definitions are available unconditionally.
Guard the includes so they are not attempted on nolibc.
--- tools/testing/selftests/vDSO/vdso_test_gettimeofday.c | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/vDSO/vdso_test_gettimeofday.c +2 -0
@@ -11,8 +11,10 @@*/ #include <stdio.h> +#ifndef NOLIBC #include <sys/auxv.h> #include <sys/time.h> +#endif #include "../kselftest.h" #include "parse_vdso.h"
Signature · 1 line
2.48.1
Re: [PATCH v2 15/16] selftests: vDSO: vdso_test_gettimeofday: Make compatible with nolibc
Quoted 6 lines · Thomas Weißschuh
nolibc does not provide
sys/time.handsys/auxv.h, instead their definitions are available unconditionally.Guard the includes so they are not attempted on nolibc.
Signed-off-by Thomas Weißschuh <[email protected]>
Quoted 20 lines
--- tools/testing/selftests/vDSO/vdso_test_gettimeofday.c | 2 ++ 1 file changed, 2 insertions(+)tools/testing/selftests/vDSO/vdso_test_gettimeofday.c +2
-0@@ -11,8 +11,10 @@*/ #include <stdio.h> +#ifndef NOLIBC #include <sys/auxv.h> #include <sys/time.h> +#endif #include "../kselftest.h" #include "parse_vdso.h"
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] selftests: vDSO: vdso_test_gettimeofday: Make compatible with nolibc
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 4f65df6a58b3de5132f978305c5f807ec3803943 Gitweb: https://git.kernel.org/tip/4f65df6a58b3de5132f978305c5f807ec3803943 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:54 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:13 +01:00
selftests: vDSO: vdso_test_gettimeofday: Make compatible with nolibc
nolibc does not provide sys/time.h and sys/auxv.h, instead their definitions are available unconditionally.
Guard the includes so they are not attempted on nolibc.
--- tools/testing/selftests/vDSO/vdso_test_gettimeofday.c | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/vDSO/vdso_test_gettimeofday.c +2 -0
@@ -11,8 +11,10 @@*/ #include <stdio.h> +#ifndef NOLIBC #include <sys/auxv.h> #include <sys/time.h> +#endif #include "../kselftest.h" #include "parse_vdso.h"
PATCH v2 16/16 selftests: vDSO: vdso_standalone_test_x86: Switch to nolibc
In reply to Thomas Weißschuhvdso_standalone_test_x86 provides its own ASM syscall wrappers and _start() implementation. The in-tree nolibc library already provides this functionality for multiple architectures. By making use of nolibc, the standalone testcase can be built from the exact same codebase as the non-standalone version.
--- tools/testing/selftests/vDSO/Makefile | 8 +- .../selftests/vDSO/vdso_standalone_test_x86.c | 168 +-------------------- 2 files changed, 7 insertions(+), 169 deletions(-)
tools/testing/selftests/vDSO/Makefile +6 -2
@@ -22,13 +22,17 @@ include ../lib.mk CFLAGS += $(TOOLS_INCLUDES) +CFLAGS_NOLIBC := -nostdlib -nostdinc -ffreestanding -fno-asynchronous-unwind-tables \ + -fno-stack-protector -include $(top_srcdir)/tools/include/nolibc/nolibc.h \ + -I$(top_srcdir)/tools/include/nolibc/ $(KHDR_INCLUDES) + $(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c $(OUTPUT)/vdso_test_getcpu: parse_vdso.c vdso_test_getcpu.c $(OUTPUT)/vdso_test_abi: parse_vdso.c vdso_test_abi.c $(OUTPUT)/vdso_test_clock_getres: vdso_test_clock_getres.c -$(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c -$(OUTPUT)/vdso_standalone_test_x86: CFLAGS +=-nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector +$(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c | headers +$(OUTPUT)/vdso_standalone_test_x86: CFLAGS:=$(CFLAGS_NOLIBC) $(CFLAGS) $(OUTPUT)/vdso_test_correctness: vdso_test_correctness.c $(OUTPUT)/vdso_test_correctness: LDFLAGS += -ldl
tools/testing/selftests/vDSO/vdso_standalone_test_x86.c deleted +0 -167
167 lines not on this page · raw message
tools/testing/selftests/vDSO/vdso_standalone_test_x86.c new file +1 -0
@@ -0,0 +1 @@ +vdso_test_gettimeofday.c
Signature · 1 line
2.48.1
Re: [PATCH v2 16/16] selftests: vDSO: vdso_standalone_test_x86: Switch to nolibc
Quoted 7 lines · Thomas Weißschuh
vdso_standalone_test_x86provides its own ASM syscall wrappers and_start()implementation. The in-tree nolibc library already provides this functionality for multiple architectures. By making use of nolibc, the standalone testcase can be built from the exact same codebase as the non-standalone version.Signed-off-by Thomas Weißschuh <[email protected]>
Quoted 211 lines
--- tools/testing/selftests/vDSO/Makefile | 8 +- .../selftests/vDSO/vdso_standalone_test_x86.c | 168 +-------------------- 2 files changed, 7 insertions(+), 169 deletions(-)tools/testing/selftests/vDSO/Makefile +6
-2@@ -22,13 +22,17 @@ include ../lib.mk CFLAGS += $(TOOLS_INCLUDES) +CFLAGS_NOLIBC := -nostdlib -nostdinc -ffreestanding -fno-asynchronous-unwind-tables \ + -fno-stack-protector -include $(top_srcdir)/tools/include/nolibc/nolibc.h \ + -I$(top_srcdir)/tools/include/nolibc/ $(KHDR_INCLUDES) + $(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c $(OUTPUT)/vdso_test_getcpu: parse_vdso.c vdso_test_getcpu.c $(OUTPUT)/vdso_test_abi: parse_vdso.c vdso_test_abi.c $(OUTPUT)/vdso_test_clock_getres: vdso_test_clock_getres.c -$(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c -$(OUTPUT)/vdso_standalone_test_x86: CFLAGS +=-nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector +$(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c | headers +$(OUTPUT)/vdso_standalone_test_x86: CFLAGS:=$(CFLAGS_NOLIBC) $(CFLAGS) $(OUTPUT)/vdso_test_correctness: vdso_test_correctness.c $(OUTPUT)/vdso_test_correctness: LDFLAGS += -ldltools/testing/selftests/vDSO/vdso_standalone_test_x86.c deleted +0
-167@@ -1,167 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* -* vdso_test.c: Sample code to test parse_vdso.c on x86 -* Copyright (c) 2011-2014 Andy Lutomirski -* -* You can amuse yourself by compiling with: -* gcc -std=gnu99 -nostdlib -* -Os -fno-asynchronous-unwind-tables -flto -lgcc_s -* vdso_standalone_test_x86.c parse_vdso.c -* to generate a small binary. On x86_64, you can omit -lgcc_s -* if you want the binary to be completely standalone. -*/ - -#include <sys/syscall.h> -#include <sys/time.h> -#include <unistd.h> -#include <stdint.h> -#include <linux/auxvec.h> - -#include "parse_vdso.h" - -/* We need some libc functions... */ -int strcmp (const char *a,const char *b) -{ -/* This implementation is buggy: it never returns -1. */ -while (*a || *b) { -if (*a != *b) -return 1 ; -if (*a ==0 || *b ==0 ) -return 1 ; - a++; - 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) -{ -long ret; -#ifdef __x86_64__ - asmvolatile ("syscall" :"=a" (ret) :"a" (nr), -"D" (a0),"S" (a1),"d" (a2) : -"cc" ,"memory" ,"rcx" , -"r8" ,"r9" ,"r10" ,"r11" ); -#else - asmvolatile ("int $0x80" :"=a" (ret) :"a" (nr), -"b" (a0),"c" (a1),"d" (a2) : -"cc" ,"memory" ); -#endif -return ret; -} - -static inline long linux_write (int fd,const void *data,size_t len) -{ -return x86_syscall3 (__NR_write, fd, (long )data, (long )len); -} - -static inline void linux_exit (int code) -{ -x86_syscall3 (__NR_exit, code,0 ,0 ); -} - -void to_base10 (char *lastdig,time_t n) -{ -while (n) { - *lastdig = (n %10 ) +'0' ; - n /=10 ; - lastdig--; - } -} - -unsigned long getauxval (const unsigned long *auxv,unsigned long type) -{ -unsigned long ret; - -if (!auxv) -return 0 ; - -while (1 ) { -if (!auxv[0 ] && !auxv[1 ]) { - ret =0 ; -break ; - } - -if (auxv[0 ] == type) { - ret = auxv[1 ]; -break ; - } - - auxv +=2 ; - } - -return ret; -} - -void c_main (void **stack) -{ -/* Parse the stack */ -long argc = (long )*stack; - stack += argc +2 ; - -/* Now we're pointing at the environment. Skip it. */ -while (*stack) - stack++; - stack++; - -/* Now we're pointing at auxv. Initialize the vDSO parser. */ -vdso_init_from_sysinfo_ehdr (getauxval ((unsigned long *)stack,AT_SYSINFO_EHDR )); - -/* Find gettimeofday. */ -typedef long (*gtod_t )(struct timeval *tv,struct timezone *tz); -gtod_t gtod = (gtod_t )vdso_sym ("LINUX_2.6" ,"__vdso_gettimeofday" ); - -if (!gtod) -linux_exit (1 ); - -struct timeval tv; -long ret =gtod (&tv,0 ); - -if (ret ==0 ) { -char buf[] ="The time is .000000\n" ; -to_base10 (buf +31 , tv.tv_sec); -to_base10 (buf +38 , tv.tv_usec); -linux_write (1 , buf,sizeof (buf) -1 ); - }else { -linux_exit (ret); - } - -linux_exit (0 ); -} - -/* -* This is the real entry point. It passes the initial stack into -* the C entry point. -*/ -asm ( - ".text\n" - ".global _start\n" - ".type _start,@function\n" - "_start:\n\t" -#ifdef __x86_64__ - "mov %rsp,%rdi\n\t" - "and $-16,%rsp\n\t" - "sub $8,%rsp\n\t" - "jmp c_main" -#else -"push %esp\n\t" -"call c_main\n\t" -"int $3" -#endif - );tools/testing/selftests/vDSO/vdso_standalone_test_x86.c new file +1
-0@@ -0,0 +1 @@ +vdso_test_gettimeofday.c
Signature · 2 lines
Regards, Vincenzo
[tip: timers/vdso] selftests: vDSO: vdso_standalone_test_x86: Switch to nolibc
In reply to Thomas WeißschuhThe following commit has been merged into the timers/vdso branch of tip:
The following commit has been merged into the timers/vdso branch of tip:
Commit-ID: 8770a9183fe18442c7cfbb56bb7e006462775a91 Gitweb: https://git.kernel.org/tip/8770a9183fe18442c7cfbb56bb7e006462775a91 Author: Thomas Weißschuh <[email protected]> AuthorDate: Wed, 26 Feb 2025 12:44:55 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Mon, 03 Mar 2025 20:00:13 +01:00
selftests: vDSO: vdso_standalone_test_x86: Switch to nolibc
vdso_standalone_test_x86 provides its own ASM syscall wrappers and _start() implementation. The in-tree nolibc library already provides this functionality for multiple architectures. By making use of nolibc, the standalone testcase can be built from the exact same codebase as the non-standalone version.
--- tools/testing/selftests/vDSO/Makefile | 8 +- tools/testing/selftests/vDSO/vdso_standalone_test_x86.c | 175 +------ 2 files changed, 39 insertions(+), 144 deletions(-)
tools/testing/selftests/vDSO/Makefile +6 -2
@@ -22,13 +22,17 @@ include ../lib.mk CFLAGS += $(TOOLS_INCLUDES) +CFLAGS_NOLIBC := -nostdlib -nostdinc -ffreestanding -fno-asynchronous-unwind-tables \ + -fno-stack-protector -include $(top_srcdir)/tools/include/nolibc/nolibc.h \ + -I$(top_srcdir)/tools/include/nolibc/ $(KHDR_INCLUDES) + $(OUTPUT)/vdso_test_gettimeofday: parse_vdso.c vdso_test_gettimeofday.c $(OUTPUT)/vdso_test_getcpu: parse_vdso.c vdso_test_getcpu.c $(OUTPUT)/vdso_test_abi: parse_vdso.c vdso_test_abi.c $(OUTPUT)/vdso_test_clock_getres: vdso_test_clock_getres.c -$(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c -$(OUTPUT)/vdso_standalone_test_x86: CFLAGS +=-nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector +$(OUTPUT)/vdso_standalone_test_x86: vdso_standalone_test_x86.c parse_vdso.c | headers +$(OUTPUT)/vdso_standalone_test_x86: CFLAGS:=$(CFLAGS_NOLIBC) $(CFLAGS) $(OUTPUT)/vdso_test_correctness: vdso_test_correctness.c $(OUTPUT)/vdso_test_correctness: LDFLAGS += -ldl
tools/testing/selftests/vDSO/vdso_standalone_test_x86.c +33 -142
200 lines not on this page · raw message
Re: [PATCH v2 16/16] selftests: vDSO: vdso_standalone_test_x86: Switch to nolibc
In reply to Thomas WeißschuhQuoted 4 lines · Thomas Weißschuh
-$(OUTPUT)/vdso_standalone_test_x86:
vdso_standalone_test_x86.cparse_vdso.c-$(OUTPUT)/vdso_standalone_test_x86: CFLAGS +=-nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector +$(OUTPUT)/vdso_standalone_test_x86:vdso_standalone_test_x86.cparse_vdso.c| headers +$(OUTPUT)/vdso_standalone_test_x86: CFLAGS:=$(CFLAGS_NOLIBC) $(CFLAGS)
This addition of "| headers" breaks O=build builds. ie this:
$ make O=build-x86 allnoconfig -s -j 14 $ make O=build-x86 -s -j 14 $ make O=build-x86 kselftest-all -s -j 16 &> /dev/null || true $ make O=build-x86 -s -j 14
Fails with:
***
*** The source tree is not clean, please run 'make mrproper' *** in /home/jgg/oss/wip/kselftests_dirty
***
Because the build now spews stuff outside the build directory that it should not do.. Bisection points to this patch and removing the "| headers" makes it stop doing that..
Any idea how to fix it?
Thanks,
Jason
Thomas Weißschuh
maintainerRe: [PATCH v2 16/16] selftests: vDSO: vdso_standalone_test_x86: Switch to nolibc
Hi Jason,
Quoted 16 lines · Jason Gunthorpe
Quoted 4 lines · Thomas Weißschuh
-$(OUTPUT)/vdso_standalone_test_x86:
vdso_standalone_test_x86.cparse_vdso.c-$(OUTPUT)/vdso_standalone_test_x86: CFLAGS +=-nostdlib -fno-asynchronous-unwind-tables -fno-stack-protector +$(OUTPUT)/vdso_standalone_test_x86:vdso_standalone_test_x86.cparse_vdso.c| headers +$(OUTPUT)/vdso_standalone_test_x86: CFLAGS:=$(CFLAGS_NOLIBC) $(CFLAGS)This addition of "| headers" breaks O=build builds. ie this:
$ make O=build-x86 allnoconfig -s -j 14 $ make O=build-x86 -s -j 14 $ make O=build-x86 kselftest-all -s -j 16 &> /dev/null || true $ make O=build-x86 -s -j 14Fails with:
Quoted 8 lines
***
*** The source tree is not clean, please run 'make mrproper' *** in/home/jgg/oss/wip/kselftests_dirty
***Because the build now spews stuff outside the build directory that it should not do.. Bisection points to this patch and removing the "| headers" makes it stop doing that..
Sorry for the breakage and thanks for the report.
Quoted 1 line
Any idea how to fix it?
Care to try this:
tools/testing/selftests/lib.mk +4 -1
@@ -228,7 +228,10 @@ $(OUTPUT)/%:%.S $(LINK.S) $^ $(LDLIBS) -o $@ endif +# Extract the expected header directory +khdr_output := $(patsubst %/usr/include,%,$(filter %/usr/include,$(KHDR_INCLUDES))) + headers: - $(Q)$(MAKE) -C $(top_srcdir) headers + $(Q)$(MAKE) -f $(top_srcdir)/Makefile -C $(khdr_output) headers .PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir headers
Thomas
Jason Gunthorpe
Reviewed-byRe: [PATCH v2 16/16] selftests: vDSO: vdso_standalone_test_x86: Switch to nolibc
Quoted 8 lines · Thomas Weißschuh
Care to try this:
tools/testing/selftests/lib.mk +0
-0@@ -228,7 +228,10 @@ $(OUTPUT)/%:%.S $(LINK.S) $^ $(LDLIBS) -o $@
tools/testing/selftests/lib.mk $(OUTPUT)/%:%.S · line 237
Quoted 10 lines
tools/testing/selftests/lib.mk +4
-1endif +# Extract the expected header directory +khdr_output := $(patsubst %/usr/include,%,$(filter %/usr/include,$(KHDR_INCLUDES))) + headers: - $(Q)$(MAKE) -C $(top_srcdir) headers + $(Q)$(MAKE) -f $(top_srcdir)/Makefile -C $(khdr_output) headers .PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir headers
Worked for me, thanks!
Though I notice it still spews stuff out of the build directory:
tools/testing/selftests/mm/local_config.h tools/testing/selftests/mm/local_config.mk tools/testing/selftests/net/rds/include.sh tools/testing/selftests/prctl/disable-tsc-ctxt-sw-stress-test tools/testing/selftests/prctl/disable-tsc-on-off-stress-test tools/testing/selftests/prctl/disable-tsc-test tools/testing/selftests/prctl/set-anon-vma-name-test tools/testing/selftests/prctl/set-process-name tools/testing/selftests/uevent/uevent_filtering
It is not related to this
Jason
Quoted 60 lines · Thomas Weißschuh
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 makeparse_vdso.ccompatible with nolibc.
As an example,vdso_standalone_test_x86is now built from the same C code as the regularvdso_test_gettimeofday, while still being completely standalone.
Also drop the dependency ofparse_vdso.con theelf.hheader from libc and only use the one from the kernel's UAPI.While this series is useful on its own now, it will also integrate with the kunit UAPI framework currently under development:
https://lore.kernel.org/lkml/[email protected]/Signed-off-by Thomas Weißschuh <[email protected]>---
Changes in v2:
- Provide alimits.hheader in nolibc
- Pick up Reviewed-by tags from Kees
- Link to v1: https://lore.kernel.org/r/[email protected]---
Thomas Weißschuh (16):
MAINTAINERS: Add vDSO selftests
elf, uapi: Add definition forSTN_UNDEF
elf, uapi: Add definition forDT_GNU_HASH
elf, uapi: Add definitions forVER_FLG_BASEandVER_FLG_WEAKelf, uapi: Add typeElfXX_Versym
elf, uapi: Add typesElfXX_VerdefandElfXX_Verauxtools/include: Adduapi/linux/elf.h
selftests: Add headers target
tools/nolibc: addlimits.hshim header
selftests: vDSO:vdso_standalone_test_x86: Usevdso_init_form_sysinfo_ehdr
selftests: vDSO:parse_vdso: Dropvdso_init_from_auxv()
selftests: vDSO:parse_vdso: Use UAPI headers instead of libc headers
selftests: vDSO:parse_vdso: Test__SIZEOF_LONG__instead ofULONG_MAX
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 nolibcMAINTAINERS | 1 + include/uapi/linux/elf.h | 38 ++ tools/include/nolibc/Makefile | 1 + tools/include/nolibc/limits.h | 7 + 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 | 19 +- tools/testing/selftests/vDSO/parse_vdso.h | 1 - .../selftests/vDSO/vdso_standalone_test_x86.c | 143 +----- .../selftests/vDSO/vdso_test_gettimeofday.c | 4 +- 11 files changed, 590 insertions(+), 164 deletions(-)
Quoted 5 lines
---
base-commit:2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20241017-parse_vdso-nolibc-e069baa7ff48Best regards,
Here is my Ack for this series to go through vDSO or x86 tree
thanks,
-- Shuah