From 28e5823a68b4474b064b5cc092febd82a558f499 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: (cherry picked from commit fd9b50aa1c07512c46ec981f19ea68fa4b8d7b4f) --- .pick_status.json | 2 +- meson.build | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 0a61fba..c25c2e5 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2218,7 +2218,7 @@ "description": "meson: combine checks for linker --gc-sections support", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "f51ce21e4e0bf7efabe58afb4a2cd6b9f98d9505" }, diff --git a/meson.build b/meson.build index 172c64a..392f85b 100644 --- a/meson.build +++ b/meson.build @@ -1119,6 +1119,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 @@ -1195,7 +1196,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 @@ -1528,11 +1531,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