-
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
cc_import and cc_library of dylib produces LC_RPATH not LC_LOAD_DYLIB and doesn't load at runtime #10254
Comments
@oquenchil I believe that I may be hitting this issue over at bazel-contrib/rules_go#3151. Do you have any pointers for how to work around this issue or even fix it in Bazel? |
I think this is WAI from Bazel's point of view. The linker always constructs the LC_LOAD_DYLIB command from whatever is in the LC_ID_DYLIB field of the dependent library. So the only thing that Bazel can do is construct a unique directory for the imported dylib, and then add that directory to the binary's rpath. |
I see, thanks. I'm still not sure why I'm seeing different behavior between Linux and macOS then on bazel-contrib/rules_go#3151, but will continue to investigate. @pcjanzen Do you happen to know whether bazel/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java Line 551 in 1a7083e
cc_test that has a dependency on a shared library imported via cc_common.create_library_to_link .
|
No, I don't think so. The sordid tale of $EXEC_ORIGIN is at #10809 (comment). The GoLink step that generates The macos cc_wrapper then fixes up all the execroot-relative paths in the binary: https://cs.opensource.google/bazel/bazel/+/master:tools/cpp/osx_cc_wrapper.sh |
Based on bazelbuild/bazel#10254 (comment) and bazelbuild/bazel#12304 being fixed, this special handling of rpaths on macOS appears to be unnecessary. This cleanup ensures that Bazel sets the correct metadata for the exec location of Go libraries linked in c-shared mode, which in turn allows to not include them in the runfiles of all dependents - cc_* targets depending on them will now generate the correct rpath entries to find the libraries at runtime at the usual position.
* Remove unnecessary rpath special handling on macOS Based on bazelbuild/bazel#10254 (comment) and bazelbuild/bazel#12304 being fixed, this special handling of rpaths on macOS appears to be unnecessary. This cleanup ensures that Bazel sets the correct metadata for the exec location of Go libraries linked in c-shared mode, which in turn allows to not include them in the runfiles of all dependents - cc_* targets depending on them will now generate the correct rpath entries to find the libraries at runtime at the usual position. * Don't include non-executable go_binary in dependent's runfiles If a go_binary is built with a non-executable link mode such as `c-archive`, its dependents currently pick up a runfile dependency on it since its DefaultInfo specifies the resulting archive as an executable. This is unnecessary as the dependent should be able to decide whether to include the file (e.g. dynamic linking) or not (e.g. static linking). With this commit, the executable field of the DefaultInfo is only populated if the go_binary is built with an executable link mode. Follow-up to #3143
I'm facing the same issue when using rules_foreign_cc. It seems that if a |
Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team ( |
This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please post |
@bazelbuild/triage not stale |
not stale but closed? |
Description of the problem / feature request:
Building a simple C++ application on osx that loads a third party (
<something>.h
+<libsomething>.dylib
) DLL, I get dyld errors -> "image not found" at runtime when the DLL is loaded at runtime. I have looked at the binary with "otool -l" and found that cc_library .so files which Bazel builds from source get loaded with specific paths like this:Bazel puts the third party .dylib one level deeper in
<some_directory>
, rather than with the rest of the.so
files that bazel generates by compiling libraries. However, although the library .dylib file shows up in<some_directory>
, bazel is annotating the binary with just an LC_RPATH and not an LC_LOAD_DYLIB command for this prebuilt DLL. This happens whether I use a cc_import or cc_library build rule for it. Specifically, the binary that uses the DLL library shows its last entry is my cc_import-ed DLL's directory:That path is valid: I have looked in bazel-bin and
<some_directory>/<libsomething>.dylib
exists. However, for whatever reason the runtime is not finding the<libsomething>.dylib
file within that directory when it tries to actually load<libsomething>.dylib
.Feature requests: what underlying problem are you trying to solve with this feature?
Is there some difference in the linker/loader procedure for cc_import versus bazel-built DLL files? bazel has no problem generating LC_LOAD_DYLIB cmd for all the other DLLs, but seems to only generate a directory LC_RPATH cmd for the DLL that I am trying to link against / import from a third party.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
I posted an example here: https://forums.opalkelly.com/t/dll-import-location-for-libokfrontpanel-dylib/1661/7
It is unclear if the problem is with bazel (especially given issue 1435 linked below), but since this is a third party DLL I don't know if it could be compounded by whatever method/flags the third party used to compile
<libsomething>.dylib
.What operating system are you running Bazel on?
OSX
What's the output of
bazel info release
?release 1.1.0
Have you found anything relevant by searching the web?
https://blog.krzyzanowskim.com/2018/12/05/rpath-what/
https://medium.com/@donblas/fun-with-rpath-otool-and-install-name-tool-e3e41ae86172
This bazel bug seems to be similar or related:
bazel-contrib/rules_go#1435
Any other information, logs, or outputs that you want to share?
The DLL is a C++ library from Opal Kelly, and it works correctly when I just put it in /usr/local/lib. I just want cc_import and/or cc_library to correctly build a working application.
The text was updated successfully, but these errors were encountered: