diff --git a/make/autoconf/flags-cflags.m4 b/make/autoconf/flags-cflags.m4 index 78bca110357..658d6299b4d 100644 --- a/make/autoconf/flags-cflags.m4 +++ b/make/autoconf/flags-cflags.m4 @@ -537,7 +537,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER], if test "x$TOOLCHAIN_TYPE" = xgcc; then TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -fstack-protector" - TOOLCHAIN_CFLAGS_JDK="-pipe -fstack-protector" + TOOLCHAIN_CFLAGS_JDK="-fvisibility=hidden -pipe -fstack-protector" # reduce lib size on linux in link step, this needs also special compile flags # do this on s390x also for libjvm (where serviceability agent is not supported) if test "x$ENABLE_LINKTIME_GC" = xtrue; then @@ -572,6 +572,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER], TOOLCHAIN_CFLAGS_JDK="-pipe" TOOLCHAIN_CFLAGS_JDK_CONLY="-fno-strict-aliasing" # technically NOT for CXX fi + TOOLCHAIN_CFLAGS_JDK="$TOOLCHAIN_CFLAGS_JDK -fvisibility=hidden" elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then # The -utf-8 option sets source and execution character sets to UTF-8 to enable correct diff --git a/make/autoconf/flags-ldflags.m4 b/make/autoconf/flags-ldflags.m4 index b0f56a53a3d..bf9b817ee72 100644 --- a/make/autoconf/flags-ldflags.m4 +++ b/make/autoconf/flags-ldflags.m4 @@ -61,7 +61,7 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER], # add -z,relro (mark relocations read only) for all libs # add -z,now ("full relro" - more of the Global Offset Table GOT is marked read only) # add --no-as-needed to disable default --as-needed link flag on some GCC toolchains - BASIC_LDFLAGS="-Wl,-z,defs -Wl,-z,relro -Wl,-z,now -Wl,--no-as-needed" + BASIC_LDFLAGS="-Wl,-z,defs -Wl,-z,relro -Wl,-z,now -Wl,--no-as-needed -Wl,--exclude-libs,ALL" # Linux : remove unused code+data in link step if test "x$ENABLE_LINKTIME_GC" = xtrue; then if test "x$OPENJDK_TARGET_CPU" = xs390x; then @@ -81,6 +81,9 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER], LDFLAGS_CXX_PARTIAL_LINKING="$MACHINE_FLAG -r" + if test "x$OPENJDK_TARGET_OS" = xlinux; then + BASIC_LDFLAGS="-Wl,--exclude-libs,ALL" + fi if test "x$OPENJDK_TARGET_OS" = xaix; then BASIC_LDFLAGS="-Wl,-b64 -Wl,-brtl -Wl,-bnorwexec -Wl,-bnolibpath -Wl,-bnoexpall \ -Wl,-bernotok -Wl,-bdatapsize:64k -Wl,-btextpsize:64k -Wl,-bstackpsize:64k" diff --git a/make/common/TestFilesCompilation.gmk b/make/common/TestFilesCompilation.gmk index 85e01b0a521..fd2954cbec6 100644 --- a/make/common/TestFilesCompilation.gmk +++ b/make/common/TestFilesCompilation.gmk @@ -59,15 +59,6 @@ define SetupTestFilesCompilationBody # Always include common test functionality TEST_CFLAGS := -I$(TOPDIR)/test/lib/native - ifeq ($(TOOLCHAIN_TYPE), gcc) - TEST_CFLAGS += -fvisibility=hidden - TEST_LDFLAGS += -Wl,--exclude-libs,ALL - else ifeq ($(TOOLCHAIN_TYPE), clang) - TEST_CFLAGS += -fvisibility=hidden - else ifeq ($(TOOLCHAIN_TYPE), xlc) - TEST_CFLAGS += -qvisibility=hidden - endif - # The list to depend on starts out empty $1 := ifeq ($$($1_TYPE), LIBRARY) @@ -75,7 +66,7 @@ define SetupTestFilesCompilationBody $1_OUTPUT_SUBDIR := lib $1_BASE_CFLAGS := $(CFLAGS_JDKLIB) $$(TEST_CFLAGS) $1_BASE_CXXFLAGS := $(CXXFLAGS_JDKLIB) $$(TEST_CFLAGS) - $1_LDFLAGS := $(LDFLAGS_JDKLIB) $$(TEST_LDFLAGS) $$(call SET_SHARED_LIBRARY_ORIGIN) + $1_LDFLAGS := $(LDFLAGS_JDKLIB) $$(call SET_SHARED_LIBRARY_ORIGIN) $1_COMPILATION_TYPE := LIBRARY $1_LOG_TYPE := library else ifeq ($$($1_TYPE), PROGRAM) @@ -83,7 +74,7 @@ define SetupTestFilesCompilationBody $1_OUTPUT_SUBDIR := bin $1_BASE_CFLAGS := $(CFLAGS_JDKEXE) $$(TEST_CFLAGS) $1_BASE_CXXFLAGS := $(CXXFLAGS_JDKEXE) $$(TEST_CFLAGS) - $1_LDFLAGS := $(LDFLAGS_JDKEXE) $$(TEST_LDFLAGS) $(LDFLAGS_TESTEXE) + $1_LDFLAGS := $(LDFLAGS_JDKEXE) $(LDFLAGS_TESTEXE) $1_COMPILATION_TYPE := EXECUTABLE $1_LOG_TYPE := executable else diff --git a/make/common/modules/LauncherCommon.gmk b/make/common/modules/LauncherCommon.gmk index 95d8474f045..1d5dac600fa 100644 --- a/make/common/modules/LauncherCommon.gmk +++ b/make/common/modules/LauncherCommon.gmk @@ -28,19 +28,6 @@ include Modules.gmk include ProcessMarkdown.gmk include ToolsJdk.gmk -# Tell the compiler not to export any functions unless declared so in -# the source code. On Windows, this is the default and cannot be changed. -# On Mac, we have always exported all symbols, probably due to oversight -# and/or misunderstanding. To emulate this, don't hide any symbols -# by default. -# Also provide an override for non-conformant libraries. -ifeq ($(TOOLCHAIN_TYPE), gcc) - LAUNCHER_CFLAGS += -fvisibility=hidden - LDFLAGS_JDKEXE += -Wl,--exclude-libs,ALL -else ifeq ($(TOOLCHAIN_TYPE), clang) - LAUNCHER_CFLAGS += -fvisibility=hidden -endif - LAUNCHER_SRC := $(TOPDIR)/src/java.base/share/native/launcher LAUNCHER_CFLAGS += -I$(TOPDIR)/src/java.base/share/native/launcher \ -I$(TOPDIR)/src/java.base/share/native/libjli \ diff --git a/make/common/modules/LibCommon.gmk b/make/common/modules/LibCommon.gmk index 67d0ff1435f..bb23ca125f6 100644 --- a/make/common/modules/LibCommon.gmk +++ b/make/common/modules/LibCommon.gmk @@ -31,21 +31,6 @@ include JdkNativeCompilation.gmk # elegant solution to this. WIN_JAVA_LIB := $(SUPPORT_OUTPUTDIR)/native/java.base/libjava/java.lib -# Tell the compiler not to export any functions unless declared so in -# the source code. On Windows, this is the default and cannot be changed. -# On Mac, we have always exported all symbols, probably due to oversight -# and/or misunderstanding. To emulate this, don't hide any symbols -# by default. -# Also provide an override for non-conformant libraries. -ifeq ($(TOOLCHAIN_TYPE), gcc) - CFLAGS_JDKLIB += -fvisibility=hidden - CXXFLAGS_JDKLIB += -fvisibility=hidden - LDFLAGS_JDKLIB += -Wl,--exclude-libs,ALL -else ifeq ($(TOOLCHAIN_TYPE), clang) - CFLAGS_JDKLIB += -fvisibility=hidden - CXXFLAGS_JDKLIB += -fvisibility=hidden -endif - # Put the libraries here. INSTALL_LIBRARIES_HERE := $(call FindLibDirForModule, $(MODULE)) diff --git a/make/hotspot/lib/CompileJvm.gmk b/make/hotspot/lib/CompileJvm.gmk index 859e75cfc9f..fb7fe9b0eee 100644 --- a/make/hotspot/lib/CompileJvm.gmk +++ b/make/hotspot/lib/CompileJvm.gmk @@ -155,7 +155,7 @@ endif ifeq ($(call isTargetOs, linux), true) HOTSPOT_VERSION_SCRIPT := $(TOPDIR)/make/data/hotspot-symbols/version-script.txt - JVM_LDFLAGS += -Wl,--exclude-libs,ALL -Wl,-version-script=$(HOTSPOT_VERSION_SCRIPT) + JVM_LDFLAGS += -Wl,-version-script=$(HOTSPOT_VERSION_SCRIPT) endif ################################################################################