Fix shared library dependencies verification on some platforms (dotnet/coreclr#8349)
authorJan Vorlicek <janvorli@microsoft.com>
Tue, 29 Nov 2016 18:09:35 +0000 (19:09 +0100)
committerGitHub <noreply@github.com>
Tue, 29 Nov 2016 18:09:35 +0000 (19:09 +0100)
The existing way of verifying shared library dependencies, used for
System.Globalization.Native.so, doesn't work on platforms that don't
have ldd or where ldd doesn't support the `-r` option.
This change makes the check happen on non-Alpine Linux only for now.
It also refactors the way the check is performed. Instead of doing it
post build in the build.sh, it is now performed as a postbuild phase
of the System.Globalization.Native target and it is also generalized
so that we can easily add such verification to other build targets.
The new verify-so.sh script is also used in corefx.

Commit migrated from https://github.com/dotnet/coreclr/commit/74816870ce9ff5ec41d30455a7dcc3b5d327bf45

src/coreclr/build.sh
src/coreclr/functions.cmake
src/coreclr/src/corefx/System.Globalization.Native/CMakeLists.txt
src/coreclr/verify-so.sh [new file with mode: 0755]

index 61b5ab1..1017d5c 100755 (executable)
@@ -218,14 +218,6 @@ build_coreclr()
         exit 1
     fi
 
-    echo "Verifying System.Globalization.Native.so dependencies"
-
-    ldd -r $__BinDir/System.Globalization.Native.so | awk 'BEGIN {count=0} /undefined symbol:/ { if (count==0) {print "Undefined symbol(s) found:"} print " " $3; count++ } END {if (count>0) exit(1)}'
-    if [ $? != 0 ]; then
-        echo "Failed. System.Globalization.Native.so has undefined dependencies. These are likely ICU APIs that need to be added to icushim.h"
-        exit 1
-    fi
-
        popd
 }
 
index f8a2eea..bac20e8 100644 (file)
@@ -216,3 +216,19 @@ function(_install)
       install(${ARGV})
     endif()
 endfunction()
+
+function(verify_dependencies targetName errorMessage)
+    # We don't need to verify dependencies on OSX, since missing dependencies
+    # result in link error over there.
+    if (NOT CLR_CMAKE_PLATFORM_DARWIN)
+        add_custom_command(
+            TARGET ${targetName}
+            POST_BUILD
+            VERBATIM
+            COMMAND ${CMAKE_SOURCE_DIR}/verify-so.sh 
+                $<TARGET_FILE:${targetName}> 
+                ${errorMessage}
+            COMMENT "Verifying ${targetName} dependencies"
+        )
+    endif()
+endfunction()
index 5892856..90f5067 100644 (file)
@@ -93,5 +93,11 @@ else()
     add_definitions(-DU_DISABLE_RENAMING=1)
 endif()
 
+verify_dependencies(
+    System.Globalization.Native
+    "Verification failed. System.Globalization.Native.so has undefined dependencies. These are likely ICU APIs that need to be added to icushim.h."
+)
+
 # add the install targets
 install_clr(System.Globalization.Native)
+
diff --git a/src/coreclr/verify-so.sh b/src/coreclr/verify-so.sh
new file mode 100755 (executable)
index 0000000..3907cf1
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+# $1 contains full path to the .so to verify
+# $2 contains message to print when the verification fails
+
+OSName=$(uname -s)
+case $OSName in
+    Linux)
+        source /etc/os-release
+        # TODO: add support for verification on Alpine Linux
+        if [ "$ID" != "alpine" ]; then
+            ldd -r $1 | awk 'BEGIN {count=0} /undefined symbol:/ { if (count==0) {print "Undefined symbol(s) found:"} print " " $3; count++ } END {if (count>0) exit(1)}'
+            if [ $? != 0 ]; then
+                echo "$2"
+                exit 1
+            fi
+        fi
+        ;;
+esac
+
+# TODO: add support for verification on non-Linux Unixes (except of OSX)