aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar David G. Andersen <dga@google.com>2017-09-12 11:56:28 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-09-12 12:01:12 -0700
commit3438981ca7b659e57fb1e15152a1f9fd99b5d6bc (patch)
treed987f33b739946bdd2674c7f806e092bb37b3074
parent7e023d865d8297a429936a64e42a0bcd256eac66 (diff)
Apply exported symbol filtering to the c++ API analogously to
what is filtered for the C API. Fixes bug reported in comments on #1924 PiperOrigin-RevId: 168413719
-rw-r--r--tensorflow/BUILD27
1 files changed, 27 insertions, 0 deletions
diff --git a/tensorflow/BUILD b/tensorflow/BUILD
index ff2892bce4..5cd92d2ff4 100644
--- a/tensorflow/BUILD
+++ b/tensorflow/BUILD
@@ -454,6 +454,17 @@ filegroup(
# -------------------------------------------
# New rules should be added above this target.
# -------------------------------------------
+
+# TensorFlow uses several libraries that may also be used by applications
+# linking against the C and C++ APIs (such as libjpeg). When we create
+# the shared library, only export the core TF API functions to avoid
+# causing library conflicts (e.g., those reported in github issue 1924).
+# On Linux, tell the linker (-Wl,<option>) to use a version script that
+# excludes all but a subset of function names.
+# On MacOS, the linker does not support version_script, but has an
+# an "-exported_symbols_list" command. -z defs disallows undefined
+# symbols in object files and -s strips the output.
+
cc_binary(
name = "libtensorflow.so",
linkopts = select({
@@ -482,8 +493,24 @@ cc_binary(
cc_binary(
name = "libtensorflow_cc.so",
+ linkopts = select({
+ "//tensorflow:darwin": [
+ "-Wl,-exported_symbols_list", # This line must be directly followed by the exported_symbols.lds file
+ "//tensorflow:tf_exported_symbols.lds",
+ ],
+ "//tensorflow:windows": [],
+ "//tensorflow:windows_msvc": [],
+ "//conditions:default": [
+ "-z defs",
+ "-s",
+ "-Wl,--version-script", # This line must be directly followed by the version_script.lds file
+ "//tensorflow:tf_version_script.lds",
+ ],
+ }),
linkshared = 1,
deps = [
+ "//tensorflow:tf_exported_symbols.lds",
+ "//tensorflow:tf_version_script.lds",
"//tensorflow/c:c_api",
"//tensorflow/c/eager:c_api",
"//tensorflow/cc:cc_ops",