]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: fix detection of libcryptsetup functions
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 30 Dec 2021 13:51:44 +0000 (14:51 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 30 Dec 2021 22:02:29 +0000 (07:02 +0900)
Meson would generate the following compile test:

  #define crypt_set_metadata_size meson_disable_define_of_crypt_set_metadata_size

  #include <limits.h>
  #undef crypt_set_metadata_size

  #ifdef __cplusplus
  extern "C"
  #endif
  char crypt_set_metadata_size (void);

  #if defined __stub_crypt_set_metadata_size || defined __stub___crypt_set_metadata_size
  fail fail fail this function is not going to work
  #endif

  int main(void) {
    return crypt_set_metadata_size ();
  }

This works fine when the identifier being queried is an actual function. But
crypt_token_max() is an inline function, so getting the address would fail,
leading to a false negative result. Complation would fail because the function
would be defined twice.

With this patch, the check is changed to include the header:

  #include <libcryptsetup.h>
  #include <limits.h>

  #if defined __stub_crypt_set_metadata_size || defined __stub___crypt_set_metadata_size
  fail fail fail this function is not going to work
  #endif

  int main(void) {
    void *a = (void*) &crypt_set_metadata_size;
    long long b = (long long) a;
    return (int) b;
  }

which seems to work correctly.

meson.build

index 0d2faf720c760282778b019f67528394580e8fca..043be41115b54f13087bbeb850fb91f4d5bfa1e5 100644 (file)
@@ -1176,12 +1176,15 @@ if want_libcryptsetup != 'false' and not skip_deps
                                    required : want_libcryptsetup == 'true' or want_libcryptsetup_plugins == 'true')
         have = libcryptsetup.found()
 
-        conf.set10('HAVE_CRYPT_SET_METADATA_SIZE',
-                   have and cc.has_function('crypt_set_metadata_size', dependencies : libcryptsetup))
-        conf.set10('HAVE_CRYPT_ACTIVATE_BY_SIGNED_KEY',
-                   have and cc.has_function('crypt_activate_by_signed_key', dependencies : libcryptsetup))
-        conf.set10('HAVE_CRYPT_TOKEN_MAX',
-                   have and cc.has_function('crypt_token_max', dependencies : libcryptsetup))
+        foreach ident : ['crypt_set_metadata_size',
+                         'crypt_activate_by_signed_key',
+                         'crypt_token_max']
+                have_ident = have and cc.has_function(
+                        ident,
+                        prefix : '#include <libcryptsetup.h>',
+                        dependencies : libcryptsetup)
+                conf.set10('HAVE_' + ident.to_upper(), have_ident)
+        endforeach
 else
         have = false
         libcryptsetup = []
@@ -1189,8 +1192,14 @@ endif
 conf.set10('HAVE_LIBCRYPTSETUP', have)
 
 if want_libcryptsetup_plugins != 'false' and not skip_deps
-        have = (cc.has_function('crypt_activate_by_token_pin', dependencies : libcryptsetup) and
-                cc.has_function('crypt_token_external_path', dependencies : libcryptsetup))
+        have = (cc.has_function(
+                        'crypt_activate_by_token_pin',
+                        prefix : '#include <libcryptsetup.h>',
+                        dependencies : libcryptsetup) and
+                cc.has_function(
+                        'crypt_token_external_path',
+                        prefix : '#include <libcryptsetup.h>',
+                        dependencies : libcryptsetup))
 else
         have = false
 endif