From fd9b50aa1c07512c46ec981f19ea68fa4b8d7b4f Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 2 Feb 2023 13:05:33 -0800 Subject: [PATCH] meson: combine checks for linker --gc-sections support We first do an incomplete check for whether the linker supports --gc-sections, then potentially add C and C++ arguments assuming that it works, then later do a complete check to see if it actually works and use --gc-sections. This means we can end up putting functions and data in separate sections when we can't gc them. Combine the checks, do less work, and be more accurate. fixes: f51ce21e4e0bf7efabe58afb4a2cd6b9f98d9505 ("meson: Drop adding -Wl,--gc-sections to project c/cpp arguments.") Reviewed-by: Eric Engestrom Part-of: --- meson.build | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index acabbcd..3f60316 100644 --- a/meson.build +++ b/meson.build @@ -965,6 +965,7 @@ endif c_msvc_compat_args = [] no_override_init_args = [] cpp_msvc_compat_args = [] +ld_args_gc_sections = [] if cc.get_argument_syntax() == 'msvc' _trial = [ '/wd4018', # signed/unsigned mismatch @@ -1044,7 +1045,9 @@ else # own sections and GC the sections after linking. This lets drivers # drop shared code unused by that specific driver (particularly # relevant for Vulkan drivers). - if cc.has_link_argument('-Wl,--gc-sections') + if cc.links('static char unused() { return 5; } int main() { return 0; }', + args : '-Wl,--gc-sections', name : 'gc-sections') + ld_args_gc_sections += '-Wl,--gc-sections' _trial_c += ['-ffunction-sections', '-fdata-sections'] _trial_cpp += ['-ffunction-sections', '-fdata-sections'] endif @@ -1380,11 +1383,6 @@ ld_args_bsymbolic = [] if cc.links('int main() { return 0; }', args : '-Wl,-Bsymbolic', name : 'Bsymbolic') ld_args_bsymbolic += '-Wl,-Bsymbolic' endif -ld_args_gc_sections = [] -if cc.links('static char unused() { return 5; } int main() { return 0; }', - args : '-Wl,--gc-sections', name : 'gc-sections') - ld_args_gc_sections += '-Wl,--gc-sections' -endif with_ld_version_script = false if cc.links('int main() { return 0; }', args : '-Wl,--version-script=@0@'.format( -- 2.7.4