Message ID | 068f343a62de3dbc3764d0ad98111881b04a60d2.1685346951.git.mprivozn@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | meson: Avoid implicit declaration of functions | expand |
On Mon, 29 May 2023 at 08:58, Michal Privoznik <mprivozn@redhat.com> wrote: > > While detecting a presence of a function via 'cc.links()' > gives desired result (i.e. detects whether function is present), > it also produces a warning on systems where the function is not > present, e.g.: > > qemu.git/build/meson-private/tmph74x3p38/testfile.c:2:34: \ > warning: implicit declaration of function 'malloc_trim' [-Wimplicit-function-declaration] Produces a warning where ? On stdout/stderr ? The linked bug report says "in the configure logs" which is kinda vague. Warnings in the logfiles are not a problem; warnings in the terminal output are... > diff --git a/meson.build b/meson.build > index 2d48aa1e2e..5da4dbac24 100644 > --- a/meson.build > +++ b/meson.build > @@ -1797,6 +1797,7 @@ malloc = [] > if get_option('malloc') == 'system' > has_malloc_trim = \ > get_option('malloc_trim').allowed() and \ > + cc.has_function('malloc_trim', prefix: '#include <malloc.h>') and \ > cc.links('''#include <malloc.h> > int main(void) { malloc_trim(0); return 0; }''') > else This seems super clunky -- surely this isn't the way Meson intends people to write tests ? thanks -- PMM
On 5/29/23 12:24, Peter Maydell wrote: > On Mon, 29 May 2023 at 08:58, Michal Privoznik <mprivozn@redhat.com> wrote: >> >> While detecting a presence of a function via 'cc.links()' >> gives desired result (i.e. detects whether function is present), >> it also produces a warning on systems where the function is not >> present, e.g.: >> >> qemu.git/build/meson-private/tmph74x3p38/testfile.c:2:34: \ >> warning: implicit declaration of function 'malloc_trim' [-Wimplicit-function-declaration] > > Produces a warning where ? On stdout/stderr ? > > The linked bug report says "in the configure logs" > which is kinda vague. Warnings in the logfiles are > not a problem; warnings in the terminal output are... It seems to be a lint: * QA Notice: Found the following implicit function declarations in configure logs: * /var/tmp/portage/app-emulation/qemu-7.2.0-r3/work/qemu-7.2.0/tools-build/meson-logs/meson-log.txt:562 - malloc_trim * /var/tmp/portage/app-emulation/qemu-7.2.0-r3/work/qemu-7.2.0/tools-build/meson-logs/meson-log.txt:591 - statx * /var/tmp/portage/app-emulation/qemu-7.2.0-r3/work/qemu-7.2.0/tools-build/meson-logs/meson-log.txt:627 - statx * /var/tmp/portage/app-emulation/qemu-7.2.0-r3/work/qemu-7.2.0/softmmu-build/meson-logs/meson-log.txt:718 - malloc_trim * /var/tmp/portage/app-emulation/qemu-7.2.0-r3/work/qemu-7.2.0/softmmu-build/meson-logs/meson-log.txt:747 - statx * /var/tmp/portage/app-emulation/qemu-7.2.0-r3/work/qemu-7.2.0/softmmu-build/meson-logs/meson-log.txt:783 - statx * Check that no features were accidentally disabled. * See https://wiki.gentoo.org/wiki/Modern_C_porting. So, not an actual bug but more of a favor that we can do to the distros. >> + cc.has_function('malloc_trim', prefix: '#include <malloc.h>') and \ >> cc.links('''#include <malloc.h> >> int main(void) { malloc_trim(0); return 0; }''') > > This seems super clunky -- surely this isn't the way Meson > intends people to write tests ? For this one can remove the cc.links test altogether, so this part of the patch is okay. The statx is less clear. > > +statx_test = statx_prefix + ''' > int main(void) { > struct statx statxbuf; > statx(0, "", 0, STATX_BASIC_STATS, &statxbuf); > return 0; > }''' > > -has_statx = cc.links(statx_test) > +has_statx = cc.has_function('statx', prefix: statx_prefix) and \ > + cc.links(statx_test) Here we could replace cc.links with a cc.has_header_symbol('sys/stat.h', 'STATX_BASIC_STATS'), and likewise for has_statx_mnt_id below. If it was just has_statx I would rather leave things as is. However, given that there is has_statx_mnt_id too, I'd apply a v2 that removes usage of cc.links for these three tests. Paolo
29.05.2023 10:56, Michal Privoznik пишет: > While detecting a presence of a function via 'cc.links()' > gives desired result (i.e. detects whether function is present), > it also produces a warning on systems where the function is not > present, e.g.: > > qemu.git/build/meson-private/tmph74x3p38/testfile.c:2:34: \ > warning: implicit declaration of function 'malloc_trim' [-Wimplicit-function-declaration] > > We can check whether given function exists via > 'cc.has_function()' firstly. This just slows down the configure step, it looks like. Shouldn't we use cc.has_function() *instead* of our cc.links(), but not both? /mjt
diff --git a/meson.build b/meson.build index 2d48aa1e2e..5da4dbac24 100644 --- a/meson.build +++ b/meson.build @@ -1797,6 +1797,7 @@ malloc = [] if get_option('malloc') == 'system' has_malloc_trim = \ get_option('malloc_trim').allowed() and \ + cc.has_function('malloc_trim', prefix: '#include <malloc.h>') and \ cc.links('''#include <malloc.h> int main(void) { malloc_trim(0); return 0; }''') else @@ -1818,27 +1819,29 @@ gnu_source_prefix = ''' #define _GNU_SOURCE #endif ''' -statx_test = gnu_source_prefix + ''' - #include <sys/stat.h> +statx_prefix = gnu_source_prefix + ''' + #include<sys/stat.h> +''' +statx_test = statx_prefix + ''' int main(void) { struct statx statxbuf; statx(0, "", 0, STATX_BASIC_STATS, &statxbuf); return 0; }''' -has_statx = cc.links(statx_test) +has_statx = cc.has_function('statx', prefix: statx_prefix) and \ + cc.links(statx_test) # Check whether statx() provides mount ID information -statx_mnt_id_test = gnu_source_prefix + ''' - #include <sys/stat.h> +statx_mnt_id_test = statx_prefix + ''' int main(void) { struct statx statxbuf; statx(0, "", 0, STATX_BASIC_STATS | STATX_MNT_ID, &statxbuf); return statxbuf.stx_mnt_id; }''' -has_statx_mnt_id = cc.links(statx_mnt_id_test) +has_statx_mnt_id = has_statx and cc.links(statx_mnt_id_test) have_vhost_user_blk_server = get_option('vhost_user_blk_server') \ .require(targetos == 'linux',
While detecting a presence of a function via 'cc.links()' gives desired result (i.e. detects whether function is present), it also produces a warning on systems where the function is not present, e.g.: qemu.git/build/meson-private/tmph74x3p38/testfile.c:2:34: \ warning: implicit declaration of function 'malloc_trim' [-Wimplicit-function-declaration] We can check whether given function exists via 'cc.has_function()' firstly. Resolves: https://bugs.gentoo.org/898810 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- meson.build | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)