Skip to content

Commit

Permalink
8327045: Consolidate -fvisibility=hidden as a basic flag for all comp…
Browse files Browse the repository at this point in the history
…ilation

Reviewed-by: erikj
  • Loading branch information
magicus committed Mar 14, 2024
1 parent fcf746d commit 44aef38
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 42 deletions.
3 changes: 2 additions & 1 deletion make/autoconf/flags-cflags.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion make/autoconf/flags-ldflags.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
13 changes: 2 additions & 11 deletions make/common/TestFilesCompilation.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,22 @@ 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)
$1_PREFIX = lib
$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)
$1_PREFIX = exe
$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
Expand Down
13 changes: 0 additions & 13 deletions make/common/modules/LauncherCommon.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
15 changes: 0 additions & 15 deletions make/common/modules/LibCommon.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion make/hotspot/lib/CompileJvm.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -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

################################################################################
Expand Down

0 comments on commit 44aef38

Please sign in to comment.