-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix Rust static linking with +verbatim= on macos #15024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The current behaviour is very much intentional, I don't remember the exact reason but IIRC rustc does not name their static lib correctly on Windows so linker won't find them, or something... Relevant links:
I'm not saying current code is perfect, but I would be extremely cautious in changing it. I would start by challenging the claim "linkers may not support passing unmodified filenames". I find that hard to believe, please back that with evidence. |
Trying to remember what was the story... I think this comment is the relevant part:
I think we want to bypass rustc as much as possible by passing our args directly to the linker with |
Yes, it's a rustc issue. More precisely: linkers may not support searching for an unmodified filename on the search path, which is currently the only way for rustc to record a dependency of a rlib or staticlib. In the case of ld64, it supports The breakage is self-evident from the code in rustc:
where |
From private conversation with @elmarco, I think the context is this build error: https://gitlab.com/marcandre.lureau/qemu/-/jobs/11301499123. I'm not sure what's the issue because as you can see Meson is not using |
This is an executable target, and therefore can use I suspect the |
mesonbuild/backend/ninjabackend.py
Outdated
if isinstance(target, build.StaticLibrary) or (isinstance(target, build.Executable) and rustc.get_crt_static()): | ||
static = isinstance(d, build.StaticLibrary) | ||
libname = os.path.basename(lib) if verbatim else d.name | ||
libname = os.path.basename(lib) if (verbatim and link_whole) else d.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not maintainable, as it relies on synchronizing the conditions between _link_library
and here. Let me put together a quick refactoring, and then we can look at fixing on top of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need to fix it in Meson at all, feels like completely a rustc issue. But I could be missing something of course.
That makes sense, yes. But then it seems to be a different issue than rust-lang/rust#138753, |
I agree it's a rustc issue in that |
@elmarco I would be curious to see build error of the unit test you wrote but without the fix. Then compare with rustc patched with rust-lang/rust#138753. |
Do not link with link_whole/bundle, to show linking issue with Apple ld. Signed-off-by: Marc-André Lureau <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
@elmarco Can you test branch verbatim-avoidance of my fork on macOS, and/or rebase your fix on top of it? |
When Meson cannot use -Clink-arg=, it has to split the path into a -L option (to add to the search directory) and a -l option (to actually link). Furthermore, if rustc does not support verbatim, Meson needs to undo the addition of "lib" and the extension. Do both tasks in the same place and with the same logic, instead of treating internal and external libraries differently. Signed-off-by: Paolo Bonzini <[email protected]>
When verbatim is not available, libraries that have custom name_prefix or name_suffix will not be found. Fail the build completely instead of ending up with a bad option. Signed-off-by: Paolo Bonzini <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
it seems to work |
@elmarco if you want, can you just push it here so we don't open a new PR for the same issue. Otherwise close this one and I will get the message! |
86e1d2d
to
73363f8
Compare
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
Currently fails with a linking issue: = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: ld: warning: ignoring duplicate libraries: '-lSystem', '-lc', '-llibgio-2.0.dylib', '-llibglib-2.0.dylib', '-llibgmodule-2.0.dylib', '-llibgnutls.dylib', '-llibgobject-2.0.dylib', '-llibintl.dylib', '-llibqemuutil.a', '-lm', 'libqemuutil.a' ld: library 'libqemuutil.a' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) error: aborting due to 1 previous error Fixed in upcoming meson: mesonbuild/meson#15024 Signed-off-by: Marc-André Lureau <[email protected]> Message-Id: <[email protected]>
rustc -lstatic+verbatim=filename is not portable, given that linkers may not support passing unmodified filenames.
If we use -bundle, then also use -verbatim (default) and let the system linker find the library by adding prefix/suffix itself.
@bonzini @xclaesse