Some MUSL fixes
cover Some MUSL fixes
Hi,
there are numerous problems with LTP build with MUSL. This patchset address only few obvious ones.
Kind regards,
Petr
Petr Vorel (5):
rt_sigaction.h: Check for type sighandler_t and use if present {rt_,}sigaction: Define _GNU_SOURCE to get SA_NOMASK on MUSL
ptrace: Use int instead of enum __ptrace_request
mremap: Define _GNU_SOURCE to get MREMAP_MAYMOVE on MUSL
mallopt: Test only on glibc
include/lapi/rt_sigaction.h | 8 ++++++++ m4/ltp-sighandler_t.m4 | 8 ++++++++ testcases/kernel/syscalls/mallopt/mallopt01.c | 6 +++--- testcases/kernel/syscalls/mremap/mremap01.c | 4 ++-- testcases/kernel/syscalls/mremap/mremap02.c | 3 +-- testcases/kernel/syscalls/mremap/mremap03.c | 3 +-- testcases/kernel/syscalls/mremap/mremap04.c | 3 +-- testcases/kernel/syscalls/ptrace/ptrace03.c | 2 +- testcases/kernel/syscalls/ptrace/ptrace06.c | 2 +- testcases/kernel/syscalls/ptrace/spawn_ptrace_child.h | 2 +- testcases/kernel/syscalls/rt_sigaction/rt_sigaction01.c | 1 + testcases/kernel/syscalls/rt_sigaction/rt_sigaction02.c | 1 + testcases/kernel/syscalls/rt_sigaction/rt_sigaction03.c | 1 + testcases/kernel/syscalls/sigaction/sigaction02.c | 2 ++ testcases/misc/crash/crash01.c | 1 + 15 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 m4/ltp-sighandler_t.m4
Signature · 1 line
2.20.1
PATCH 1/5 rt_sigaction.h: Check for type sighandler_t and use if present
__sighandler_t is libc implementation specific and should not be relied upon. Instead, we fall back upon void (*)(int), as specified by POSIX.
This fixes MUSL build.
Credits: taken from util-linux
--- include/lapi/rt_sigaction.h | 8 ++++++++ m4/ltp-sighandler_t.m4 | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 m4/ltp-sighandler_t.m4
include/lapi/rt_sigaction.h +8 -0
@@ -36,12 +36,20 @@ #if defined(__mips__) struct kernel_sigaction { unsigned int sa_flags; +# ifdef HAVE_SIGHANDLER_T __sighandler_t k_sa_handler; +# else +void (* k_sa_handler)(int); +# endif sigset_t sa_mask; }; #else struct kernel_sigaction { +# ifdef HAVE_SIGHANDLER_T __sighandler_t k_sa_handler; +# else +void (* k_sa_handler)(int); +# endif unsigned long sa_flags; void (*sa_restorer) (void); sigset_t sa_mask;
m4/ltp-sighandler_t.m4 new file +8 -0
@@ -0,0 +1,8 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2019 Petr Vorel <[email protected]> + +AC_DEFUN([LTP_CHECK_SIGHANDLER_T],[ +AC_CHECK_TYPES([sighandler_t], [], [], [[ +#include <signal.h> +]]) +])
Signature · 1 line
2.20.1
PATCH 1/5 rt_sigaction.h: Check for type sighandler_t and use if present
Hi!
Quoted 2 lines
__sighandler_tis libc implementation specific and should not be relied upon. Instead, we fall back upon void (*)(int), as specified by POSIX.
Can't we just use the void (* k_sa_handler)(int) in all cases and don't add more ifdefs to that file?
The __sighandler_t is defined to void (* __sighandler_t)(int) in glibc anyways.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/5 rt_sigaction.h: Check for type sighandler_t and use if present
Hi Cyril,
Quoted 7 lines
Quoted 2 lines
__sighandler_tis libc implementation specific and should not be relied upon. Instead, we fall back upon void (*)(int), as specified by POSIX.Can't we just use the void (* k_sa_handler)(int) in all cases and don't add more ifdefs to that file?
The
__sighandler_tis defined to void (* __sighandler_t)(int) in glibc anyways.
Thanks for a hint, make sense.
Fixed accordingly and pushed whole patchset.
Kind regards,
Petr
PATCH 2/5 {rt_, }sigaction: Define _GNU_SOURCE to get SA_NOMASK on MUSL
In reply to Petr VorelUnlike glibc and uclibc (which define SA_NOMASK under __USE_MISC) MUSL requires _GNU_SOURCE.
_GNU_SOURCE is already used in crash02.c.
--- testcases/kernel/syscalls/rt_sigaction/rt_sigaction01.c | 1 + testcases/kernel/syscalls/rt_sigaction/rt_sigaction02.c | 1 + testcases/kernel/syscalls/rt_sigaction/rt_sigaction03.c | 1 + testcases/kernel/syscalls/sigaction/sigaction02.c | 2 ++ testcases/misc/crash/crash01.c | 1 + 5 files changed, 6 insertions(+)
testcases/kernel/syscalls/rt_sigaction/rt_sigaction01.c +1 -0
@@ -28,6 +28,7 @@/* sigset_t type. */ /******************************************************************************/ +#define _GNU_SOURCE#include <stdio.h> #include <stdlib.h> #include <unistd.h>
testcases/kernel/syscalls/rt_sigaction/rt_sigaction02.c +1 -0
@@ -24,6 +24,7 @@/* rt_sigaction Expected EFAULT error check */ /******************************************************************************/ +#define _GNU_SOURCE#include <stdio.h> #include <stdlib.h> #include <unistd.h>
testcases/kernel/syscalls/rt_sigaction/rt_sigaction03.c +1 -0
@@ -24,6 +24,7 @@/* rt_sigaction Expected EINVAL error check */ /******************************************************************************/ +#define _GNU_SOURCE#include <stdio.h> #include <stdlib.h> #include <unistd.h>
testcases/kernel/syscalls/sigaction/sigaction02.c +2 -0
@@ -49,6 +49,8 @@* This test doesn't follow the correct LTP format - PLEASE FIX! */ #define DEBUG 0 + +#define _GNU_SOURCE#include <stdio.h> #include <stdlib.h> #include <unistd.h>
testcases/misc/crash/crash01.c +1 -0
@@ -50,6 +50,7 @@ benchmark.*/ +#define _GNU_SOURCE#include <stdio.h> #include <stdlib.h> #include <string.h>
Signature · 1 line
2.20.1
PATCH 2/5 {rt_, }sigaction: Define _GNU_SOURCE to get SA_NOMASK on MUSL
Hi!
This is obviously OK.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/5 ptrace: Use int instead of enum __ptrace_request
In reply to Petr Vorelenum __ptrace_request is glibc/uclibc specific.
--- testcases/kernel/syscalls/ptrace/ptrace03.c | 2 +- testcases/kernel/syscalls/ptrace/ptrace06.c | 2 +- testcases/kernel/syscalls/ptrace/spawn_ptrace_child.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/ptrace/ptrace03.c +1 -1
@@ -102,7 +102,7 @@ static pid_t unused_pid;static pid_t zero_pid;struct test_case_t { -enum __ptrace_request request; +int request;pid_t *pid;int exp_errno; } test_cases[] = {
testcases/kernel/syscalls/ptrace/ptrace06.c +1 -1
@@ -38,7 +38,7 @@char *TCID ="ptrace06" ;struct test_case_t { -enum __ptrace_request request; +int request;long addr;long data; } test_cases[] = {
testcases/kernel/syscalls/ptrace/spawn_ptrace_child.h +1 -1
@@ -130,7 +130,7 @@ static char *strings[] = { SPT(KILL) SPT(SINGLESTEP) }; -static inline char *strptrace (enum __ptrace_request request) +static inline char *strptrace (int request) {return strings[request]; }
Signature · 1 line
2.20.1
PATCH 3/5 ptrace: Use int instead of enum __ptrace_request
Hi!
Looks OK as well.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 4/5 mremap: Define _GNU_SOURCE to get MREMAP_MAYMOVE on MUSL
In reply to Petr VorelUnlike glibc and uclibc (which define MREMAP_MAYMOVE under __USE_MISC) MUSL requires _GNU_SOURCE.
+ Remove __USE_GNU
--- testcases/kernel/syscalls/mremap/mremap01.c | 4 ++-- testcases/kernel/syscalls/mremap/mremap02.c | 3 +-- testcases/kernel/syscalls/mremap/mremap03.c | 3 +-- testcases/kernel/syscalls/mremap/mremap04.c | 3 +-- 4 files changed, 5 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/mremap/mremap01.c +2 -2
@@ -74,11 +74,11 @@* RESTRICTIONS: * None. */ + +#define _GNU_SOURCE#include <unistd.h> #include <errno.h> -#define __USE_GNU#include <sys/mman.h> -#undef __USE_GNU#include <fcntl.h> #include "test.h"
testcases/kernel/syscalls/mremap/mremap02.c +1 -2
@@ -72,12 +72,11 @@* RESTRICTIONS: * None. */ +#define _GNU_SOURCE#include <errno.h> #include <unistd.h> #include <fcntl.h> -#define __USE_GNU#include <sys/mman.h> -#undef __USE_GNU#include "test.h"
testcases/kernel/syscalls/mremap/mremap03.c +1 -2
@@ -73,12 +73,11 @@* RESTRICTIONS: * None. */ +#define _GNU_SOURCE#include <errno.h> #include <unistd.h> #include <fcntl.h> -#define __USE_GNU#include <sys/mman.h> -#undef __USE_GNU#include "test.h"
testcases/kernel/syscalls/mremap/mremap04.c +1 -2
@@ -77,11 +77,10 @@* RESTRICTIONS: * None. */ +#define _GNU_SOURCE#include <errno.h> #include <unistd.h> -#define __USE_GNU#include <sys/mman.h> -#undef __USE_GNU#include <sys/ipc.h> #include <sys/shm.h>
Signature · 1 line
2.20.1
PATCH 4/5 mremap: Define _GNU_SOURCE to get MREMAP_MAYMOVE on MUSL
Hi!
Quoted 3 lines
Unlike glibc and uclibc (which define
MREMAP_MAYMOVEunder__USE_MISC) MUSL requires_GNU_SOURCE.
+ Remove__USE_GNU
Acked, the __USE_GNU is hack that is not supposed to be used anyway.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 5/5 mallopt: Test only on glibc
In reply to Petr VorelTest works with is glibc specific definitions M_MXFAST , M_NLBLKS, which aren't supported on other libc (uClibc, MUSL, Bionic), probably no other libc will ever define.
uClibc also defines them in headers, that's we explicitly check glibc.
---
Hi,
maybe #ifdef M_MXFAST && !defined(UCLINUX) would be better.
Kind regards,
Petr
--- testcases/kernel/syscalls/mallopt/mallopt01.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/mallopt/mallopt01.c +3 -3
@@ -63,7 +63,7 @@ extern int tst_COUNT; /* Test Case counter for tst_routines */void printinfo (); -#if !defined(UCLINUX ) +#if defined(__GLIBC__)struct mallinfo info;int main (int argc,char *argv[])
@@ -150,6 +150,6 @@ void printinfo(void)#else int main (void ) { -tst_brkm (TCONF ,NULL ,"test is not available on uClinux" ); +tst_brkm (TCONF ,NULL ,"mallopt defined only for glibc" ); } -#endif /* if !defined(UCLINUX) */ +#endif
Signature · 1 line
2.20.1
PATCH 5/5 mallopt: Test only on glibc
Hi!
I guess that this is OK as well.
Signature · 2 lines
Cyril Hrubis [email protected]