You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ad...@apache.org on 2016/09/29 17:50:18 UTC

[3/7] kudu git commit: thirdparty: fix up libtool scripts if needed

thirdparty: fix up libtool scripts if needed

Older versions of libtool (such as the version found on el6) do not pass
-stdlib=libc++ found in CXXFLAGS down to the libtool link command line, and
as a result, the shared object is linked against the system libstdc++. The
net effect is that some thirdparty shared objects sprout @@GLIBCXX
dependencies. Mysteriously, Kudu libraries and binaries themselves do not,
and the @@GLIBCXX dependencies appear to be satisfied via libc++ somehow.

Nevertheless, this is confusing and could prove problematic down the road,
so here's a quick hack to "fix up" libtool scripts after they are generated
via configure.

Change-Id: Id51c10d38984e892496621135634d21f3e2386ce
Reviewed-on: http://gerrit.cloudera.org:8080/4512
Reviewed-by: Dan Burkert <da...@cloudera.com>
Tested-by: Dan Burkert <da...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/3625a0c1
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/3625a0c1
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/3625a0c1

Branch: refs/heads/master
Commit: 3625a0c1704fad8302d0aa0801033d3be5287f00
Parents: fd8a50a
Author: Adar Dembo <ad...@cloudera.com>
Authored: Wed Sep 21 14:47:35 2016 -0700
Committer: Adar Dembo <ad...@cloudera.com>
Committed: Thu Sep 29 17:46:31 2016 +0000

----------------------------------------------------------------------
 thirdparty/build-definitions.sh | 38 +++++++++++++++
 thirdparty/build-thirdparty.sh  |  3 ++
 thirdparty/postflight.py        | 95 ++++++++++++++++++++++++++++++++++++
 3 files changed, 136 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/3625a0c1/thirdparty/build-definitions.sh
----------------------------------------------------------------------
diff --git a/thirdparty/build-definitions.sh b/thirdparty/build-definitions.sh
index d9a5320..86b1a8f 100644
--- a/thirdparty/build-definitions.sh
+++ b/thirdparty/build-definitions.sh
@@ -51,6 +51,39 @@ restore_env() {
   EXTRA_LIBS=${_EXTRA_LIBS}
 }
 
+# Some versions of libtool are vulnerable to a bug[1] wherein clang's -stdlib
+# parameter isn't passed through to the link command line. This causes the
+# libtool to link the shared object against libstdc++ instead of libc++.
+#
+# The bug was only fixed in version 2.4.2 of libtool and el6 carries version
+# 2.2.6, so we work around it here.
+#
+# 1. https://debbugs.gnu.org/db/10/10579.html
+fixup_libtool() {
+  if [[ ! "$EXTRA_CXXFLAGS" =~ "-stdlib=libc++" ]]; then
+    echo "libtool does not need to be fixed up: not using libc++"
+    return
+  fi
+  if [ ! -f libtool ]; then
+    echo "libtool not found"
+    exit 1
+  fi
+  if ! grep -q -e 'postdeps=.*-lstdc++' libtool; then
+    echo "libtool does not need to be fixed up: already configured for libc++"
+    return
+  fi
+
+  # Modify a line like:
+  #
+  #   postdeps="-lfoo -lstdc++ -lbar -lstdc++ -lbaz"
+  #
+  # To become:
+  #
+  #   postdeps="-lfoo -lc++ -lbar -lc++ -lbaz"
+  sed -i.before_fixup -e '/postdeps=/s/-lstdc++/-lc++/g' libtool
+  echo "libtool has been fixed up"
+}
+
 build_cmake() {
   CMAKE_BDIR=$TP_BUILD_DIR/$CMAKE_NAME$MODE_SUFFIX
   mkdir -p $CMAKE_BDIR
@@ -241,6 +274,7 @@ build_glog() {
     --with-pic \
     --prefix=$PREFIX \
     --with-gflags=$PREFIX
+  fixup_libtool
   make -j$PARALLEL install
   popd
 }
@@ -258,6 +292,7 @@ build_gperftools() {
     --enable-heap-checker \
     --with-pic \
     --prefix=$PREFIX
+  fixup_libtool
   make -j$PARALLEL install
   popd
 }
@@ -303,6 +338,7 @@ build_protobuf() {
     --enable-shared \
     --enable-static \
     --prefix=$PREFIX
+  fixup_libtool
   make -j$PARALLEL install
   popd
 }
@@ -318,6 +354,7 @@ build_snappy() {
     $SNAPPY_SOURCE/configure \
     --with-pic \
     --prefix=$PREFIX
+  fixup_libtool
   make -j$PARALLEL install
   popd
 }
@@ -445,6 +482,7 @@ build_crcutil() {
     LIBS="$EXTRA_LIBS" \
     ./configure \
     --prefix=$PREFIX
+  fixup_libtool
   make -j$PARALLEL install
   popd
 }

http://git-wip-us.apache.org/repos/asf/kudu/blob/3625a0c1/thirdparty/build-thirdparty.sh
----------------------------------------------------------------------
diff --git a/thirdparty/build-thirdparty.sh b/thirdparty/build-thirdparty.sh
index 4bba95c..6271b3b 100755
--- a/thirdparty/build-thirdparty.sh
+++ b/thirdparty/build-thirdparty.sh
@@ -379,5 +379,8 @@ if [ -n "$F_TSAN" ]; then
   restore_env
 fi
 
+# Now run the post-flight checks.
+$TP_DIR/postflight.py
+
 echo "---------------------"
 echo "Thirdparty dependencies built and installed into $PREFIX successfully"

http://git-wip-us.apache.org/repos/asf/kudu/blob/3625a0c1/thirdparty/postflight.py
----------------------------------------------------------------------
diff --git a/thirdparty/postflight.py b/thirdparty/postflight.py
new file mode 100755
index 0000000..0a20823
--- /dev/null
+++ b/thirdparty/postflight.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+Simple script which performs some sanity checks on the built thirdparty/.
+"""
+
+import os
+import subprocess
+import sys
+
+TP_DIR = os.path.dirname(os.path.realpath(__file__))
+
+def shell(status_msg, script):
+  to_print = status_msg + " ..."
+
+  p = subprocess.Popen(["/bin/bash"],
+      stderr=subprocess.PIPE,
+      stdout=subprocess.PIPE,
+      stdin=subprocess.PIPE)
+  stdout, _ = p.communicate(input=script)
+  if p.returncode != 0:
+    to_print += " FAILED\n"
+    for line in stdout.strip().split("\n"):
+      to_print += "==> " + line + "\n"
+  else:
+    to_print += " PASSED"
+  print to_print
+
+  if p.returncode != 0:
+    sys.exit(1)
+
+
+def check_tsan_dependencies():
+  shell(
+    "Checking that no TSAN dependency depends on libstdc++",
+"""
+if [[ "$OSTYPE" == "darwin"* ]]; then
+  echo No TSAN support on macOS, skipping test
+  exit 0
+fi
+
+lib_dir="{tp_dir}/installed/tsan/lib"
+echo Looking for TSAN dependencies directory $lib_dir
+if [ ! -d "$lib_dir" ]; then
+  echo Could not find TSAN dependencies directory $lib_dir, skipping test
+  exit 0
+fi
+echo Found TSAN dependencies directory $lib_dir
+
+echo Looking for ldd
+if ! $(which ldd > /dev/null 2>&1); then
+  echo Could not find ldd
+  exit 1
+fi
+echo Found ldd
+
+echo Checking dependencies
+for so in $lib_dir/*.so; do
+  found=$(ldd $so 2>/dev/null | grep -q libstdc++ && echo $so)
+  if [ -n "$found" ]; then
+    echo Found bad dependency: $found
+    exit 1
+  fi
+done
+
+echo All TSAN dependencies checked
+""".format(tp_dir=TP_DIR))
+
+
+def main():
+  print "Running post-flight checks"
+  print "-------------------------"
+  check_tsan_dependencies()
+  print "-------------------------"
+  print "Post-flight checks succeeded."
+  return 0
+
+if __name__ == "__main__":
+  sys.exit(main())