]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Meson: Archive
authorFred Morcos <fred.morcos@open-xchange.com>
Tue, 8 Aug 2023 12:13:14 +0000 (14:13 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Wed, 20 Mar 2024 12:28:33 +0000 (13:28 +0100)
meson-archive/code-coverage/meson.build [new file with mode: 0644]
meson-archive/lto/meson.build [new file with mode: 0644]
meson-archive/meson_options.txt [new file with mode: 0644]
meson-archive/pie/meson.build [new file with mode: 0644]

diff --git a/meson-archive/code-coverage/meson.build b/meson-archive/code-coverage/meson.build
new file mode 100644 (file)
index 0000000..bdfbe84
--- /dev/null
@@ -0,0 +1,18 @@
+# Code coverage
+
+code_coverage = get_option('code-coverage')
+
+if code_coverage
+  args = ['-U_FORTIFY_SOURCE', '-g', '-O0', '-fprofile-arcs', '-ftest-coverage']
+
+  foreach arg: args
+    if not cxx.has_argument(arg)
+      error('Compiler does not support ' + arg + ', which is needed for code coverage')
+      break
+    endif
+  endforeach
+
+  add_global_arguments(args, language: ['cpp'])
+endif
+
+summary('Code Coverage', code_coverage, bool_yn: true, section: 'Configuration')
diff --git a/meson-archive/lto/meson.build b/meson-archive/lto/meson.build
new file mode 100644 (file)
index 0000000..eb9a0f1
--- /dev/null
@@ -0,0 +1,35 @@
+# Link-time Optimization
+
+opt_lto = get_option('lto')
+
+if opt_lto == 'thin'
+  compiler_opt = '-flto=thin'
+  if cxx.has_argument(compiler_opt)
+    add_global_arguments(compiler_opt, language: ['c', 'cpp'])
+    add_global_link_arguments(compiler_opt, language: ['c', 'cpp'])
+  else
+    opt_lto = 'auto'
+  endif
+endif
+
+if opt_lto == 'auto'
+  compiler_opt = '-flto=auto'
+  if cxx.has_argument(compiler_opt)
+    add_global_arguments(compiler_opt, language: ['c', 'cpp'])
+    add_global_link_arguments(compiler_opt, language: ['c', 'cpp'])
+  else
+    opt_lto = 'yes'
+  endif
+endif
+
+if opt_lto == 'yes'
+  compiler_opt = '-flto'
+  if cxx.has_argument(compiler_opt)
+    add_global_arguments(compiler_opt, language: ['c', 'cpp'])
+    add_global_link_arguments(compiler_opt, language: ['c', 'cpp'])
+  else
+    error('LTO was requested but is not supported')
+  endif
+endif
+
+summary('LTO', opt_lto, section: 'Configuration')
diff --git a/meson-archive/meson_options.txt b/meson-archive/meson_options.txt
new file mode 100644 (file)
index 0000000..a43cdd3
--- /dev/null
@@ -0,0 +1,10 @@
+# TODO Use meson's -Db_coverage option?
+# option('code-coverage', type: 'boolean', value: false, description: 'Enable code coverage')
+# TODO Use meson's -Db_sanitize option?
+# option('sanitizer-address', type: 'boolean', value: false, description: 'Enable the Address Sanitizer')
+# option('sanitizer-memory', type: 'boolean', value: false, description: 'Enable the Memory Sanitizer')
+# option('sanitizer-thread', type: 'boolean', value: false, description: 'Enable the Thread Sanitizer')
+# option('sanitizer-leak', type: 'boolean', value: false, description: 'Enable the Leak Sanitizer')
+# option('sanitizer-undefined', type: 'boolean', value: false, description: 'Enable the Undefined Behavior Sanitizer')
+# TODO Use meson's -Db_lto* options?
+# option('lto', type: 'combo', choices: ['yes', 'no', 'thin', 'auto'], value: 'no', description: 'Enable link-time optimization')
diff --git a/meson-archive/pie/meson.build b/meson-archive/pie/meson.build
new file mode 100644 (file)
index 0000000..2f83d7f
--- /dev/null
@@ -0,0 +1,38 @@
+# PIE
+# Inputs: hardening_features conf
+
+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')