Defining _GNU_SOURCE for module-map-included headers


(Dan Stenmark) #1

I'm trying to invoke Linux's unshare() system call from Swift, but without much success. From C, it requires _GNU_SOURCE to be #define'd before the #include <sched.h>. The Glibc module map does indeed include sched.h, so the lack of _GNU_SOURCE appears to be the likely culprit. What's the appropriate action to take here?

Dan


(Dmitri Gribenko) #2

+ swift-dev, Jordan

···

On Sun, Dec 20, 2015 at 2:21 AM, Dan Stenmark via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

I'm trying to invoke Linux's unshare() system call from Swift, but without much success. From C, it requires _GNU_SOURCE to be #define'd before the #include <sched.h>. The Glibc module map does indeed include sched.h, so the lack of _GNU_SOURCE appears to be the likely culprit. What's the appropriate action to take here?

Dan
_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/


(Jordan Rose) #3

Hm. If this is the right setting to set on everybody's system, we could add it as part of Clang initialization (for the Clang inside Swift). Otherwise, you can use "-Xcc" to pass extra flags to Clang, in this case "-Xcc -D_GNU_SOURCE=1".

Hope that helps,
Jordan

···

On Dec 20, 2015, at 2:29 , Dmitri Gribenko <gribozavr@gmail.com> wrote:

+ swift-dev, Jordan

On Sun, Dec 20, 2015 at 2:21 AM, Dan Stenmark via swift-corelibs-dev > <swift-corelibs-dev@swift.org> wrote:

I'm trying to invoke Linux's unshare() system call from Swift, but without much success. From C, it requires _GNU_SOURCE to be #define'd before the #include <sched.h>. The Glibc module map does indeed include sched.h, so the lack of _GNU_SOURCE appears to be the likely culprit. What's the appropriate action to take here?

Dan
_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/


(Pierre Habouzit) #4

Hm. If this is the right setting to set on everybody's system, we could add it as part of Clang initialization (for the Clang inside Swift). Otherwise, you can use "-Xcc" to pass extra flags to Clang, in this case "-Xcc -D_GNU_SOURCE=1”.

You definitely want -D_GNU_SOURCE=1 on linux systems, as all the non portable calls (that also are the interesting ones) will be hidden behind this.

···

On Dec 21, 2015, at 9:34 AM, Jordan Rose via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Hope that helps,
Jordan

On Dec 20, 2015, at 2:29 , Dmitri Gribenko <gribozavr@gmail.com> wrote:

+ swift-dev, Jordan

On Sun, Dec 20, 2015 at 2:21 AM, Dan Stenmark via swift-corelibs-dev >> <swift-corelibs-dev@swift.org> wrote:

I'm trying to invoke Linux's unshare() system call from Swift, but without much success. From C, it requires _GNU_SOURCE to be #define'd before the #include <sched.h>. The Glibc module map does indeed include sched.h, so the lack of _GNU_SOURCE appears to be the likely culprit. What's the appropriate action to take here?

Dan
_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev


(Jordan Rose) #5

Seems reasonable. If anyone wants to fix this, the relevant function is getNormalInvocationArguments <https://github.com/apple/swift/blob/master/lib/ClangImporter/ClangImporter.cpp#L265> in ClangImporter.cpp; otherwise, please file a bug report at https://bugs.swift.org <https://bugs.swift.org/>.

Thanks,
Jordan

···

On Dec 21, 2015, at 10:57 , Pierre Habouzit <pierre@habouzit.net> wrote:

On Dec 21, 2015, at 9:34 AM, Jordan Rose via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

Hm. If this is the right setting to set on everybody's system, we could add it as part of Clang initialization (for the Clang inside Swift). Otherwise, you can use "-Xcc" to pass extra flags to Clang, in this case "-Xcc -D_GNU_SOURCE=1”.

You definitely want -D_GNU_SOURCE=1 on linux systems, as all the non portable calls (that also are the interesting ones) will be hidden behind this.


(Pierre Habouzit) #6

FWIW the effect of _GNU_SOURCE is documented in <features.h> on linux, and that’s also how you get 64bit vfs call (large file support) etc…
autotools give you _GNU_SOURCE by default usually e.g.

I double checked, _GNU_SOURCE is enough to get all the bits and pieces that you care about (at* calls, _BSD_SOURCE, etc…)

-Pierre

···

On Dec 21, 2015, at 11:00 AM, Jordan Rose <jordan_rose@apple.com> wrote:

On Dec 21, 2015, at 10:57 , Pierre Habouzit <pierre@habouzit.net <mailto:pierre@habouzit.net>> wrote:

On Dec 21, 2015, at 9:34 AM, Jordan Rose via swift-corelibs-dev <swift-corelibs-dev@swift.org <mailto:swift-corelibs-dev@swift.org>> wrote:

Hm. If this is the right setting to set on everybody's system, we could add it as part of Clang initialization (for the Clang inside Swift). Otherwise, you can use "-Xcc" to pass extra flags to Clang, in this case "-Xcc -D_GNU_SOURCE=1”.

You definitely want -D_GNU_SOURCE=1 on linux systems, as all the non portable calls (that also are the interesting ones) will be hidden behind this.

Seems reasonable. If anyone wants to fix this, the relevant function is getNormalInvocationArguments <https://github.com/apple/swift/blob/master/lib/ClangImporter/ClangImporter.cpp#L265> in ClangImporter.cpp; otherwise, please file a bug report at https://bugs.swift.org <https://bugs.swift.org/>.

Thanks,
Jordan