[PATCH] linux-user: Remove unnecessary static assert involving __SIGRTMAX

Michael Forney posted 1 patch 2 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/next-importer-push tags/patchew/20210526043928.9586-1-mforney@mforney.org
Maintainers: Laurent Vivier <laurent@vivier.eu>
linux-user/signal.c | 1 -
1 file changed, 1 deletion(-)
[PATCH] linux-user: Remove unnecessary static assert involving __SIGRTMAX
Posted by Michael Forney 2 years, 10 months ago
Since "linux-user: fix use of SIGRTMIN" (6bc024e7), qemu removed
use of __SIGRTMAX except for in this QEMU_BUILD_BUG_ON assert.
Presumably, this check is to ensure that the loop in signal_table_init
from SIGRTMIN to SIGRTMAX falls within the bounds of
host_to_target_signal_table (_NSIG).

However, _NSIG is already defined to be the one larger than the
largest signal supported by the system (as specified in the upcoming
POSIX revision[0]), so the check is unnecessary.

musl libc does not define __SIGRTMAX, so removing this check fixes
one of the last remaining errors when building qemu.

[0] https://www.austingroupbugs.net/view.php?id=741

Signed-off-by: Michael Forney <mforney@mforney.org>
---
If you prefer, I can send an alternate patch to leave the
QEMU_BUILD_BUG_ON, but guard it by #ifdef __SIGRTMAX.

 linux-user/signal.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 9016896dcd..6f62f2b528 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -38,7 +38,6 @@ static void host_signal_handler(int host_signum, siginfo_t *info,
  * Signal number 0 is reserved for use as kill(pid, 0), to test whether
  * a process exists without sending it a signal.
  */
-QEMU_BUILD_BUG_ON(__SIGRTMAX + 1 != _NSIG);
 static uint8_t host_to_target_signal_table[_NSIG] = {
     [SIGHUP] = TARGET_SIGHUP,
     [SIGINT] = TARGET_SIGINT,
-- 
2.31.1


Re: [PATCH] linux-user: Remove unnecessary static assert involving __SIGRTMAX
Posted by Philippe Mathieu-Daudé 2 years, 10 months ago
On 5/26/21 6:39 AM, Michael Forney wrote:
> Since "linux-user: fix use of SIGRTMIN" (6bc024e7), qemu removed
> use of __SIGRTMAX except for in this QEMU_BUILD_BUG_ON assert.
> Presumably, this check is to ensure that the loop in signal_table_init
> from SIGRTMIN to SIGRTMAX falls within the bounds of
> host_to_target_signal_table (_NSIG).
> 
> However, _NSIG is already defined to be the one larger than the
> largest signal supported by the system (as specified in the upcoming
> POSIX revision[0]), so the check is unnecessary.
> 
> musl libc does not define __SIGRTMAX, so removing this check fixes
> one of the last remaining errors when building qemu.
> 
> [0] https://www.austingroupbugs.net/view.php?id=741
> 
> Signed-off-by: Michael Forney <mforney@mforney.org>
> ---
> If you prefer, I can send an alternate patch to leave the
> QEMU_BUILD_BUG_ON, but guard it by #ifdef __SIGRTMAX.

This looks safer, personally I prefer, but let's see what the
maintainers prefer.

>  linux-user/signal.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index 9016896dcd..6f62f2b528 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -38,7 +38,6 @@ static void host_signal_handler(int host_signum, siginfo_t *info,
>   * Signal number 0 is reserved for use as kill(pid, 0), to test whether
>   * a process exists without sending it a signal.
>   */
> -QEMU_BUILD_BUG_ON(__SIGRTMAX + 1 != _NSIG);
>  static uint8_t host_to_target_signal_table[_NSIG] = {
>      [SIGHUP] = TARGET_SIGHUP,
>      [SIGINT] = TARGET_SIGINT,
> 


Re: [PATCH] linux-user: Remove unnecessary static assert involving __SIGRTMAX
Posted by Laurent Vivier 2 years, 10 months ago
Le 26/05/2021 à 19:16, Philippe Mathieu-Daudé a écrit :
> On 5/26/21 6:39 AM, Michael Forney wrote:
>> Since "linux-user: fix use of SIGRTMIN" (6bc024e7), qemu removed
>> use of __SIGRTMAX except for in this QEMU_BUILD_BUG_ON assert.
>> Presumably, this check is to ensure that the loop in signal_table_init
>> from SIGRTMIN to SIGRTMAX falls within the bounds of
>> host_to_target_signal_table (_NSIG).
>>
>> However, _NSIG is already defined to be the one larger than the
>> largest signal supported by the system (as specified in the upcoming
>> POSIX revision[0]), so the check is unnecessary.
>>
>> musl libc does not define __SIGRTMAX, so removing this check fixes
>> one of the last remaining errors when building qemu.
>>
>> [0] https://www.austingroupbugs.net/view.php?id=741
>>
>> Signed-off-by: Michael Forney <mforney@mforney.org>
>> ---
>> If you prefer, I can send an alternate patch to leave the
>> QEMU_BUILD_BUG_ON, but guard it by #ifdef __SIGRTMAX.
> 
> This looks safer, personally I prefer, but let's see what the
> maintainers prefer.

I agree, the reason of the check is explained in the comment above.

I think it's safer to keep the QEMU_BUILD_BUG_ON().

In the past we had a confusion between _NSIG, NSIG and TARGET_NSIG.

See 9fcff3a67f2b ("linux-user: fix TARGET_NSIG and _NSIG uses")

Thanks,
Laurent

Re: [PATCH] linux-user: Remove unnecessary static assert involving __SIGRTMAX
Posted by Laurent Vivier 2 years, 10 months ago
Le 26/05/2021 à 06:39, Michael Forney a écrit :
> Since "linux-user: fix use of SIGRTMIN" (6bc024e7), qemu removed
> use of __SIGRTMAX except for in this QEMU_BUILD_BUG_ON assert.
> Presumably, this check is to ensure that the loop in signal_table_init
> from SIGRTMIN to SIGRTMAX falls within the bounds of
> host_to_target_signal_table (_NSIG).
> 
> However, _NSIG is already defined to be the one larger than the
> largest signal supported by the system (as specified in the upcoming
> POSIX revision[0]), so the check is unnecessary.
> 
> musl libc does not define __SIGRTMAX, so removing this check fixes
> one of the last remaining errors when building qemu.
> 
> [0] https://www.austingroupbugs.net/view.php?id=741
> 
> Signed-off-by: Michael Forney <mforney@mforney.org>
> ---
> If you prefer, I can send an alternate patch to leave the
> QEMU_BUILD_BUG_ON, but guard it by #ifdef __SIGRTMAX.
> 
>  linux-user/signal.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index 9016896dcd..6f62f2b528 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -38,7 +38,6 @@ static void host_signal_handler(int host_signum, siginfo_t *info,
>   * Signal number 0 is reserved for use as kill(pid, 0), to test whether
>   * a process exists without sending it a signal.
>   */
> -QEMU_BUILD_BUG_ON(__SIGRTMAX + 1 != _NSIG);
>  static uint8_t host_to_target_signal_table[_NSIG] = {
>      [SIGHUP] = TARGET_SIGHUP,
>      [SIGINT] = TARGET_SIGINT,
> 

Applied to my linux-user-for-6.1 branch.

Thanks,
Laurent



[PATCH v2] linux-user: Disable static assert involving __SIGRTMAX if it is missing
Posted by Michael Forney 2 years, 10 months ago
This check is to ensure that the loop in signal_table_init() from
SIGRTMIN to SIGRTMAX falls within the bounds of host_to_target_signal_table
(_NSIG). However, it is not critical, since _NSIG is already defined
to be the one larger than the largest signal supported by the system
(as specified in the upcoming POSIX revision[0]).

musl libc does not define __SIGRTMAX, so disabling this check when
it is missing fixes one of the last remaining errors when building
qemu.

[0] https://www.austingroupbugs.net/view.php?id=741

Signed-off-by: Michael Forney <mforney@mforney.org>
---
Changes since v2:
* Guard check by #ifdef __SIGRTMAX instead of removing it.

 linux-user/signal.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 9016896dcd..0f19c59dee 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -38,7 +38,9 @@ static void host_signal_handler(int host_signum, siginfo_t *info,
  * Signal number 0 is reserved for use as kill(pid, 0), to test whether
  * a process exists without sending it a signal.
  */
+#ifdef __SIGRTMAX
 QEMU_BUILD_BUG_ON(__SIGRTMAX + 1 != _NSIG);
+#endif
 static uint8_t host_to_target_signal_table[_NSIG] = {
     [SIGHUP] = TARGET_SIGHUP,
     [SIGINT] = TARGET_SIGINT,
-- 
2.31.1


Re: [PATCH v2] linux-user: Disable static assert involving __SIGRTMAX if it is missing
Posted by Laurent Vivier 2 years, 10 months ago
Le 26/05/2021 à 21:02, Michael Forney a écrit :
> This check is to ensure that the loop in signal_table_init() from
> SIGRTMIN to SIGRTMAX falls within the bounds of host_to_target_signal_table
> (_NSIG). However, it is not critical, since _NSIG is already defined
> to be the one larger than the largest signal supported by the system
> (as specified in the upcoming POSIX revision[0]).
> 
> musl libc does not define __SIGRTMAX, so disabling this check when
> it is missing fixes one of the last remaining errors when building
> qemu.
> 
> [0] https://www.austingroupbugs.net/view.php?id=741
> 
> Signed-off-by: Michael Forney <mforney@mforney.org>
> ---
> Changes since v2:
> * Guard check by #ifdef __SIGRTMAX instead of removing it.
> 
>  linux-user/signal.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index 9016896dcd..0f19c59dee 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -38,7 +38,9 @@ static void host_signal_handler(int host_signum, siginfo_t *info,
>   * Signal number 0 is reserved for use as kill(pid, 0), to test whether
>   * a process exists without sending it a signal.
>   */
> +#ifdef __SIGRTMAX
>  QEMU_BUILD_BUG_ON(__SIGRTMAX + 1 != _NSIG);
> +#endif
>  static uint8_t host_to_target_signal_table[_NSIG] = {
>      [SIGHUP] = TARGET_SIGHUP,
>      [SIGINT] = TARGET_SIGINT,
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>