Opened 3 months ago
Closed 3 months ago
#19095 closed bug (fixed)
pthread functions hidden under _GNU_SOURCE
Reported by: | brad0 | Owned by: | nobody |
---|---|---|---|
Priority: | normal | Milestone: | Unscheduled |
Component: | System/POSIX | Version: | R1/beta5 |
Keywords: | r1beta5-fixes | Cc: | |
Blocked By: | Blocking: | ||
Platform: | All |
Description
I was working on a patch for LLVM/Clang to add support for setting POSIX thread names. As I've done for gazillions of other projects in the same manner.
I was searching around and noticed this commit for Haiku adding the POSIX threads functions most other OS's have for setting thread names.
https://github.com/haiku/haiku/commit/44cceee67e056d8e34cb017d5f5c07b9fac874c0
I made the miniminal changes to LLVM/Clang to use said API and thought things were good, but then noticed CMake was not detecting the functions that looked to be there.
Digging further I noticed headers/compatibility/gnu/pthread.h hides the functions by default, defeating the purpose of adding the functions. None of the other OS's, FreeBSD/NetBSD/OpenBSD/DragonFly BSD, Solaris, Linux, etc. hide the functions like Haiku does.
Change History (6)
follow-up: 2 comment:1 by , 3 months ago
Component: | - General → System/POSIX |
---|
comment:2 by , 3 months ago
Replying to waddlesplash:
This is deliberate. We don't want to define anything past the POSIX specification in default headers if a strict mode is enabled.
But in this scenario a strict mode is not enabled. e.g. _POSIX_C_SOURCE. Yes, this has been a source of problems with a tiny few projects.
This is building code like cc -c foo.c -o foo.o. Without any other flags.
This file is in the default include path, and while it doesn't include "features.h" directly, it looks as though it is included indirectly through the main
pthread.h
's includes (unless I've missed something). Infeatures.h
, we gate all non-POSIX functions (in POSIX header names anyway) behind_DEFAULT_SOURCE
; which we disable if__STRICT_ANSI__
is defined.By default, GCC and Clang define this in
-std=c...
mode, while they don't define it in-std=gnu...
mode. If you want these and other non-POSIX methods, then probably the build systems in question should be adjusted to permit the headers to define them (or just define_BSD_SOURCE
, or undefine__STRICT_ANSI__
before including something that includesfeatures.h
and then pthreads in the appropriate files.)And it isn't true that no other OS does this; FreeBSD for example puts them behind
__BSD_VISIBLE
, as you can see in theirinclude/pthread.h
. It appears (in theircdefs.h
) that they don't define__BSD_VISIBLE
if various standards-mode definitions are set, though admittedly__STRICT_ANSI__
doesn't seem to be one of them.
Yes, but building without any special flags as is the case here the functions are exposed and that is the case for all of the OS's I mentioned including FreeBSD. The behavior between the other OS's and Haiku is not the same.
Unless you see something I've missed, I think this ticket should be closed as invalid, and upstream patched to not define a strict standards-mode when it doesn't want that.
(Either way, thanks for working on adding more Haiku support to upstream projects!)
comment:3 by , 3 months ago
Ah, it appears the file uses _GNU_SOURCE guards and not _DEFAULT_SOURCE; that looks like an oversight, indeed. So there is a bug we should fix here.
I'll fix it next week if nobody beats me to it.
comment:4 by , 3 months ago
This doesn't match what I see on Ubuntu:
echo -e "#include <pthread.h>" | gcc -E - | grep pthread_setname_np echo -e "#define _GNU_SOURCE\n#include <pthread.h>" | gcc -E - | grep pthread_setname_np extern int pthread_setname_np (pthread_t __target_thread, const char *__name)
without flags pthread_setname_np isn't found.
comment:6 by , 3 months ago
Keywords: | r1beta5-fixes added |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Fixed in hrev58152 +beta5.
This is deliberate. We don't want to define anything past the POSIX specification in default headers if a strict mode is enabled.
This file is in the default include path, and while it doesn't include "features.h" directly, it looks as though it is included indirectly through the main
pthread.h
's includes (unless I've missed something). Infeatures.h
, we gate all non-POSIX functions (in POSIX header names anyway) behind_DEFAULT_SOURCE
; which we disable if__STRICT_ANSI__
is defined.By default, GCC and Clang define this in
-std=c...
mode, while they don't define it in-std=gnu...
mode. If you want these and other non-POSIX methods, then probably the build systems in question should be adjusted to permit the headers to define them (or just define_BSD_SOURCE
, or undefine__STRICT_ANSI__
before including something that includesfeatures.h
and then pthreads in the appropriate files.)And it isn't true that no other OS does this; FreeBSD for example puts them behind
__BSD_VISIBLE
, as you can see in theirinclude/pthread.h
. It appears (in theircdefs.h
) that they don't define__BSD_VISIBLE
if various standards-mode definitions are set, though admittedly__STRICT_ANSI__
doesn't seem to be one of them.Unless you see something I've missed, I think this ticket should be closed as invalid, and upstream patched to not define a strict standards-mode when it doesn't want that.
(Either way, thanks for working on adding more Haiku support to upstream projects!)