From 85db59b794d1ca7f16ea816c916bb4472958cc1b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 25 Dec 2017 12:01:14 +0100 Subject: [PATCH 1/4] meson: use "args" for setting _GNU_SOURCE when checking for functions This reworks how we set _GNU_SOURCE when checking for the availability of functions: 1. We set it for most of the functions we look for. After all we set it for our entire built anyway, and it's usually how Linux-specific definitions in glibc are protected these days. Given that we usually have checks for such modern stuff only anyway, let's just blanket enable it. 2. Use "args" instead of "prefix" to set the macro. This is what is suggested in the meson docs, hence let's do it. --- meson.build | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/meson.build b/meson.build index f3a65b3893..eda9e382bf 100644 --- a/meson.build +++ b/meson.build @@ -454,33 +454,29 @@ foreach ident : ['secure_getenv', '__secure_getenv'] endforeach foreach ident : [ - ['memfd_create', '''#define _GNU_SOURCE - #include '''], + ['memfd_create', '''#include '''], ['gettid', '''#include '''], ['pivot_root', '''#include '''], # no known header declares pivot_root - ['name_to_handle_at', '''#define _GNU_SOURCE - #include + ['name_to_handle_at', '''#include #include #include '''], - ['setns', '''#define _GNU_SOURCE - #include '''], + ['setns', '''#include '''], ['renameat2', '''#include '''], ['kcmp', '''#include '''], ['keyctl', '''#include #include '''], - ['copy_file_range', '''#define _GNU_SOURCE - #include + ['copy_file_range', '''#include #include '''], ['bpf', '''#include #include '''], ['explicit_bzero' , '''#include '''], ] - have = cc.has_function(ident[0], prefix : ident[1]) + have = cc.has_function(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') conf.set10('HAVE_' + ident[0].to_upper(), have) endforeach -if cc.has_function('getrandom', prefix : '''#include ''') +if cc.has_function('getrandom', prefix : '''#include ''', args : '-D_GNU_SOURCE') conf.set10('USE_SYS_RANDOM_H', true) conf.set10('HAVE_GETRANDOM', true) else From 3c042add1db8948d7ed03be701fe097529785e77 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 25 Dec 2017 12:07:40 +0100 Subject: [PATCH 2/4] meson: when pivot_root() is added one day, look for it in We of course don't know in which header glibc will export pivot_root() and if it ever will. But there's a good chance they'll place it where chroot() is located, given the similarity in the operations, hence let's try our luck and look for it at the same place. If we are lucky this means we don't have to patch our code if glibc decides to expose the call one day. --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index eda9e382bf..9911afb0e7 100644 --- a/meson.build +++ b/meson.build @@ -456,7 +456,8 @@ endforeach foreach ident : [ ['memfd_create', '''#include '''], ['gettid', '''#include '''], - ['pivot_root', '''#include '''], # no known header declares pivot_root + ['pivot_root', '''#include + #include '''], # no known header declares pivot_root ['name_to_handle_at', '''#include #include #include '''], From 7b961e40ee5cd5c453cad70906327ea5a11fa75e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 25 Dec 2017 12:35:28 +0100 Subject: [PATCH 3/4] meson: look for gettid() definition where getpid() is defined Hopefully, should gettid() show up one day in glibc it'll show up where getpid() is defined too. --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 9911afb0e7..9fc45abc02 100644 --- a/meson.build +++ b/meson.build @@ -455,7 +455,8 @@ endforeach foreach ident : [ ['memfd_create', '''#include '''], - ['gettid', '''#include '''], + ['gettid', '''#include + #include '''], ['pivot_root', '''#include #include '''], # no known header declares pivot_root ['name_to_handle_at', '''#include From 2acfd0ff439b6317f91c32f6dbb42e9ce06b8943 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 25 Dec 2017 12:35:43 +0100 Subject: [PATCH 4/4] meson: hopefully renameat2() will show up where renameat() is defined Should glibc add this eventually, let's try to be smart where to look for it. --- meson.build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 9fc45abc02..c582c1b4ee 100644 --- a/meson.build +++ b/meson.build @@ -463,7 +463,8 @@ foreach ident : [ #include #include '''], ['setns', '''#include '''], - ['renameat2', '''#include '''], + ['renameat2', '''#include + #include '''], ['kcmp', '''#include '''], ['keyctl', '''#include #include '''],