-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Support for CROSSTOOL with custom dynamic runtime libs w/o using EXEC_ORIGIN #3592
Comments
Hi Jean, sorry for the silence. Is the only problem that bazel emits $EXEC_ORIGIN instead of $ORIGIN with your crosstool? |
It's not clear at all to us how we can craft a CROSSTOOL that will allow, say, Our CROSSTOOL's BUILD file looks something like this:
The CROSSTOOL is generated from a template downloaded from Cloud Storage using a repository_rule in our WORKSPACE to have absolute paths, and looks like this:
|
I'm not sure I understand the problem, are you saying that you want to specify cc_toolchain without having to provide toolchain inputs via One detail, I see you have One more question, why do you need absolute paths in your crosstool if you provide the hermetic toolchain (i.e. you're not using the toolchain that is installed on the host system). In this case it's usual to use relative paths. I'm just curious. Thanks! |
The problem is, with that CROSSTOOL, if I do bazel test --crosstool_top=@mycrosstool//:toolchain //... All the tests will fail because libc++ and libc++abi will not be in the sandbox. If I set The absolute paths solve some strange problems we've had with cxx_builtin_include_directory and cgo. We don't hardcode them, we use a repository_rule to generate the final CROSSTOOL from a template. |
Heh maybe you encountered the same problem we're discussing with @jayconrod at this very moment over here: bazelbuild/rules_go#1357 If you put libc++ library into |
@mhlopko I replicated a similar setup as @jfroy described - basically with the goal of having a hermetic clang and libc++ pulled in with bazel via http_archive. I eventually got it working but it took adding this to my crosstool to make EXEC_ORIGIN just ORIGIN because ubuntu 14.04 and 16.04 don't support EXEC_ORIGIN...
ORIGIN works, I don't know why EXEC_ORIGIN was used there, but it's very un-supported, can it be changed to ORIGIN on master? |
@dapirian Thanks, I will try that. Do you mind sharing your whole CROSSTOOL? |
@jfroy Here's my repo: https://github.com/dapirian/m |
So removing EXEC_ORIGIN is pending a small internal migration, but not too hard. Then I can replace it with ORIGIN in CppActionConfigs. Until then the workaround is to define your own |
Changing $EXEC_ORIGIN with $ORIGIN doesn't seems to fix the issue on my setup (Ubuntu 18 & Bazel 2.0.0). The shared libraries needed at runtime are located under the *.runfiles/ directory which is also where tests are executed. The test binary under this directory tree is a symlink. So I believe it is supposed to work with $EXEC_ORIGIN on a machine where the dynamic linker supports it (note the difference between $ORIGIN and $EXEC_ORIGIN is that the first one resolves from the actual targeted binary, while the latter one from the executed target, so a symlink in that case).
Seems to be a similar concern in #6700 |
As a workaround, you can actual use the following. Seems to works as Bazel run/test binaries from the root of the *.runfiles/ tree:
|
Hi! The solution proposed by @blaizard seems exactly what I'm looking for. Just one caveat:
How do I populate |
@dapirian I'm interested in solving exactly the same problem but the repo is no longer available. Do you mind sharing it? Thanks! |
@carlosgalvezp I wanted also to understand this topic and did a small reproducer:
This "dynamic_runtime_lib" thing seems to me a bit like a workaround. I cannot find the code responsible for controlling the 'runtime_library_search_directories' variable. Btw, @hlopko does any actual example of a fully hermetic toolchain exist? I have a shameful workaround, but this definitely does not work with remote execution: |
@ltekieli thanks, that's exactly what I was looking for! I did try the On a side note, I'm no longer sure this is the right way to go. If we depend on a third-party .so file that itself depends on Therefore I believe the safest solution is to create a custom cc_binary rule that generates a wrapper around the actual binary. The wrapper should then set the correct About the dynamic linker, it is indeed a problem. I found that the dynamic linker and glibc need to match, otherwise the binary crashes with segfault. So perhaps a middle-point solution is to use system-wide dynamic linker glibc, and use hermetic libstdc++, libgcc and so on? |
For future reference, I had to add this feature to the cc_toolchain config: feature(
name='runtime_library_search_directories',
flag_sets=[
flag_set(
actions=[
'c++-link-executable',
'c++-link-dynamic-library',
'c++-link-nodeps-dynamic-library',
],
flag_groups=[
flag_group(
expand_if_available='runtime_library_search_directories',
iterate_over='runtime_library_search_directories',
flags=['-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}'],
)
]
)
]
), (it's #3592 (comment) but starlark syntax) |
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 |
This fixes running cc_test libcap_test. Link: bazelbuild/bazel#3592 Bug: 325514706 Change-Id: Ibc034ceede5c381dc5d9f5ac7b4f603ea0f695f9
This fixes running cc_test libcap_test. Link: bazelbuild/bazel#3592 Bug: 325514706 Change-Id: Ibc034ceede5c381dc5d9f5ac7b4f603ea0f695f9
Our project targets a slightly strange flavor of Linux where the runtime environment does not use libstdc++. We built a custom CROSSTOOL with clang/llvm and a minimal sysroot, and we can compile programs, but we cannot run tests because the sysroot runtime libraries are not made available to test programs. Using
dynamic_runtime_libs
incc_toolchain
andsupports_embedded_runtimes: true
inCROSSTOOL
does not work because the standard Linux dynamic linker doesn't support EXEC_ORIGIN (at least on the Debian and Ubuntu workstations we use). We don't want to use a pile of hacks to solve this, so we'd like to see a solution in bazel for this use case.Environment info
Operating System:
Ubuntu 14.04 LTS
Debian unstable
Bazel version (output of
bazel info release
):release 0.5.3
The text was updated successfully, but these errors were encountered: