1 # 2 # Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 # 5 # This code is free software; you can redistribute it and/or modify it 6 # under the terms of the GNU General Public License version 2 only, as 7 # published by the Free Software Foundation. Oracle designates this 8 # particular file as subject to the "Classpath" exception as provided 9 # by Oracle in the LICENSE file that accompanied this code. 10 # 11 # This code is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 # version 2 for more details (a copy is included in the LICENSE file that 15 # accompanied this code). 16 # 17 # You should have received a copy of the GNU General Public License version 18 # 2 along with this work; if not, write to the Free Software Foundation, 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 # or visit www.oracle.com if you need additional information or have any 23 # questions. 24 # 25 26 ################################################################################ 27 # 28 29 AC_DEFUN([FLAGS_SETUP_LDFLAGS], 30 [ 31 FLAGS_SETUP_LDFLAGS_HELPER 32 33 # Setup the target toolchain 34 35 # On some platforms (mac) the linker warns about non existing -L dirs. 36 # For any of the variants server, client or minimal, the dir matches the 37 # variant name. The "main" variant should be used for linking. For the 38 # rest, the dir is just server. 39 if HOTSPOT_CHECK_JVM_VARIANT(server) || HOTSPOT_CHECK_JVM_VARIANT(client) \ 40 || HOTSPOT_CHECK_JVM_VARIANT(minimal); then 41 TARGET_JVM_VARIANT_PATH=$JVM_VARIANT_MAIN 42 else 43 TARGET_JVM_VARIANT_PATH=server 44 fi 45 FLAGS_SETUP_LDFLAGS_CPU_DEP([TARGET]) 46 47 # Setup the build toolchain 48 49 # When building a buildjdk, it's always only the server variant 50 BUILD_JVM_VARIANT_PATH=server 51 52 FLAGS_SETUP_LDFLAGS_CPU_DEP([BUILD], [OPENJDK_BUILD_]) 53 54 LDFLAGS_TESTEXE="${TARGET_LDFLAGS_JDK_LIBPATH}" 55 AC_SUBST(LDFLAGS_TESTEXE) 56 ]) 57 58 ################################################################################ 59 60 # CPU independent LDFLAGS setup, used for both target and build toolchain. 61 AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER], 62 [ 63 # Setup basic LDFLAGS 64 if test "x$TOOLCHAIN_TYPE" = xgcc; then 65 # If this is a --hash-style=gnu system, use --hash-style=both, why? 66 # We have previously set HAS_GNU_HASH if this is the case 67 if test -n "$HAS_GNU_HASH"; then 68 BASIC_LDFLAGS="-Wl,--hash-style=both" 69 LIBJSIG_HASHSTYLE_LDFLAGS="-Wl,--hash-style=both" 70 fi 71 72 # Add -z,defs, to forbid undefined symbols in object files. 73 # add -z,relro (mark relocations read only) for all libs 74 # add -z,now ("full relro" - more of the Global Offset Table GOT is marked read only) 75 BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,-z,defs -Wl,-z,relro -Wl,-z,now" 76 # Linux : remove unused code+data in link step 77 if test "x$ENABLE_LINKTIME_GC" = xtrue; then 78 if test "x$OPENJDK_TARGET_CPU" = xs390x; then 79 BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,--gc-sections -Wl,--print-gc-sections" 80 else 81 BASIC_LDFLAGS_JDK_ONLY="$BASIC_LDFLAGS_JDK_ONLY -Wl,--gc-sections" 82 fi 83 fi 84 85 BASIC_LDFLAGS_JVM_ONLY="-Wl,-O1" 86 87 elif test "x$TOOLCHAIN_TYPE" = xclang; then 88 BASIC_LDFLAGS_JVM_ONLY="-mno-omit-leaf-frame-pointer -mstack-alignment=16 \ 89 -fPIC" 90 91 elif test "x$TOOLCHAIN_TYPE" = xxlc; then 92 BASIC_LDFLAGS="-b64 -brtl -bnorwexec -bnolibpath -bexpall -bernotok -btextpsize:64K \ 93 -bdatapsize:64K -bstackpsize:64K" 94 # libjvm.so has gotten too large for normal TOC size; compile with qpic=large and link with bigtoc 95 BASIC_LDFLAGS_JVM_ONLY="-Wl,-lC_r -bbigtoc" 96 97 elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 98 BASIC_LDFLAGS="-nologo -opt:ref" 99 BASIC_LDFLAGS_JDK_ONLY="-incremental:no" 100 BASIC_LDFLAGS_JVM_ONLY="-opt:icf,8 -subsystem:windows" 101 fi 102 103 if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then 104 if test -n "$HAS_NOEXECSTACK"; then 105 BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,-z,noexecstack" 106 fi 107 fi 108 109 # Setup OS-dependent LDFLAGS 110 if test "x$TOOLCHAIN_TYPE" = xclang || test "x$TOOLCHAIN_TYPE" = xgcc; then 111 if test "x$OPENJDK_TARGET_OS" = xmacosx; then 112 # Assume clang or gcc. 113 # FIXME: We should really generalize SET_SHARED_LIBRARY_ORIGIN instead. 114 OS_LDFLAGS_JVM_ONLY="-Wl,-rpath,@loader_path/. -Wl,-rpath,@loader_path/.." 115 OS_LDFLAGS_JDK_ONLY="-mmacosx-version-min=$MACOSX_VERSION_MIN" 116 fi 117 fi 118 119 # Setup debug level-dependent LDFLAGS 120 if test "x$TOOLCHAIN_TYPE" = xgcc; then 121 if test "x$OPENJDK_TARGET_OS" = xlinux; then 122 if test x$DEBUG_LEVEL = xrelease; then 123 DEBUGLEVEL_LDFLAGS_JDK_ONLY="$DEBUGLEVEL_LDFLAGS_JDK_ONLY -Wl,-O1" 124 fi 125 fi 126 127 elif test "x$TOOLCHAIN_TYPE" = xxlc; then 128 # We need '-qminimaltoc' or '-qpic=large -bbigtoc' if the TOC overflows. 129 # Hotspot now overflows its 64K TOC (currently only for debug), 130 # so we build with '-qpic=large -bbigtoc'. 131 if test "x$DEBUG_LEVEL" != xrelease; then 132 DEBUGLEVEL_LDFLAGS_JVM_ONLY="$DEBUGLEVEL_LDFLAGS_JVM_ONLY -bbigtoc" 133 fi 134 fi 135 136 # Setup LDFLAGS for linking executables 137 if test "x$TOOLCHAIN_TYPE" = xgcc; then 138 EXECUTABLE_LDFLAGS="$EXECUTABLE_LDFLAGS -Wl,--allow-shlib-undefined" 139 # Enabling pie on 32 bit builds prevents the JVM from allocating a continuous 140 # java heap. 141 if test "x$OPENJDK_TARGET_CPU_BITS" != "x32"; then 142 EXECUTABLE_LDFLAGS="$EXECUTABLE_LDFLAGS -pie" 143 fi 144 fi 145 146 if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then 147 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 148 BASIC_LDFLAGS="$BASIC_LDFLAGS -pdbaltpath:%_PDB%" 149 fi 150 fi 151 152 # Export some intermediate variables for compatibility 153 LDFLAGS_CXX_JDK="$BASIC_LDFLAGS_ONLYCXX $BASIC_LDFLAGS_ONLYCXX_JDK_ONLY $DEBUGLEVEL_LDFLAGS_JDK_ONLY" 154 AC_SUBST(LDFLAGS_CXX_JDK) 155 AC_SUBST(LIBJSIG_HASHSTYLE_LDFLAGS) 156 AC_SUBST(LIBJSIG_NOEXECSTACK_LDFLAGS) 157 ]) 158 159 ################################################################################ 160 # $1 - Either BUILD or TARGET to pick the correct OS/CPU variables to check 161 # conditionals against. 162 # $2 - Optional prefix for each variable defined. 163 AC_DEFUN([FLAGS_SETUP_LDFLAGS_CPU_DEP], 164 [ 165 # Setup CPU-dependent basic LDFLAGS. These can differ between the target and 166 # build toolchain. 167 if test "x$TOOLCHAIN_TYPE" = xgcc; then 168 if test "x${OPENJDK_$1_CPU}" = xx86; then 169 $1_CPU_LDFLAGS_JVM_ONLY="-march=i586" 170 elif test "x$OPENJDK_$1_CPU" = xarm; then 171 $1_CPU_LDFLAGS_JVM_ONLY="${$1_CPU_LDFLAGS_JVM_ONLY} -fsigned-char" 172 $1_CPU_LDFLAGS="$ARM_ARCH_TYPE_FLAGS $ARM_FLOAT_TYPE_FLAGS" 173 fi 174 175 elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 176 if test "x${OPENJDK_$1_CPU}" = "xx86"; then 177 $1_CPU_LDFLAGS="-safeseh" 178 # NOTE: Old build added -machine. Probably not needed. 179 $1_CPU_LDFLAGS_JVM_ONLY="-machine:I386" 180 $1_CPU_EXECUTABLE_LDFLAGS="-stack:327680" 181 else 182 $1_CPU_LDFLAGS_JVM_ONLY="-machine:AMD64" 183 $1_CPU_EXECUTABLE_LDFLAGS="-stack:1048576" 184 fi 185 fi 186 187 # JVM_VARIANT_PATH depends on if this is build or target... 188 if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then 189 $1_LDFLAGS_JDK_LIBPATH="-libpath:${OUTPUTDIR}/support/modules_libs/java.base" 190 else 191 $1_LDFLAGS_JDK_LIBPATH="-L\$(SUPPORT_OUTPUTDIR)/modules_libs/java.base \ 192 -L\$(SUPPORT_OUTPUTDIR)/modules_libs/java.base/${$1_JVM_VARIANT_PATH}" 193 fi 194 195 # Export variables according to old definitions, prefix with $2 if present. 196 LDFLAGS_JDK_COMMON="$BASIC_LDFLAGS $BASIC_LDFLAGS_JDK_ONLY \ 197 $OS_LDFLAGS_JDK_ONLY $DEBUGLEVEL_LDFLAGS_JDK_ONLY ${$2EXTRA_LDFLAGS}" 198 $2LDFLAGS_JDKLIB="$LDFLAGS_JDK_COMMON $BASIC_LDFLAGS_JDK_LIB_ONLY \ 199 ${$1_LDFLAGS_JDK_LIBPATH} $SHARED_LIBRARY_FLAGS" 200 $2LDFLAGS_JDKEXE="$LDFLAGS_JDK_COMMON $EXECUTABLE_LDFLAGS \ 201 ${$1_CPU_EXECUTABLE_LDFLAGS}" 202 203 $2JVM_LDFLAGS="$BASIC_LDFLAGS $BASIC_LDFLAGS_JVM_ONLY $OS_LDFLAGS_JVM_ONLY \ 204 $DEBUGLEVEL_LDFLAGS $DEBUGLEVEL_LDFLAGS_JVM_ONLY $BASIC_LDFLAGS_ONLYCXX \ 205 ${$1_CPU_LDFLAGS} ${$1_CPU_LDFLAGS_JVM_ONLY} ${$2EXTRA_LDFLAGS}" 206 207 AC_SUBST($2LDFLAGS_JDKLIB) 208 AC_SUBST($2LDFLAGS_JDKEXE) 209 210 AC_SUBST($2JVM_LDFLAGS) 211 ])