You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by no...@apache.org on 2017/02/08 17:02:52 UTC

[trafficserver] branch master updated: Prune some unused library dependencies

This is an automated email from the ASF dual-hosted git repository.

nottheoilrig pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/master by this push:
       new  a7fb5f1   Prune some unused library dependencies
a7fb5f1 is described below

commit a7fb5f1eea5c16935fa7a7ae4686c6a44ac32a5a
Author: Jack Bates <ja...@nottheoilrig.com>
AuthorDate: Wed Feb 1 14:29:16 2017 -0700

    Prune some unused library dependencies
    
    and add a script to check for unused dependencies going forward.
---
 Makefile.am                     |  2 +
 cmd/traffic_cop/Makefile.am     |  3 +-
 cmd/traffic_ctl/Makefile.am     |  3 +-
 cmd/traffic_manager/Makefile.am |  2 +-
 cmd/traffic_via/Makefile.am     |  3 +-
 proxy/Makefile.am               |  5 +--
 tools/Makefile.am               |  2 +-
 tools/check-unused-dependencies | 97 +++++++++++++++++++++++++++++++++++++++++
 8 files changed, 106 insertions(+), 11 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index f1a8747..e28a028 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -99,6 +99,8 @@ install-examples: examples
 install-data-hook:
 	@cd doc && $(MAKE) $(AM_MAKEFLAGS) install-man
 
+TESTS = tools/check-unused-dependencies
+
 rat:
 	java -jar $(top_srcdir)/ci/apache-rat-0.11-SNAPSHOT.jar -E $(top_srcdir)/ci/rat-regex.txt  -d $(top_srcdir)
 
diff --git a/cmd/traffic_cop/Makefile.am b/cmd/traffic_cop/Makefile.am
index b098cc9..ceb8026 100644
--- a/cmd/traffic_cop/Makefile.am
+++ b/cmd/traffic_cop/Makefile.am
@@ -36,8 +36,7 @@ traffic_cop_LDADD = \
   $(top_builddir)/mgmt/libmgmt_c.la \
   $(top_builddir)/mgmt/api/libtsmgmt.la \
   $(top_builddir)/lib/ts/libtsutil.la \
-  $(top_builddir)/lib/records/librecords_cop.a \
-  @LIBRESOLV@
+  $(top_builddir)/lib/records/librecords_cop.a
 
 include $(top_srcdir)/build/tidy.mk
 
diff --git a/cmd/traffic_ctl/Makefile.am b/cmd/traffic_ctl/Makefile.am
index 11bdd7d..220097c 100644
--- a/cmd/traffic_ctl/Makefile.am
+++ b/cmd/traffic_ctl/Makefile.am
@@ -36,8 +36,7 @@ traffic_ctl_SOURCES = \
 
 traffic_ctl_LDADD = \
   $(top_builddir)/mgmt/api/libtsmgmt.la \
-  $(top_builddir)/lib/ts/libtsutil.la \
-  @LIBRESOLV@ @LIBTCL@
+  $(top_builddir)/lib/ts/libtsutil.la
 
 include $(top_srcdir)/build/tidy.mk
 
diff --git a/cmd/traffic_manager/Makefile.am b/cmd/traffic_manager/Makefile.am
index 5f4cd95..43dd559 100644
--- a/cmd/traffic_manager/Makefile.am
+++ b/cmd/traffic_manager/Makefile.am
@@ -64,7 +64,7 @@ traffic_manager_LDADD += \
 
 traffic_manager_LDADD +=\
   $(LIBUNWIND_LIBS) \
-  @LIBRESOLV@ @LIBPCRE@ @LIBTCL@ @LIBCAP@ @HWLOC_LIBS@ \
+  @LIBPCRE@ @LIBTCL@ @LIBCAP@ @HWLOC_LIBS@ \
   -lm
 
 # Must do it this way or the dependencies aren't detected.
diff --git a/cmd/traffic_via/Makefile.am b/cmd/traffic_via/Makefile.am
index 7a6853d..d550125 100644
--- a/cmd/traffic_via/Makefile.am
+++ b/cmd/traffic_via/Makefile.am
@@ -32,8 +32,7 @@ traffic_via_SOURCES = \
 
 traffic_via_LDADD = \
   $(top_builddir)/lib/ts/libtsutil.la \
-  @LIBPCRE@ \
-  @LIBTCL@
+  @LIBPCRE@
 
 TESTS = \
   test_traffic_via
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index c4bd26b..d44cdd0 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -215,7 +215,6 @@ traffic_server_LDADD = \
   @HWLOC_LIBS@ \
   @LIBPCRE@ \
   @LIBTCL@ \
-  @LIBCAP@ \
   @LIBRESOLV@ \
   @LIBZ@ \
   @LIBLZMA@ \
@@ -236,7 +235,7 @@ traffic_logcat_LDADD = \
   $(top_builddir)/lib/ts/libtsutil.la \
   $(top_builddir)/lib/bindings/libbindings.la \
   $(top_builddir)/lib/luajit/src/libluajit.a \
-  @LIBRESOLV@ @LIBPCRE@ @LIBTCL@ @HWLOC_LIBS@\
+  @LIBTCL@ @HWLOC_LIBS@\
   @LIBPROFILER@ -lm
 
 traffic_logstats_SOURCES = logstats.cc
@@ -250,7 +249,7 @@ traffic_logstats_LDADD = \
   $(top_builddir)/lib/ts/libtsutil.la \
   $(top_builddir)/lib/bindings/libbindings.la \
   $(top_builddir)/lib/luajit/src/libluajit.a \
-  @LIBRESOLV@ @LIBPCRE@ @LIBTCL@ @HWLOC_LIBS@ \
+  @LIBTCL@ @HWLOC_LIBS@ \
   @LIBPROFILER@ -lm
 
 versiondir = $(pkgsysconfdir)
diff --git a/tools/Makefile.am b/tools/Makefile.am
index d6223ef..2937ee0 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -33,7 +33,7 @@ noinst_PROGRAMS = jtest/jtest
 endif
 
 jtest_jtest_SOURCES = jtest/jtest.cc
-jtest_jtest_LDADD = $(top_builddir)/lib/ts/libtsutil.la @OPENSSL_LIBS@
+jtest_jtest_LDADD = $(top_builddir)/lib/ts/libtsutil.la
 
 if BUILD_HTTP_LOAD
 
diff --git a/tools/check-unused-dependencies b/tools/check-unused-dependencies
new file mode 100755
index 0000000..a7908d0
--- /dev/null
+++ b/tools/check-unused-dependencies
@@ -0,0 +1,97 @@
+#!/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.
+
+# Check for programs linked with libraries they don't in fact use.
+# For example, if a program was linked with -lfoo but doesn't use any
+# symbols from libfoo.
+#
+# The list of programs is gathered by scraping Automake files, which are
+# themselves gathered from Git. ldd does the actual business of checking
+# for unused dependencies.
+#
+# There are a couple of manual exceptions listed below, either because
+# we deliberately link with an unused library -- possibly for
+# convenience -- or because I haven't figured out how to fix it yet.
+#
+# For now, this only checks the programs that we install,
+# but it could potentially check our libraries as well.
+
+import os.path
+import re
+import subprocess
+import sys
+
+programs_re = re.compile(r'([^\n ]*_)PROGRAMS \+?= (.*)')
+
+
+def get_dependencies(program):
+  args = [
+      './libtool', '--mode=execute', 'ldd', '--unused', '--function-relocs',
+      program
+  ]
+  for dependency in subprocess.Popen(args, stdout=subprocess.PIPE).stdout:
+    dependency = dependency[:-1]
+    if any(
+        map(
+            os.path.basename(dependency).startswith,
+            [
+                'libdl.so.',  # Because we add -ldl to LIBS
+                'libgcc_s.so.',
+                'libm.so.',  # Why does Libtool call ld with -lm?
+                'libpthread.so.',  # Because we add -lpthread to LIBS
+            ])):
+      continue
+
+    # Why does Libtool call ld with -lcrypto -lresolv -lssl?
+    if os.path.basename(program) == 'traffic_manager':
+      if any(
+          map(
+              os.path.basename(dependency).startswith, [
+                  'libcrypto.so.',
+                  'libresolv.so.',
+                  'libssl.so.',
+              ])):
+        continue
+
+    yield dependency
+
+
+success = True
+args = ['git', 'ls-files']
+for filename in subprocess.Popen(args, stdout=subprocess.PIPE).stdout:
+  filename = filename[:-1]
+  if os.path.basename(filename) == 'Makefile.am':
+    contents = open(filename).read()
+    contents = contents.replace('\\\n', '')
+    for prefix, programs in programs_re.findall(contents):
+      if prefix not in {
+          'EXTRA_',
+          'check_',
+          'noinst_',
+      }:
+        for program in programs.split():
+          program = os.path.join(os.path.dirname(filename), program)
+          if os.path.exists(program):
+            dependencies = list(get_dependencies(program))
+            if len(dependencies) > 1:
+              success = False
+              print program
+              for dependency in dependencies:
+                print dependency
+
+if not success:
+  sys.exit(1)

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].