-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Incorrect linker command line on MacOS with LLD when using a shared object named ".so" #18464
Comments
As far as macOS lld not supporting bazel/src/main/java/com/google/devtools/build/lib/rules/cpp/LibrariesToLinkCollector.java Lines 604 to 614 in 98d5d5f
else statement here, it would end up getting added directly to the link command line, which should work with both linkers.
|
I think so, too, yes -- I don't know what the benefit of the |
I think you're probably right, worth a try |
@trybka: Any thoughts on why we use |
So you could ask, "why not pass the filename directly?" When building for ELF, the whole filename is there, which makes runtime path searching usually not work. So this code in Bazel should probably ask the toolchain (via a feature), "do you need legacy ELF |
Ah yes, the |
I mean, sure, but Bazel has no way to know if you did this or not. In this stage, it is dealing with libraries that it may not have built (you can just have a checked in .so that you reference with |
Yes, makes sense, thanks! |
While not the recommended extension on macOS .so is supported by ld64. This mirrors that behavior. Related report: bazelbuild/bazel#18464 Differential Revision: https://reviews.llvm.org/D151147
Can this be closed? |
@oquenchil The issue hasn't been fixed yet, has it? |
I wasn't sure if the comments from Keith and Tom were enough here. I will leave it open then. |
There were several issues under discussion, but the main problem has not been addressed as far as I'm aware. @MaskRay may have a change to LLD in the pipeline that would make this issue moot, though, without changing Bazel, as long as people are able to upgrade to a sufficiently modern linker. |
Yea the issue around |
|
While not the recommended extension on macOS .so is supported by ld64. This mirrors that behavior. Related report: bazelbuild/bazel#18464 Differential Revision: https://reviews.llvm.org/D151147
Description of the bug:
On MacOS, the default linker is LD64, which is tolerant to whether a dynamic library uses the native
.dylib
or the anatopic.so
file extension from the ELF world: the flag-lfoo
considers bothlibfoo.dylib
andlibfoo.so
to match.Bazel leans on this behaviour when a
cc_binary
has a precompiled source,srcs = [":libfoo.so"]
, and emits the linker flag-lfoo
, both on Linux and on MacOS (together with an-L
flag specifying the mangled solib directory into which the precompiled library is symlinked). However, on MacOS this is not always correct:With LLVM's LLD linker, this setup is broken, as that linker strictly requires the
.dylib
file extension. With LLD, linking simply fails.The reason this matters is that sometimes the shared library is part of our build rules, and so we have to pick a name for it; that way we can end up with something named
.so
on MacOS. That setup works with LD64, but not with LLD.There is also a related issue where both LD64's and LLD's behaviour deviates from what Bazel expects, namely when the filename is not of the form
lib<name>.so
orlib<name>.dylib
, e.g.x.dylib
: in that case Bazel emits the flag-l:x.dylib
, but the:
syntax is not recognized by by either linker.What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
With some trivial source files
foo.cc
,bar.cc
, anddemo.cc
:Linking with
libfoo.so
will fail with LLD:ld64.lld: error: library not found for -lfoo
Linking with
bar.dylib
will fail with both linkers:ld: library not found for -l:bar.dylib
ld64.lld: error: library not found for -l:bar.dylib
Which operating system are you running Bazel on?
MacOS 12 and 13
What is the output of
bazel info release
?release 6.2.0 (via bazelisk)
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse master; git rev-parse HEAD
?No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
This appears to be a straight-forward behavioural difference between LD64 and LLD. It seems like Bazel should be made aware of the effective linker.
The use of the
-l:...
syntax should probably be avoided entirely on MacOS.The text was updated successfully, but these errors were encountered: