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

OS X: Nonexistant shared library search path when linking in a Bazel-generated shared object #3450

Closed
allenlavoie opened this issue Jul 25, 2017 · 5 comments
Assignees
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) type: bug

Comments

@allenlavoie
Copy link
Contributor

Description of the problem / feature request / question:

(Largely irrelevant background) I'm attempting to split out a shared object from TensorFlow that extensions (custom user ops) can rely on. This means TensorFlow itself will need to rely on the same shared object (so it can access the list of ops registered by custom op libraries), which looks like it will involve cc_binary rule with linkshared=1 which gets re-used within TensorFlow (e.g. our Python extension _pywrap_tensorflow.so will depend on this cc_binary rule).

I have a prototype which is working, although I've run into an OS X linking issue which means tests on that platform need to be built with linkstatic=1.

If possible, provide a minimal example to reproduce the problem:

At https://github.com/allenlavoie/bazelrepro

git clone https://github.com/allenlavoie/bazelrepro.git
cd bazelrepro/
bazel run :link_repro

The important bit (the source files are ~trivial):

cc_library(
	name="regular_dep",
	hdrs=["regular_dep.h"],
	srcs=["regular_dep.cc"],
)

cc_binary(
	name="libsome.so",
	linkshared=1,
)

cc_test(
	name="link_repro",
	srcs=[
            "test.cc",
            ":libsome.so" # Removing this fixes the test!
          ],
	deps=[":regular_dep"],
)

This gets me output like:

INFO: Reading 'startup' options from /etc/bazel.bazelrc: --batch
INFO: Found 1 target...
Target //:link_repro up-to-date:
  bazel-bin/link_repro
INFO: Elapsed time: 6.749s, Critical Path: 0.21s

INFO: Running command line: bazel-bin/link_repro
dyld: Library not loaded: @loader_path/_solib_darwin_x86_64/_U_S_S_Clink_Urepro___U/liblibregular_Udep.so
  Referenced from: /private/var/tmp/_bazel_allen/5fdaac27a275125cca7a7ab6df9508e8/execroot/__main__/bazel-out/darwin_x86_64-fastbuild/bin/link_repro
  Reason: image not found

Running otool -L on the binary:

otool -L bazel-bin/link_repro
bazel-bin/link_repro:
	@loader_path/_solib_darwin_x86_64/_U_S_S_Clink_Urepro___U/libsome.so (compatibility version 0.0.0, current version 0.0.0)
	@loader_path/_solib_darwin_x86_64/_U_S_S_Clink_Urepro___U/liblibregular_Udep.so (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)

bazel-bin/_solib_darwin_x86_64/liblibregular_Udep.so does exist, but the path above does not. Removing ":libsome.so" from the srcs of the link_repro means the test passes, and otool -L on the binary returns:

otool -L bazel-bin/link_repro
bazel-bin/link_repro:
	@loader_path/_solib_darwin_x86_64//liblibregular_Udep.so (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)

Which is the correct location for the regular_dep shared object, although the double slash is a bit suspicious.

Environment info

  • Operating System:

macOS Sierra 10.12.5

  • Bazel version (output of bazel info release):

release 0.5.2

Have you found anything relevant by searching the web?

This may be the same underlying problem as #507 (similar symptoms, although the cause sounds different). Feel free to close as a duplicate if you think they're the same.

@hlopko hlopko self-assigned this Aug 1, 2017
@hlopko hlopko added category: rules > C++ P3 We're not considering working on this, but happy to review a PR. (No assignee) type: bug labels Aug 1, 2017
@martinwicke
Copy link

This will likely start blocking TF's effort to build more modularly, and if so, will quickly become a priority for us. For now, since it appears to only affect Macs, we can continue working.

@hlopko
Copy link
Member

hlopko commented Aug 7, 2017

I have a fix in the oven, will try to submit this week.

@hlopko
Copy link
Member

hlopko commented Aug 17, 2017

And finally submitting.

@gunan
Copy link

gunan commented Aug 18, 2017

Great!
which release should we expect this to be in?

@hlopko
Copy link
Member

hlopko commented Aug 21, 2017

The fix was too late for 0.5.4 so the one after that.

bazel-io pushed a commit that referenced this issue Oct 11, 2017
In f426544 I updated osx_cc_wrapper to work correctly in case both
precompiled .so and cc_library-made .so are linked into a single binary. This cl
makes osx_cc_wrapper work also when a precompiled .dylib is provided.

Fixes #3450 again for dylibs
Fixes #407
One step closer to finishing #1576

RELNOTES: None.
PiperOrigin-RevId: 171683650
bazel-io pushed a commit that referenced this issue Oct 11, 2017
*** Reason for rollback ***

I broke http://ci.bazel.io/view/Dashboard/job/bazel-tests/1079/testReport/junit/(root)/(empty)/test_osx_cc_wrapper_rpaths_handling/

*** Original change description ***

Fix osx_cc_wrapper to also update dylibs

In f426544 I updated osx_cc_wrapper to work correctly in case both
precompiled .so and cc_library-made .so are linked into a single binary. This cl
makes osx_cc_wrapper work also when a precompiled .dylib is provided.

Fixes #3450 again for dylibs
Fixes #407
One step closer to finishing #1576

RELNOTES: None.
PiperOrigin-RevId: 171806769
bazel-io pushed a commit that referenced this issue Oct 13, 2017
In f426544 I updated osx_cc_wrapper to work correctly in case both
precompiled .so and cc_library-made .so are linked into a single binary. This cl
makes osx_cc_wrapper work also when a precompiled .dylib is provided.

This is roll-forward of 0257c29.

Fixes #3450 again for dylibs
Fixes #407
One step closer to finishing #1576

RELNOTES: None.
PiperOrigin-RevId: 171969333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) type: bug
Projects
None yet
Development

No branches or pull requests

4 participants