diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2022-10-12 12:46:23 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2023-05-18 08:53:52 +0200 |
commit | 911d4caaa267c43a5aa727f5a100e9122158e989 (patch) | |
tree | 084cedaa12a9b5e12798f3a2dced58229ba6ac7e /meson.build | |
parent | 6739825aa6e432fdb668e842def12c5deb3e5bad (diff) |
build: move stack protector flag selection to meson
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'meson.build')
-rw-r--r-- | meson.build | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/meson.build b/meson.build index 130dfab82a..252082c142 100644 --- a/meson.build +++ b/meson.build @@ -200,7 +200,7 @@ foreach arg : config_host['QEMU_CFLAGS'].split() endif endforeach qemu_objcflags = config_host['QEMU_OBJCFLAGS'].split() -qemu_ldflags = config_host['QEMU_LDFLAGS'].split() +qemu_ldflags = [] if get_option('gprof') qemu_common_flags += ['-p'] @@ -211,6 +211,32 @@ if get_option('prefer_static') qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static' endif +if not get_option('stack_protector').disabled() + stack_protector_probe = ''' + int main(int argc, char *argv[]) + { + char arr[64], *p = arr, *c = argv[argc - 1]; + while (*c) { + *p++ = *c++; + } + return 0; + }''' + have_stack_protector = false + foreach arg : ['-fstack-protector-strong', '-fstack-protector-all'] + # We need to check both a compile and a link, since some compiler + # setups fail only on a .c->.o compile and some only at link time + if cc.compiles(stack_protector_probe, args: ['-Werror', arg]) and \ + cc.links(stack_protector_probe, args: ['-Werror', arg]) + have_stack_protector = true + qemu_cflags += arg + qemu_ldflags += arg + break + endif + endforeach + get_option('stack_protector') \ + .require(have_stack_protector, error_message: 'Stack protector not supported') +endif + coroutine_backend = get_option('coroutine_backend') ucontext_probe = ''' #include <ucontext.h> |