Hook up nm to check for leaking symbols in the static library
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 18 Aug 2014 23:16:39 +0000 (09:16 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 25 Aug 2014 00:06:48 +0000 (10:06 +1000)
We ignore anything that starts with an underscore, anything that starts with
libevdev and main (since we test the test-static-link binary) and a couple of
gcov-related functions. This should catch any functions we accidentally
export.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
configure.ac
test/Makefile.am

index 4781434..bb4bbbb 100644 (file)
@@ -125,6 +125,16 @@ AC_MSG_RESULT([$enable_gcov])
 
 AM_PATH_PYTHON([2.6])
 
+# nm to check for leaking symbols in the static library
+AC_PATH_PROG(NM, [nm])
+AM_CONDITIONAL(HAVE_NM, [test "x$NM" != "x"])
+if test "x$NM" == "x"; then
+       AC_MSG_WARN([nm not found - skipping symbol leak test])
+       have_nm="no"
+else
+       have_nm="yes"
+fi
+
 AC_CONFIG_FILES([Makefile
                 libevdev/Makefile
                 doc/Makefile
@@ -136,7 +146,8 @@ AC_CONFIG_FILES([Makefile
 AC_OUTPUT
 
 AC_MSG_RESULT([
-              Build documentation      ${have_doxygen}
-              Build unit-tests         ${HAVE_CHECK}
-              Enable profiling         ${enable_gcov}
+              Build documentation              ${have_doxygen}
+              Build unit-tests                 ${HAVE_CHECK}
+              Enable profiling                 ${enable_gcov}
+              Static library symbol check      ${have_nm}
               ])
index 992ce4f..0781d72 100644 (file)
@@ -119,6 +119,26 @@ endif
 clean-local: gcov-clean
        rm -f *.gcno *.gcda
 
-check-local: $(check_local_deps)
+if HAVE_NM
+# Hack to check for leaking symbols in the static library.
+# See https://bugs.freedesktop.org/show_bug.cgi?id=82785
+# Note the spaces in the expressions! After the first grep, each line
+# is " T symbol_name"
+static-symbol-leaks: test-static-link
+       $(AM_V_GEN)(\
+               $(NM) --extern-only $(builddir)/test-static-link | \
+                       grep -o -e " T .*" | \
+                       grep -v -e " main$$" \
+                               -e " atexit" \
+                               -e " *gcov.*" \
+                               -e " _.*" \
+                               -e " libevdev_*" && \
+                               echo "Leaking symbols found" && \
+                               exit 1 || exit 0 \
+       )
 
+check_local_deps += static-symbol-leaks
+endif
+
+check-local: $(check_local_deps)
 endif