meson: add stack protection option

This commit is contained in:
Steve Lhomme 2023-01-27 14:20:17 +01:00
parent 1bf09fe8d6
commit 6b1f7dc265
2 changed files with 33 additions and 1 deletions

View File

@ -791,6 +791,33 @@ add_project_arguments(
cc.get_supported_arguments('-fvisibility=hidden'),
language: ['c'])
# Stack smashing protection (default enabled for optimized builds)
if (get_option('ssp')
.disable_auto_if(get_option('optimization') == '0')
.allowed())
add_project_arguments(
cc.get_supported_arguments('-fstack-protector-strong'),
language: ['c', 'cpp'])
if host_system == 'windows'
# Win32 requires linking to ssp for stack-protection
ssp_test = '''
#include <stdio.h>
int main(void) {
char buf[100];
fgets(buf, sizeof(buf), stdin);
return 0;
}
'''
# Check if linker supports -lssp
if cc.links(ssp_test, args: ['-fstack-protector-strong', '-lssp'],
name: 'linker supports stack protectors')
add_project_link_arguments('-lssp', language: ['c', 'cpp'])
endif
endif
endif
# Check if linker supports -Bsymbolic
symbolic_linkargs = []
if cc.has_link_argument('-Wl,-Bsymbolic')
@ -987,4 +1014,4 @@ subdir('modules')
warning('''
The Meson build system of VLC is currently EXPERIMENTAL and INCOMPLETE.
Testing and reporting or contributing missing plugins and features is welcome!
''')
''')

View File

@ -45,6 +45,11 @@ option('branch_protection',
value : 'auto',
description : 'AArch64 branch protection')
option('ssp',
type : 'feature',
value : 'auto',
description : 'Stack smashing protection')
option('winstore_app',
type : 'boolean',
value : 'false',