Skip to contentSkip to conversation

kconfig/kbuild: define _POSIX_C_SOURCE

PATCH In review Valentin Ochs 3 participants 6 messages Apr 10, 2011 – Apr 19, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kconfig/kbuild: define _POSIX_C_SOURCE

The three patched files use PATH_MAX without defining the required _POSIX_C_SOURCE feature test macro. This prevents compilation with the musl libc. The patch applies to 2.6.38.2.

Changes since v1:
- fix scripts/kconfig/lex.zconf.c_shipped
- fix scripts/kconfig/mconf.c

Sorry about the incomplete patch I sent a few hours ago, it won't happen again. :)

Best regards,
Valentin

---

scripts/basic/fixdep.c +1 -0
@@ -102,7 +102,7 @@
  * through arch/um/include/uml-config.h; this fixdep "bug" makes sure that
  * those files will have correct dependencies.
  */
 
+#define _POSIX_C_SOURCE 200809L
 #include <sys/types.h>
 #include <sys/stat.h>

#include <sys/mman.h>

scripts/kconfig/lex.zconf.c_shipped +1 -0
@@ -35,6 +35,7 @@
 /* First, we deal with  platform-specific or compiler-specific issues. */
 
 /* begin standard C headers. */
+#define _POSIX_C_SOURCE 200809L
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
scripts/kconfig/mconf.c +1 -0
@@ -7,7 +7,7 @@
  *
  * i18n, 2005, Arnaldo Carvalho de Melo <[email protected]>
  */
 
+#define _POSIX_C_SOURCE 200809L
 #include <ctype.h>
 #include <errno.h>

#include <fcntl.h>

#1 lore raw

Hi,

Quoted 6 lines · Valentin Ochs

The three patched files use PATH_MAX without defining the required _POSIX_C_SOURCE feature test macro.  This prevents compilation with the musl libc.  The patch applies to 2.6.38.2.

Changes since v1:
 - fix scripts/kconfig/lex.zconf.c_shipped

this file is autogenerated from zconf.l, which should be updated as well. I'm not sure how you searched for PATH_MAX, but you're still missing confdata.c' and nconf.c'.

I had a quick look to different libc implementation, glibc and uClibc default to _POSIX_C_SOURCE == 200112L, FreeBSD >8.0 defaults to 200809L for >8.0, FreeBSD 7.x to 200112L. None of these seems to requires _POSIX_C_SOURCE to define PATH_MAX, so I'm not certain of the requirement of the change. Moreover, musl libc seems to be really young (first public version less than two month old), and still marked "alpha", not sure if its the best time to start fixing things.

- Arnaud

Quoted 47 lines

 - fix scripts/kconfig/mconf.c

Sorry about the incomplete patch I sent a few hours ago, it won't happen again. :)

Best regards,
Valentin

---

scripts/basic/fixdep.c +1 -0
@@ -102,7 +102,7 @@
  * through arch/um/include/uml-config.h; this fixdep "bug" makes sure that
  * those files will have correct dependencies.
  */
 
+#define _POSIX_C_SOURCE 200809L
  #include <sys/types.h>
  #include <sys/stat.h>

 #include <sys/mman.h>

scripts/kconfig/lex.zconf.c_shipped +1 -0
@@ -35,6 +35,7 @@
  /* First, we deal with  platform-specific or compiler-specific issues. */
 
  /* begin standard C headers. */
+#define _POSIX_C_SOURCE 200809L
  #include <stdio.h>
  #include <string.h>
  #include <errno.h>
scripts/kconfig/mconf.c +1 -0
@@ -7,7 +7,7 @@
  *
  * i18n, 2005, Arnaldo Carvalho de Melo <[email protected]>
  */
 
+#define _POSIX_C_SOURCE 200809L
  #include <ctype.h>
  #include <errno.h>

 #include <fcntl.h>
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#2 lore raw

Thanks for the answer!

Quoted 7 lines · Arnaud Lacombe

Hi,

Quoted 4 lines · Valentin Ochs

The three patched files use PATH_MAX without defining the required _POSIX_C_SOURCE feature test macro.  This prevents compilation with the musl libc.  The patch applies to 2.6.38.2.

Quoted 5 lines
Quoted 2 lines

Changes since v1:
 - fix scripts/kconfig/lex.zconf.c_shipped

this file is autogenerated from zconf.l, which should be updated as well. I'm not sure how you searched for PATH_MAX, but you're still missing confdata.c' and nconf.c'.

To be honest, I only fixed the files that did not compile when I ran 'make menuconfig'. It didn't even occur to me that it could be in other files as well. I've grepped for it now, and there are lots of other files that use PATH_MAX - it's probably safe to assume that kernel/* and fs/* use the limits.h in include/linux. What about the files in tools/*? Would it be preferable to have the makefile define _POSIX_C_SOURCE, or is that too hackish?

Quoted 3 lines

I had a quick look to different libc implementation, glibc and uClibc default to _POSIX_C_SOURCE == 200112L, FreeBSD >8.0 defaults to 200809L for >8.0, FreeBSD 7.x to 200112L.

I got the value I used from the Open Group System Interfaces specification, but the musl author said that 200112L would be fine too.

Quoted 2 lines

None of these seems to requires _POSIX_C_SOURCE to define PATH_MAX, so I'm not certain of the requirement of the change.

While I don't want to appear like a language lawyer, the specification says that 'all symbols required by POSIX.1-2008 to appear when the header is included shall be made visible' when an application defines _POSIX_C_SOURCE. I guess the musl author interprets that as 'if you don't define the feature test macros, you're not getting PATH_MAX.' This does not seem to be incorrect behaviour to me.

Quoted 3 lines

Moreover, musl libc seems to be really young (first public version less than two month old), and still marked "alpha", not sure if its the best time to start fixing things.

I don't think that the musl headers are going to change much in that regard, and the patch only changes the files to better conform to POSIX. But if you don't want to apply the patch now, I can resubmit it in a few months and just ask the musl author to put it on the musl website for now.

Best regards,
Valentin

Quoted 6 lines

- Arnaud

Quoted 4 lines

 - fix scripts/kconfig/mconf.c

Sorry about the incomplete patch I sent a few hours ago, it won't happen again. :)

#3 lore raw
Quoted 11 lines · Valentin Ochs
Quoted 10 lines · Arnaud Lacombe
Quoted 6 lines · Valentin Ochs

The three patched files use PATH_MAX without defining the required _POSIX_C_SOURCE feature test macro. This prevents compilation with the musl libc. The patch applies to 2.6.38.2.

Changes since v1:
- fix scripts/kconfig/lex.zconf.c_shipped

this file is autogenerated from zconf.l, which should be updated as well. I'm not sure how you searched for PATH_MAX, but you're still missing confdata.c' and nconf.c'.

Yes, please fix the bison parser and run make GENERATE_PARSER=1 menuconfig to update the *_shipped files.

Quoted 6 lines
Quoted 3 lines

I had a quick look to different libc implementation, glibc and uClibc default to _POSIX_C_SOURCE == 200112L, FreeBSD >8.0 defaults to 200809L for >8.0, FreeBSD 7.x to 200112L.

I got the value I used from the Open Group System Interfaces specification, but the musl author said that 200112L would be fine too.

I suggest you use 200112L, so that it is a nop for glibc/uClibc builds. Please also accompany it with a /* for PATH_MAX */ comment or so.

Quoted 10 lines
Quoted 3 lines

None of these seems to requires _POSIX_C_SOURCE to define PATH_MAX, so I'm not certain of the requirement of the change.

While I don't want to appear like a language lawyer, the specification says that 'all symbols required by POSIX.1-2008 to appear when the header is included shall be made visible' when an application defines _POSIX_C_SOURCE. I guess the musl author interprets that as 'if you don't define the feature test macros, you're not getting PATH_MAX.' This does not seem to be incorrect behaviour to me.

While I don't completely understand the motivation for such super-pedantic libc implementation, the fact is that POSIX says one should define this macro, so let's define it, it does not hurt us.

Michal

#4 lore raw

Hi,

Quoted 21 lines · Michal Marek
Quoted 11 lines · Valentin Ochs
Quoted 10 lines · Arnaud Lacombe
Quoted 6 lines · Valentin Ochs

The three patched files use PATH_MAX without defining the required _POSIX_C_SOURCE feature test macro.  This prevents compilation with the musl libc.  The patch applies to 2.6.38.2.

Changes since v1:
 - fix scripts/kconfig/lex.zconf.c_shipped

this file is autogenerated from zconf.l, which should be updated as well. I'm not sure how you searched for PATH_MAX, but you're still missing confdata.c' and nconf.c'.

Yes, please fix the bison parser and run make GENERATE_PARSER=1 menuconfig to update the *_shipped files.

Quoted 4 lines
Quoted 3 lines

I had a quick look to different libc implementation, glibc and uClibc default to _POSIX_C_SOURCE == 200112L, FreeBSD >8.0 defaults to 200809L for >8.0, FreeBSD 7.x to 200112L.

Quoted 6 lines
Quoted 2 lines

I got the value I used from the Open Group System Interfaces specification, but the musl author said that 200112L would be fine too.

I suggest you use 200112L, so that it is a nop for glibc/uClibc builds. Please also accompany it with a /* for PATH_MAX */ comment or so.

no it's not. Defining _POSIX_C_SOURCE disables automatic definition of a few features macros, see below.

Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

None of these seems to requires _POSIX_C_SOURCE to define PATH_MAX, so I'm not certain of the requirement of the change.

While I don't want to appear like a language lawyer, the specification says that 'all symbols required by POSIX.1-2008 to appear when the header is included shall be made visible' when an application defines _POSIX_C_SOURCE. I guess the musl author interprets that as 'if you don't define the feature test macros, you're not getting PATH_MAX.' This does not seem to be incorrect behaviour to me.

Quoted 4 lines

While I don't completely understand the motivation for such super-pedantic libc implementation, the fact is that POSIX says one should define this macro, so let's define it, it does not hurt us.

If we go that way, we should at least:

Makefile +0 -0
index d6592b6..0490413 100644
@@ -233,7 +233,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then

echo $$BASH; \

 HOSTCC       = gcc
 HOSTCXX      = g++
-HOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2

-fomit-frame-pointer
+HOSTCFLAGS = -D_POSIX_C_SOURCE=200112L -Wall -Wmissing-prototypes
-Wstrict-prototypes -O2 -fomit-frame-pointer
HOSTCXXFLAGS = -O2

at best:

index d6592b6..0490413 100644

Makefile +0 -0
@@ -233,7 +233,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then

echo $$BASH; \

 HOSTCC       = gcc
 HOSTCXX      = g++
-HOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2

-fomit-frame-pointer
+HOSTCFLAGS = --std=c99 -D_POSIX_C_SOURCE=200112L -Wall
-Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
HOSTCXXFLAGS = -O2

Both introduces new warnings with the glibc shipped with fedora 14 relating to strdup(3) needing one of: _SVID_SOURCE, _BSD_SOURCE, _XOPEN_SOURCE, _POSIX_C_SOURCE>=200809L (for __USE_XOPEN2K8). -D_POSIX_C_SOURCE=200809L do not generate more warning, at least on my host.

Just for reference, the second change fails anyway as `nconf' uses GNU extension of C99.

- Arnaud

Quoted 6 lines

Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#5 lore raw

Hi,

Quoted 13 lines · Arnaud Lacombe
Makefile +0 -0
index d6592b6..0490413 100644
@@ -233,7 +233,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then
 echo $$BASH; \
 

 HOSTCC       = gcc
 HOSTCXX      = g++

Makefile +1 -3
-HOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2
-fomit-frame-pointer
+HOSTCFLAGS   = -D_POSIX_C_SOURCE=200112L -Wall -Wmissing-prototypes
-Wstrict-prototypes -O2 -fomit-frame-pointer
Quoted 2 lines

 HOSTCXXFLAGS = -O2

Sorry, gmail wrapped long lines, the relevant part is only:

HOSTCFLAGS+= -D_POSIX_C_SOURCE=200112L

- Arnaud