aboutsummaryrefslogtreecommitdiff
path: root/meson.build
diff options
context:
space:
mode:
authorAndrew Deason <adeason@sinenomine.net>2022-03-15 22:52:25 -0500
committerPeter Maydell <peter.maydell@linaro.org>2022-03-18 11:31:41 +0000
commit8900c204df0e521361e2bd31131d5f9089d08000 (patch)
tree146aa5d3a334d6c6f910df4309d83a948d6a177f /meson.build
parenteb7a38ba664c8ab7f216fa701a0bea897d433763 (diff)
util/osdep: Avoid madvise proto on modern Solaris
On older Solaris releases (before Solaris 11), we didn't get a prototype for madvise, and so util/osdep.c provides its own prototype. Some time between the public Solaris 11.4 release and Solaris 11.4.42 CBE, we started getting an madvise prototype that looks like this: extern int madvise(void *, size_t, int); which conflicts with the prototype in util/osdeps.c. Instead of always declaring this prototype, check if we're missing the madvise() prototype, and only declare it ourselves if the prototype is missing. Move the prototype to include/qemu/osdep.h, the normal place to handle platform-specific header quirks. The 'missing_madvise_proto' meson check contains an obviously wrong prototype for madvise. So if that code compiles and links, we must be missing the actual prototype for madvise. Signed-off-by: Andrew Deason <adeason@sinenomine.net> Message-id: 20220316035227.3702-2-adeason@sinenomine.net Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'meson.build')
-rw-r--r--meson.build23
1 files changed, 21 insertions, 2 deletions
diff --git a/meson.build b/meson.build
index bae62efc9c..282e7c4650 100644
--- a/meson.build
+++ b/meson.build
@@ -1715,11 +1715,30 @@ config_host_data.set('CONFIG_FDATASYNC', cc.links(gnu_source_prefix + '''
#error Not supported
#endif
}'''))
-config_host_data.set('CONFIG_MADVISE', cc.links(gnu_source_prefix + '''
+
+has_madvise = cc.links(gnu_source_prefix + '''
#include <sys/types.h>
#include <sys/mman.h>
#include <stddef.h>
- int main(void) { return madvise(NULL, 0, MADV_DONTNEED); }'''))
+ int main(void) { return madvise(NULL, 0, MADV_DONTNEED); }''')
+missing_madvise_proto = false
+if has_madvise
+ # Some platforms (illumos and Solaris before Solaris 11) provide madvise()
+ # but forget to prototype it. In this case, has_madvise will be true (the
+ # test program links despite a compile warning). To detect the
+ # missing-prototype case, we try again with a definitely-bogus prototype.
+ # This will only compile if the system headers don't provide the prototype;
+ # otherwise the conflicting prototypes will cause a compiler error.
+ missing_madvise_proto = cc.links(gnu_source_prefix + '''
+ #include <sys/types.h>
+ #include <sys/mman.h>
+ #include <stddef.h>
+ extern int madvise(int);
+ int main(void) { return madvise(0); }''')
+endif
+config_host_data.set('CONFIG_MADVISE', has_madvise)
+config_host_data.set('HAVE_MADVISE_WITHOUT_PROTOTYPE', missing_madvise_proto)
+
config_host_data.set('CONFIG_MEMFD', cc.links(gnu_source_prefix + '''
#include <sys/mman.h>
int main(void) { return memfd_create("foo", MFD_ALLOW_SEALING); }'''))