]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Meson: Use builtin feature to build PIEs
authorFred Morcos <fred.morcos@open-xchange.com>
Tue, 8 Aug 2023 12:13:05 +0000 (14:13 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Wed, 20 Mar 2024 12:28:33 +0000 (13:28 +0100)
meson/hardening/meson.build
meson/hardening/pie/meson.build [deleted file]

index 349df78dd03ed0a2c77719668e5b19d85d11d5ea..eeb31c86a4031355a09c2b1144c85a41b0fe2662 100644 (file)
@@ -4,8 +4,15 @@ opt_hardening = get_option('hardening')
 if opt_hardening.enabled() or opt_hardening.auto()
   hardening_features = []
 
-  # TODO Use meson's -Db_pie and -Db_staticpic options?
-  # subdir('pie')                 # PIE
+  # PIE
+  opt_pie = get_option('b_pie')
+  if not opt_pie
+    error('Hardening was requested but building position independent executables is disabled')
+  endif
+  hardening_features += [[opt_pie, 'Building position independent executables (PIEs)']]
+  conf.set10('PIE', opt_pie, description: 'Whether we enable building a Position Independent Executable (PIE)')
+  summary('PIE', opt_pie, bool_yn: true, section: 'Hardening')
+
   subdir('stack-prot')          # Stack Protector
   subdir('stack-smashing-prot') # Stack-Smashing Protection
   subdir('fortify-source')      # Fortify Source
diff --git a/meson/hardening/pie/meson.build b/meson/hardening/pie/meson.build
deleted file mode 100644 (file)
index ceab528..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-# PIE
-# Inputs: hardening_features conf deps
-
-prog = '''
-#include <pthread.h>
-__thread unsigned int t_id;
-
-int main() {
-  t_id = 1;
-  return 0;
-}
-'''
-
-found_variant = false
-if system == 'windows' and system == 'cygwin'
-  # All code is position independent on Win32 targets.
-  found_variant = true
-else
-  pie_variants = [
-    [['-fPIE', '-DPIE'], ['-pie']],
-    [['-fPIE', '-DPIE'], ['-Wl,-pie']],
-  ]
-  foreach variant: pie_variants
-    cflags = variant[0]
-    ldflags = variant[1]
-
-    if cxx.links(prog, args: cflags + ldflags, name: 'compiler can build Position Independent Executables')
-      add_global_arguments(cflags, language: ['cpp'])
-      add_global_link_arguments(ldflags, language: ['cpp'])
-      found_variant = true
-      break
-    endif
-  endforeach
-endif
-
-hardening_features += [[found_variant, 'Building position independent executables (PIEs)']]
-conf.set10('PIE', found_variant, description: 'Whether we enable building a Position Independent Executable (PIE)')
-summary('PIE', found_variant, bool_yn: true, section: 'Hardening')