Browse Source

Detect if LD supports --version-script and, if so, use that in order to hide symbols exported by a plugin. If not - use -export-symbols and a symbol.map file instead of an -export-symbols-regex, which can lead to more issues than it can solve.

Stanislav Galabov 11 years ago
parent
commit
cc00cf1137
4 changed files with 42 additions and 1 deletions
  1. 30 0
      configure.ac
  2. 5 1
      plugins/lua/module.am
  3. 3 0
      plugins/lua/symbols.map
  4. 4 0
      plugins/lua/version.map

+ 30 - 0
configure.ac

@@ -29,6 +29,36 @@ AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
 AC_CHECK_SIZEOF(size_t)
 
+#########################################
+# See if linker supports version scripts
+#########################################
+# Check if LD supports linker scripts,
+# and define automake conditional HAVE_LD_VERSION_SCRIPT if so.
+AC_ARG_ENABLE([ld-version-script],
+              AS_HELP_STRING([--enable-ld-version-script],
+                             [enable linker version script (default is enabled when possible)]),
+                             [have_ld_version_script=$enableval], [])
+if test -z "$have_ld_version_script"; then
+    AC_MSG_CHECKING([if LD -Wl,--version-script works])
+    save_LDFLAGS="$LDFLAGS"
+    LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
+    cat > conftest.map <<EOF
+VERS_1 {
+    global: sym;
+};
+
+VERS_2 {
+    global: sym;
+} VERS_1;
+EOF
+    AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 0; }])],
+                   [have_ld_version_script=yes], [have_ld_version_script=no])
+    rm -f conftest.map
+    LDFLAGS="$save_LDFLAGS"
+    AC_MSG_RESULT($have_ld_version_script)
+fi
+AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
+
 ################################
 # Deal with debugging options
 ################################

+ 5 - 1
plugins/lua/module.am

@@ -2,7 +2,11 @@ lib_LTLIBRARIES			+= clish_plugin_lua.la
 clish_plugin_lua_la_SOURCES	 = 
 clish_plugin_lua_la_LIBADD	 = @LUA_LIB@
 clish_plugin_lua_la_LDFLAGS	 = -avoid-version -module -shared
-clish_plugin_lua_la_LDFLAGS	+= -export-symbols-regex "^clish_plugin_"
+if HAVE_LD_VERSION_SCRIPT
+clish_plugin_lua_la_LDFLAGS	+= -Wl,--version-script=plugins/lua/version.map
+else
+clish_plugin_lua_la_LDFLAGS     += -export-symbols plugins/lua/symbols.map
+endif
 
 clish_plugin_lua_la_CPPFLAGS	 = $(AM_CPPFLAGS) @LUA_INCLUDE@
 

+ 3 - 0
plugins/lua/symbols.map

@@ -0,0 +1,3 @@
+clish_plugin_init
+clish_plugin_fini
+clish_plugin_lua_action

+ 4 - 0
plugins/lua/version.map

@@ -0,0 +1,4 @@
+{
+	global: clish_plugin_init; clish_plugin_fini; clish_plugin_lua_action;
+	local: *;
+};