From: Fred Morcos Date: Tue, 8 Aug 2023 12:13:05 +0000 (+0200) Subject: Meson: Use builtin feature to build PIEs X-Git-Tag: rec-5.1.0-alpha1~80^2~291 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0711a4c3b22fa3c290e917b07d8cc8ad33bd2941;p=thirdparty%2Fpdns.git Meson: Use builtin feature to build PIEs --- diff --git a/meson/hardening/meson.build b/meson/hardening/meson.build index 349df78dd0..eeb31c86a4 100644 --- a/meson/hardening/meson.build +++ b/meson/hardening/meson.build @@ -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 index ceab528da1..0000000000 --- a/meson/hardening/pie/meson.build +++ /dev/null @@ -1,38 +0,0 @@ -# PIE -# Inputs: hardening_features conf deps - -prog = ''' -#include -__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')