Skip to content
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

Linker scripts in cc_library deps missing from sandbox #807

Closed
claridge opened this issue Jan 21, 2016 · 9 comments
Closed

Linker scripts in cc_library deps missing from sandbox #807

claridge opened this issue Jan 21, 2016 · 9 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) type: feature request

Comments

@claridge
Copy link

In #184, we added support for linker scripts (.ld and .lds files) to cc_library's "deps" attribute. However, these don't appear to be mounted to the sandbox.

As a short-term workaround, I put my linker scripts in a filegroup and included that in the linker_files attribute of the appropriate cc_toolchain.

@tjurkiewicz
Copy link

Since cc_toolchain is not officially docummented, could you please describe, how exactly you use the cc_toolchain rule ?

@philwo
Copy link
Member

philwo commented Dec 9, 2016

Is this still an issue? If yes, please kindly re-open this bug with a small example on how to reproduce this. :)

@philwo philwo closed this as completed Dec 9, 2016
@jnewton-sx
Copy link

jnewton-sx commented Feb 22, 2018

@philwo please re-open this issue, it is still an issue and I have an example that reproduces it. It prevents using -Wl,--version-script in linkopts.

Test case:

BUILD:
 
cc_library(
    name="test",
    srcs=["test.c"],
    deps=[':linker.lds'],
    linkopts = ["-Wl,--version-script", "$(location :linker.lds)"],
)

linker.lds:

 LIBTEST_1.0 {
  global:
    func;
 
  local:
    *;
};

test.c:
 
int func(){
  return 0;
}

Works with --spawn_strategy=standalone, otherwise produces:

ERROR: /home/user/bazel-ldscript-testcase/BUILD:1:1: Linking of rule '//:test' failed (Exit 1): linux-sandbox failed: error executing command 
  (cd /home/user/.cache/bazel/_bazel_user/3f57239b7854dc2d2a7465a30e6c1cb3/execroot/__main__ && \
  exec env - \
    LD_LIBRARY_PATH=.: \
    PATH=/home/user/bin:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games \
    PWD=/proc/self/cwd \
    TMPDIR=/tmp \
  /home/user/.cache/bazel/_bazel_user/3f57239b7854dc2d2a7465a30e6c1cb3/execroot/__main__/_bin/linux-sandbox -t 15 -w /home/user/.cache/bazel/_bazel_user/3f57239b7854dc2d2a7465a30e6c1cb3/bazel-sandbox/1558636619903579259/execroot/__main__ -w /tmp -w /dev/shm -D -- /usr/bin/gcc -shared -o bazel-out/k8-fastbuild/bin/libtest.so -Wl,--version-script linker.lds '-fuse-ld=gold' -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -B/usr/bin -pass-exit-codes -Wl,-S -Wl,@bazel-out/k8-fastbuild/bin/libtest.so-2.params)
src/main/tools/linux-sandbox.cc:154: linux-sandbox-pid1 has PID 136963
src/main/tools/linux-sandbox-pid1.cc:175: working dir: /home/user/.cache/bazel/_bazel_user/3f57239b7854dc2d2a7465a30e6c1cb3/bazel-sandbox/1558636619903579259/execroot/__main__
src/main/tools/linux-sandbox-pid1.cc:194: writable: /home/user/.cache/bazel/_bazel_user/3f57239b7854dc2d2a7465a30e6c1cb3/bazel-sandbox/1558636619903579259/execroot/__main__
src/main/tools/linux-sandbox-pid1.cc:194: writable: /tmp
src/main/tools/linux-sandbox-pid1.cc:194: writable: /dev/shm
src/main/tools/linux-sandbox-pid1.cc:265: remount ro: /
src/main/tools/linux-sandbox-pid1.cc:265: remount ro: /dev
src/main/tools/linux-sandbox-pid1.cc:265: remount ro: /dev/pts
src/main/tools/linux-sandbox-pid1.cc:265: remount rw: /dev/shm
src/main/tools/linux-sandbox-pid1.cc:265: remount rw: /home/user/.cache/bazel/_bazel_user/3f57239b7854dc2d2a7465a30e6c1cb3/bazel-sandbox/1558636619903579259/execroot/__main__
src/main/tools/linux-sandbox-pid1.cc:265: remount rw: /home/user/.cache/bazel/_bazel_user/3f57239b7854dc2d2a7465a30e6c1cb3/bazel-sandbox/1558636619903579259/execroot/__main__
src/main/tools/linux-sandbox-pid1.cc:265: remount rw: /tmp
src/main/tools/linux-sandbox-pid1.cc:265: remount rw: /dev/shm
src/main/tools/process-tools.cc:118: sigaction(32, &sa, nullptr) failed
src/main/tools/process-tools.cc:118: sigaction(33, &sa, nullptr) failed
gcc: error: linker.lds: No such file or directory
src/main/tools/linux-sandbox-pid1.cc:437: waitpid returned 2
src/main/tools/linux-sandbox-pid1.cc:457: child exited with code 1
src/main/tools/linux-sandbox.cc:204: child exited normally with exitcode 1
Target //:test failed to build
INFO: Elapsed time: 0.447s, Critical Path: 0.08s
FAILED: Build did NOT complete successfully

Only the following symlinks exist under bazel 10.0’s link-time sandbox, under ~/.cache/bazel/_bazel_user/3f57239b7854dc2d2a7465a30e6c1cb3/bazel-sandbox/2101481633161564656/execroot/__main__$ :

./external/bazel_tools/tools/cpp/build_interface_so
./external/bazel_tools/tools/cpp/link_dynamic_library.sh
./bazel-out/k8-fastbuild/bin/_objs/test/test.pic.o
./bazel-out/k8-fastbuild/bin/libtest.so-2.params

There’s a few related issues, as well as several replies that indicate an expectation for this to work:
#184
#716 (note: this was filed about propagation to cc_binary)
#4440

@philwo philwo reopened this Feb 22, 2018
@philwo
Copy link
Member

philwo commented Feb 22, 2018

@mhlopko Seems like these files are missing from the inputs of C++ link actions? WDYT?

@hlopko
Copy link
Member

hlopko commented Feb 23, 2018

Looks like dup of #716, the workaround is to only use linker scripts on cc_binary, that's how this feature was intended to be used.

@philwo
Copy link
Member

philwo commented Jul 19, 2018

I'm closing this again and unassigning it from me. It is definitely not a sandbox issue, but it might be a C++ rules issue. If it's actually a problem (but I understand @mhlopko so that this is working as intended), then please reopen.

@philwo philwo closed this as completed Jul 19, 2018
@philwo philwo removed their assignment Jul 19, 2018
@hlopko
Copy link
Member

hlopko commented Jul 19, 2018

cc @oquenchil

@keithwyss
Copy link

What's the reason that ldscripts should only work with cc_binary rules @mhlopko and not with cc_library rules? I'd like to understand this better and whether our team is holding it wrong.

@hlopko
Copy link
Member

hlopko commented Dec 14, 2018

ldscripts were meant to be used to give more precise control into symbols visibility/stripping. And that makes sense for cc_binaries only. But I agree that #716 should be fixed somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) type: feature request
Projects
None yet
Development

No branches or pull requests

8 participants