Skip to content

fix linker args for lld-link + clang-cl + flang#15660

Open
lucascolley wants to merge 1 commit intomesonbuild:masterfrom
lucascolley:flang-linker-args
Open

fix linker args for lld-link + clang-cl + flang#15660
lucascolley wants to merge 1 commit intomesonbuild:masterfrom
lucascolley:flang-linker-args

Conversation

@lucascolley
Copy link
Copy Markdown

@lucascolley lucascolley commented Mar 29, 2026

Closes scipy/scipy#24925 (in combination with conda-forge/flang-activation-feedstock#51).

I have been unable to find a way to craft LDFLAGS such that both clang-cl and flang ingest them without warnings when using lld-link. This PR aims to fix that by stripping -Wl, when the ninja backend grabs LINK_ARGS.

@lucascolley

This comment was marked as outdated.

@lucascolley

This comment was marked as outdated.

@lucascolley

This comment was marked as outdated.

@lucascolley

This comment was marked as outdated.

@lucascolley

This comment was marked as outdated.

@lucascolley lucascolley force-pushed the flang-linker-args branch 3 times, most recently from c056aad to b548178 Compare March 29, 2026 21:09
@lucascolley lucascolley changed the title WIP: fix linker args for flang + clang-cl fix linker args for flang + clang-cl + lld-link Mar 29, 2026
@lucascolley lucascolley changed the title fix linker args for flang + clang-cl + lld-link fix linker args for lld-link + clang-cl + flang Mar 29, 2026
@lucascolley lucascolley marked this pull request as ready for review March 29, 2026 21:14
@lucascolley lucascolley requested a review from dcbaker as a code owner March 29, 2026 21:14
@lucascolley
Copy link
Copy Markdown
Author

This fix is for the following rule:

rule c_LINKER
 command = "lld-link" $ARGS /MACHINE:x64 /OUT:$out $in $LINK_ARGS
 description = Linking target $out

On this PR:

build scipy/_cyutility.cp314-win_amd64.pyd | scipy/_cyutility.cp314-win_amd64.pdb: c_LINKER scipy/_cyutility.cp314-win_amd64.pyd.p/meson-generated_..__cyutility.c.obj | C$:/Users/lucas/ghq/github.com/scipy/scipy/.pixi/envs/build/libs/python314.lib
 LINK_ARGS = "/nologo" "/DEBUG" "/PDB:scipy\_cyutility.cp314-win_amd64.pdb" "/DLL" "/IMPLIB:scipy\_cyutility.cp314-win_amd64.lib" "/DEFAULTLIB:C:/Users/lucas/ghq/github.com/scipy/scipy/.pixi/envs/build/lib/clang/21/lib/windows/clang_rt.builtins-x86_64.lib" "C:\Users\lucas\ghq\github.com\scipy\scipy\.pixi\envs\build\libs\python314.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib"

On the latest release:

[76/1160] Linking target scipy/_cyutility.cp314-win_amd64.pyd
lld-link: warning: ignoring unknown argument '-Wl,/DEFAULTLIB:C:/Users/lucas/ghq/github.com/scipy/scipy/.pixi/envs/build/lib/clang/21/lib/windows/clang_rt.builtins-x86_64.lib'
build scipy/_cyutility.cp314-win_amd64.pyd | scipy/_cyutility.cp314-win_amd64.pdb: c_LINKER scipy/_cyutility.cp314-win_amd64.pyd.p/meson-generated_..__cyutility.c.obj | C$:/Users/lucas/ghq/github.com/scipy/scipy/.pixi/envs/build/libs/python314.lib
 LINK_ARGS = "/nologo" "/DEBUG" "/PDB:scipy\_cyutility.cp314-win_amd64.pdb" "/DLL" "/IMPLIB:scipy\_cyutility.cp314-win_amd64.lib" "-Wl,/DEFAULTLIB:C:/Users/lucas/ghq/github.com/scipy/scipy/.pixi/envs/build/lib/clang/21/lib/windows/clang_rt.builtins-x86_64.lib" "C:\Users\lucas\ghq\github.com\scipy\scipy\.pixi\envs\build\libs\python314.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib"

return args

def get_build_link_args(self, target: BuildTarget, build: Build) -> T.List[str]:
return self._sanitize_linker_args(super().get_build_link_args(target, build))
Copy link
Copy Markdown
Author

@lucascolley lucascolley Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is called at

commands += linker.get_build_link_args(target, self.build)
where the linker is (bare) lld-link when using it with clang-cl. Hence, we want the same stripping of -Wl, as occurs at
largs += [l for l in self.linker_to_compiler_args(la) if l != '/link']
in build_wrapper_args.

@lucascolley
Copy link
Copy Markdown
Author

cc @bonzini I see you have worked on this file recently :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BLD: warnings from lld-link on Windows

1 participant