NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

standards/58275: Many incorrect feature test macro checks



>Number:         58275
>Category:       standards
>Synopsis:       Many incorrect feature test macro checks
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    standards-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 23 05:25:00 +0000 2024
>Originator:     Guilherme Janczak
>Release:        NetBSD 10, NetBSD-current
>Organization:
>Environment:
NetBSD jan-evo-nbsd 10.0 NetBSD 10.0 (GENERIC) #0: Thu Mar 28 08:33:33 UTC 2024  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/i386/compile/GENERIC i386

>Description:
Many feature tests in NetBSD's <unistd.h> do not declare functions even though the appropriate feature test macro is defined by the program, or declare it even though the defined feature test macro isn't supposed to declare the function. 

References:
System Interfaces and Headers, Issue 4, Version 2: https://pubs.opengroup.org/onlinepubs/9695969499/toc.pdf
System Interfaces and Headers, Issue 5: https://pubs.opengroup.org/onlinepubs/009639399/toc.pdf
System Interfaces and Headers, Issue 6 (IEEE Std 1003.1, 2004 XSH): https://pubs.opengroup.org/onlinepubs/009695399/
System Interfaces and Headers, Issue 7 (IEEE Std 1003.1?-2008 XSH): https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/

In this block of code in the latest NetBSD-current:
https://github.com/NetBSD/src/blob/a0c1e9831a7c5c572cfbe62e09d597893299b98c/include/unistd.h#L248-L296
I see the following problems:

sbrk(), brk(), getdablesize(), getpagesize() were:
- Introduced on Issue 4, version 2.
- Marked LEGACY on Issue 5
- Not present on Issue 6.
However, NetBSD still declares them even if _XOPEN_SOURCE >= 600, but they're not part of that standard. This violates POSIX 2001 or later, which states in https://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_02.html#tag_02_02 that:
"Additional symbols not required or explicitly permitted by IEEE Std 1003.1-2001 to be in that header shall not be made visible, except when enabled by another feature test macro."

ualarm() and usleep() were:
- Introduced on Issue 4, version 2.
- Marked Obsolescent on Issue 6 (https://pubs.opengroup.org/onlinepubs/009695399/functions/ualarm.html#tag_03_796_13 https://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html#tag_03_805_13)
- Not present on Issue 7
However, NetBSD still declares it even when _XOPEN_SOURCE >= 700, violating POSIX for the same reason as the other functions above.

setpgrp() isn't compliant with any of the referenced standards, the declaration isn't compatible: the X/Open and POSIX version has a (void) prototype, NetBSD has a (pid_t, pid_t) prototype. It must only be declared if NetBSD's implementation-defined feature test macro is enabled, it's currently declared where a standards-compliant version must be.

getpgid(), and fchdir() were moved from the XSI option to base in Issue 7: https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/functions/getpgid.html https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/functions/fchdir.html
This means that they must to be changed to also be declared if _POSIX_C_SOURCE >= 200809L.

gethostname() was "First released in Issue 6. Derived from the XNS, Issue 5.2 specification": https://pubs.opengroup.org/onlinepubs/009695399/functions/gethostname.html 
The function is currently declared when the user defines feature test macro values that predate it. It must only be declared if _XOPEN_SOURCE >= 520 || defined(_NETBSD_SOURCE), as 520 is XNS Issue 5.2's _XOPEN_SOURCE value according to https://pubs.opengroup.org/onlinepubs/009619199/chap1.htm#tagcjh_02_03 and POSIX says it's an XSI extension.

symlink() and fchown() aren't marked XSI according to https://pubs.opengroup.org/onlinepubs/9699919799/functions/symlink.html https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchown.html
This means that they must also be declared if _POSIX_C_SOURCE >= 200112L. I started going down the rabbit role of this problem report because https://github.com/zlib-ng/minizip-ng/commit/5aec551bf78ed79f6bec3160a5c7ce7fdac66776 doesn't compile on NetBSD 10.0 because of this bug in NetBSD's unistd.h.


I expect that other headers on NetBSD and other parts of unistd.h contain more errors of this kind. Careful reading of the standards and the headers is needed. This took me many hours to make.

>How-To-Repeat:

>Fix:
OpenBSD's unistd.h looks more compliant, it might be worth using as inspiration for NetBSD's unistd.h and all other headers, specially their internal __POSIX_VISIBLE and __XPG_VISIBLE macros, but be careful, OpenBSD also has similar errors.



Home | Main Index | Thread Index | Old Index