From 6e4ee8da2b209c8f53bff1e0e84e59e764d3b9d9 Mon Sep 17 00:00:00 2001 From: Thad House Date: Fri, 3 Jul 2020 21:53:56 -0700 Subject: [PATCH] [cscore] Limit jnicvstatic exports to only C and JNI symbols (#2565) Reduces risk even more about accidentally interfering with OpenCV. --- buildSrc/src/main/groovy/SingleNativeBuild.groovy | 2 +- cscore/build.gradle | 9 ++++++++- cscore/src/main/native/LinuxSymbolScript.txt | 4 ++++ cscore/src/main/native/MacSymbolScript.txt | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 cscore/src/main/native/LinuxSymbolScript.txt create mode 100644 cscore/src/main/native/MacSymbolScript.txt diff --git a/buildSrc/src/main/groovy/SingleNativeBuild.groovy b/buildSrc/src/main/groovy/SingleNativeBuild.groovy index 2b7e087b24..3dc6fb7bb7 100644 --- a/buildSrc/src/main/groovy/SingleNativeBuild.groovy +++ b/buildSrc/src/main/groovy/SingleNativeBuild.groovy @@ -79,7 +79,7 @@ class SingleNativeBuild implements Plugin { components.each { component -> if (component.name == "${nativeName}Base") { base = (NativeLibrarySpec) component - } else if (component.name == "${nativeName}" || component.name == "${nativeName}JNI") { + } else if (component.name == "${nativeName}" || component.name == "${nativeName}JNI" || component.name == "${nativeName}JNICvStatic") { subs << component } } diff --git a/cscore/build.gradle b/cscore/build.gradle index 383fe68be2..3366f9d72e 100644 --- a/cscore/build.gradle +++ b/cscore/build.gradle @@ -18,7 +18,7 @@ apply from: "${rootDir}/shared/jni/setupBuild.gradle" model { components { cscoreJNICvStatic(JniNativeLibrarySpec) { - baseName = 'cscore-jnicvstatic' + baseName = 'cscorejnicvstatic' enableCheckTask true javaCompileTasks << compileJava @@ -46,6 +46,13 @@ model { } lib library: "${nativeName}", linkage: 'static' lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' + + if (it.targetPlatform.operatingSystem.linux) { + it.linker.args '-Wl,--version-script=' + file('src/main/native/LinuxSymbolScript.txt') + } else if (it.targetPlatform.operatingSystem.macOsX) { + it.linker.args '-exported_symbols_list' + it.linker.args file('src/main/native/MacSymbolScript.txt').toString() + } } } } diff --git a/cscore/src/main/native/LinuxSymbolScript.txt b/cscore/src/main/native/LinuxSymbolScript.txt new file mode 100644 index 0000000000..505808064c --- /dev/null +++ b/cscore/src/main/native/LinuxSymbolScript.txt @@ -0,0 +1,4 @@ +cscorejnicvstatic { + global: CS_*; JNI_*; Java_*; # explicitly list symbols to be exported + local: *; # hide everything else +}; diff --git a/cscore/src/main/native/MacSymbolScript.txt b/cscore/src/main/native/MacSymbolScript.txt new file mode 100644 index 0000000000..ecfe349d53 --- /dev/null +++ b/cscore/src/main/native/MacSymbolScript.txt @@ -0,0 +1,3 @@ +_CS_* +_JNI_* +_Java_*