Skip to content

Cleanup and fix sanitycheck linker args - #16166

Merged
bonzini merged 8 commits into
mesonbuild:masterfrom
bonzini:cleanup-and-fix-sanitycheck-largs
Aug 29, 2026
Merged

Cleanup and fix sanitycheck linker args#16166
bonzini merged 8 commits into
mesonbuild:masterfrom
bonzini:cleanup-and-fix-sanitycheck-largs

Conversation

@bonzini

@bonzini bonzini commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Sanity check arguments were duplicated between Compiler._sanity_check_compile_args() and CLikeCompiler._get_basic_compiler_args(), and when the latter called the former via super() they ended up before the /link flag that MSVC wants.

Furthermore, the arguments from get_linker_always_args() were retrieved via get_compiler_args_for_mode() but that placed them before /link.

Fix the mess by building upon the infrastructure introduced by commit c9bb03c.

Cc: @tristan957
Fixes: #16086
Fixes: #16111
Fixes: #16115

@bonzini bonzini added this to the 1.12.1 milestone Aug 28, 2026
@bonzini
bonzini force-pushed the cleanup-and-fix-sanitycheck-largs branch 3 times, most recently from da168db to 2b2681e Compare August 28, 2026 20:12
@thesamesam

Copy link
Copy Markdown
Member

Sorry, I merged e6bb7f2 as it looks/looked like an easy correct improvement, but it leads to a conflict here.

@bonzini

bonzini commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Ok, I will push a pr16166-for-1.12 branch with the current version and rebase. Later today.

Commit 300d7c3 ("compilers: add link always args if
CompileCheckMode.LINK") made has_function() and friends pass the linker's
always args, so that e.g. -Zomf is not missing on OS/2 when a dependency
is used.  Before changing where those arguments are added, add a test.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Commit c9bb03c ("Stop passing link arguments to compile-only
sanity checks", 2026-08-28) dropped link arguments from compile-only
checks for CLikeCompiler.  Introduce Compiler._sanity_check_mode()
to move this logic up to Compiler and so that it applies also to
the super() call of CLikeCompiler._sanity_check_compile_args().

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Commit 797decc ("compilers: pass external args to sanity check")
made Compiler._sanity_check_compile_args() add {c,cpp}_args and
{c,cpp}_link_args, assuming the extra copies on the CLike path were
harmless because "arglist deduplicates them", but the sanity check
builds a plain list so nothing is deduplicated.  Furthermore,
the copy of linker arguments in s_largs would end up in front
of the /link that linker_to_compiler_args() inserts for MSVC-style
compilers.  For example, with c_link_args=['/SUBSYSTEM:CONSOLE']
the probe became

  cl ... /c /SUBSYSTEM:CONSOLE /link /SUBSYSTEM:CONSOLE

(the first from super()._sanity_check_compile_args, the second
from self._get_basic_compiler_args) instead of

  cl ... /c /link /SUBSYSTEM:CONSOLE

Stop using super()._sanity_check_compile_args() to remove the duplication
while keeping control of the position of the linker arguments.

Note that get_always_args() was also duplicated because
_get_basic_compiler_args() returns it via get_compiler_args_for_mode(),
so drop it as well.  The effect is to remove the copy of get_always_args()
that was previously in front of the output argument, and only keep the
one after the source file, but this is harmless.

Fixes: mesonbuild#16111
Fixes: 797decc ("compilers: pass external args to sanity check")
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Right now they are passed twice, but this will be fixed.  Add a
partial test for now.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Commit 300d7c3 ("compilers: add link always args if CompileCheckMode.LINK",
2026-01-07) added get_linker_always_args() to get_compiler_args_for_mode(),
but that function returns *compiler* arguments, and it is applied twice
to a compile check: once by CLikeCompiler._get_basic_compiler_args()
and once by Compiler.compile().

For MSVC this puts linker-only flags on the compiler command line twice
*and* in the wrong place:

  cl ... /release /nologo ... /release /nologo ... /link foo.lib

Add them to the linker argument list that is passed through
linker_to_compiler_args() instead of going through get_compiler_args_for_mode().
While that appears twice (in build_wrapper_args() and in the sanity check),
it is not necessary anymore to add linker always args in find_library()
now that build_wrapper_args() adds them.  Note that this does not include
the Ninja backend which has a call to get_linker_always_args() of its own.

Fixes: mesonbuild#16086
Fixes: 300d7c3 ("compilers: add link always args if CompileCheckMode.LINK", 2026-01-07)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Commit decc3e assumed the sanity check goes through CompilerArgs,
but it does not.  Add to _sanity_check_compile_args() the
missing call to DCompiler.unix_args_to_native().

Fixes: mesonbuild#16115
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Avoid a repeated get_value_for() idiom.

Rust wraps the linker arguments with -Clink-arg as usual; this is
a bug fix for cc.links(), cc.has_function() and friends which
previously received the raw arguments.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
rustc's sanity check passes no external args at all.  Fix it
for consistency with other languages and to ensure that failures
are detected early.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
@bonzini
bonzini force-pushed the cleanup-and-fix-sanitycheck-largs branch from 2b2681e to 774cb92 Compare August 29, 2026 06:41
@bonzini bonzini modified the milestones: 1.12.1, 1.13 Aug 29, 2026
@bonzini
bonzini merged commit f49aaca into mesonbuild:master Aug 29, 2026
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants