Skip to content

Linker scripts in cc_library deps missing from sandbox #807

Closed

Description

@claridge

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.

Activity

  1. added
    P2
    on Feb 15, 2016
  2. tjurkiewicz commented on Aug 20, 2016

    @tjurkiewicz

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

  3. philwo commented on Dec 9, 2016

    @philwo
    Member

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

  4. jnewton-sx commented on Feb 22, 2018

    @jnewton-sx

    @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

  5. reopened this on Feb 22, 2018
  6. philwo commented on Feb 22, 2018

    @philwo
    Member

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

  7. hlopko commented on Feb 23, 2018

    @hlopko
    Member

    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.

  8. philwo commented on Jul 19, 2018

    @philwo
    Member

    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.

  9. removed their assignment
    on Jul 19, 2018
  10. hlopko commented on Jul 19, 2018

    @hlopko
    Member
  11. keithwyss commented on Nov 6, 2018

    @keithwyss

    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.

  12. hlopko commented on Dec 14, 2018

    @hlopko
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2type: feature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions