jdk

Форк
0
/
flags-ldflags.m4 
205 строк · 7.8 Кб
1
#
2
# Copyright (c) 2011, 2024, 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
  FLAGS_SETUP_LDFLAGS_CPU_DEP([TARGET])
35

36
  # Setup the build toolchain
37
  FLAGS_SETUP_LDFLAGS_CPU_DEP([BUILD], [OPENJDK_BUILD_])
38

39
  AC_SUBST(ADLC_LDFLAGS)
40
])
41

42
################################################################################
43

44
# CPU independent LDFLAGS setup, used for both target and build toolchain.
45
AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER],
46
[
47
  # Setup basic LDFLAGS
48
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
49
    # Add -z,defs, to forbid undefined symbols in object files.
50
    # add -z,relro (mark relocations read only) for all libs
51
    # add -z,now ("full relro" - more of the Global Offset Table GOT is marked read only)
52
    # add --no-as-needed to disable default --as-needed link flag on some GCC toolchains
53
    BASIC_LDFLAGS="-Wl,-z,defs -Wl,-z,relro -Wl,-z,now -Wl,--no-as-needed -Wl,--exclude-libs,ALL"
54
    # Linux : remove unused code+data in link step
55
    if test "x$ENABLE_LINKTIME_GC" = xtrue; then
56
      if test "x$OPENJDK_TARGET_CPU" = xs390x; then
57
        BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,--gc-sections"
58
      else
59
        BASIC_LDFLAGS_JDK_ONLY="$BASIC_LDFLAGS_JDK_ONLY -Wl,--gc-sections"
60
      fi
61
    fi
62

63
    BASIC_LDFLAGS_JVM_ONLY=""
64

65
    LDFLAGS_CXX_PARTIAL_LINKING="$MACHINE_FLAG -r"
66

67
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
68
    BASIC_LDFLAGS_JVM_ONLY="-mno-omit-leaf-frame-pointer -mstack-alignment=16 \
69
        -fPIC"
70

71
    LDFLAGS_CXX_PARTIAL_LINKING="$MACHINE_FLAG -r"
72

73
    if test "x$OPENJDK_TARGET_OS" = xlinux; then
74
      BASIC_LDFLAGS="-fuse-ld=lld -Wl,--exclude-libs,ALL"
75
    fi
76
    if test "x$OPENJDK_TARGET_OS" = xaix; then
77
      BASIC_LDFLAGS="-Wl,-b64 -Wl,-brtl -Wl,-bnorwexec -Wl,-bnolibpath -Wl,-bnoexpall \
78
        -Wl,-bernotok -Wl,-bdatapsize:64k -Wl,-btextpsize:64k -Wl,-bstackpsize:64k"
79
      BASIC_LDFLAGS_JVM_ONLY="$BASIC_LDFLAGS_JVM_ONLY -Wl,-lC_r -Wl,-bbigtoc"
80
    fi
81

82
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
83
    BASIC_LDFLAGS="-opt:ref"
84
    BASIC_LDFLAGS_JDK_ONLY="-incremental:no"
85
    BASIC_LDFLAGS_JVM_ONLY="-opt:icf,8 -subsystem:windows"
86
  fi
87

88
  if (test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang) \
89
      && test "x$OPENJDK_TARGET_OS" != xaix; then
90
    if test -n "$HAS_NOEXECSTACK"; then
91
      BASIC_LDFLAGS="$BASIC_LDFLAGS -Wl,-z,noexecstack"
92
    fi
93
  fi
94

95
  # Setup OS-dependent LDFLAGS
96
  if test "x$OPENJDK_TARGET_OS" = xmacosx && test "x$TOOLCHAIN_TYPE" = xclang; then
97
    # FIXME: We should really generalize SET_SHARED_LIBRARY_ORIGIN instead.
98
    OS_LDFLAGS_JVM_ONLY="-Wl,-rpath,@loader_path/. -Wl,-rpath,@loader_path/.."
99
    OS_LDFLAGS="-mmacosx-version-min=$MACOSX_VERSION_MIN"
100
  fi
101

102
  # Setup debug level-dependent LDFLAGS
103
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
104
    if test "x$OPENJDK_TARGET_OS" = xlinux; then
105
      if test x$DEBUG_LEVEL = xrelease; then
106
        DEBUGLEVEL_LDFLAGS_JDK_ONLY="$DEBUGLEVEL_LDFLAGS_JDK_ONLY -Wl,-O1"
107
      fi
108
    fi
109

110
  elif test "x$TOOLCHAIN_TYPE" = xclang && test "x$OPENJDK_TARGET_OS" = xaix; then
111
    # We need '-fpic' or '-fpic -mcmodel=large -Wl,-bbigtoc' if the TOC overflows.
112
    # Hotspot now overflows its 64K TOC (currently only for debug),
113
    # so we build with '-fpic -mcmodel=large -Wl,-bbigtoc'.
114
    if test "x$DEBUG_LEVEL" != xrelease; then
115
      DEBUGLEVEL_LDFLAGS_JVM_ONLY="$DEBUGLEVEL_LDFLAGS_JVM_ONLY -Wl,-bbigtoc"
116
    fi
117
  fi
118

119
  # Setup LDFLAGS for linking executables
120
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
121
    # Enabling pie on 32 bit builds prevents the JVM from allocating a continuous
122
    # java heap.
123
    if test "x$OPENJDK_TARGET_CPU_BITS" != "x32"; then
124
      EXECUTABLE_LDFLAGS="$EXECUTABLE_LDFLAGS -pie"
125
    fi
126
  fi
127

128
  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
129
    REPRODUCIBLE_LDFLAGS="-experimental:deterministic"
130
    FLAGS_LINKER_CHECK_ARGUMENTS(ARGUMENT: [$REPRODUCIBLE_LDFLAGS],
131
        IF_FALSE: [
132
            REPRODUCIBLE_LDFLAGS=
133
        ]
134
    )
135
  fi
136

137
  if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
138
    if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
139
      BASIC_LDFLAGS="$BASIC_LDFLAGS -pdbaltpath:%_PDB%"
140
      # PATHMAP_FLAGS is setup in flags-cflags.m4.
141
      FILE_MACRO_LDFLAGS="${PATHMAP_FLAGS}"
142
    fi
143
  fi
144

145
  # Export some intermediate variables for compatibility
146
  LDFLAGS_CXX_JDK="$DEBUGLEVEL_LDFLAGS_JDK_ONLY"
147
  AC_SUBST(LDFLAGS_CXX_JDK)
148
  AC_SUBST(LDFLAGS_CXX_PARTIAL_LINKING)
149
])
150

151
################################################################################
152
# $1 - Either BUILD or TARGET to pick the correct OS/CPU variables to check
153
#      conditionals against.
154
# $2 - Optional prefix for each variable defined.
155
AC_DEFUN([FLAGS_SETUP_LDFLAGS_CPU_DEP],
156
[
157
  # Setup CPU-dependent basic LDFLAGS. These can differ between the target and
158
  # build toolchain.
159
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
160
    if test "x${OPENJDK_$1_CPU}" = xx86; then
161
      $1_CPU_LDFLAGS_JVM_ONLY="-march=i586"
162
    elif test "x$OPENJDK_$1_CPU" = xarm; then
163
      $1_CPU_LDFLAGS_JVM_ONLY="${$1_CPU_LDFLAGS_JVM_ONLY} -fsigned-char"
164
      $1_CPU_LDFLAGS="$ARM_ARCH_TYPE_FLAGS $ARM_FLOAT_TYPE_FLAGS"
165
    fi
166

167
    # MIPS ABI does not support GNU hash style
168
    if test "x${OPENJDK_$1_CPU}" = xmips ||
169
       test "x${OPENJDK_$1_CPU}" = xmipsel ||
170
       test "x${OPENJDK_$1_CPU}" = xmips64 ||
171
       test "x${OPENJDK_$1_CPU}" = xmips64el; then
172
      $1_CPU_LDFLAGS="${$1_CPU_LDFLAGS} -Wl,--hash-style=sysv"
173
    else
174
      $1_CPU_LDFLAGS="${$1_CPU_LDFLAGS} -Wl,--hash-style=gnu"
175
    fi
176

177
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
178
    if test "x${OPENJDK_$1_CPU_BITS}" = "x32"; then
179
      $1_CPU_EXECUTABLE_LDFLAGS="-stack:327680"
180
    elif test "x${OPENJDK_$1_CPU_BITS}" = "x64"; then
181
      $1_CPU_EXECUTABLE_LDFLAGS="-stack:1048576"
182
    fi
183
    if test "x${OPENJDK_$1_CPU}" = "xx86"; then
184
      $1_CPU_LDFLAGS="-safeseh"
185
    fi
186
  fi
187

188
  # Export variables according to old definitions, prefix with $2 if present.
189
  LDFLAGS_JDK_COMMON="$BASIC_LDFLAGS $BASIC_LDFLAGS_JDK_ONLY \
190
      $OS_LDFLAGS $DEBUGLEVEL_LDFLAGS_JDK_ONLY ${$2EXTRA_LDFLAGS}"
191
  $2LDFLAGS_JDKLIB="$LDFLAGS_JDK_COMMON $BASIC_LDFLAGS_JDK_LIB_ONLY \
192
      $SHARED_LIBRARY_FLAGS $REPRODUCIBLE_LDFLAGS $FILE_MACRO_LDFLAGS"
193
  $2LDFLAGS_JDKEXE="$LDFLAGS_JDK_COMMON $EXECUTABLE_LDFLAGS \
194
      ${$1_CPU_EXECUTABLE_LDFLAGS} $REPRODUCIBLE_LDFLAGS $FILE_MACRO_LDFLAGS"
195

196
  $2JVM_LDFLAGS="$BASIC_LDFLAGS $BASIC_LDFLAGS_JVM_ONLY $OS_LDFLAGS $OS_LDFLAGS_JVM_ONLY \
197
      $DEBUGLEVEL_LDFLAGS $DEBUGLEVEL_LDFLAGS_JVM_ONLY $BASIC_LDFLAGS_ONLYCXX \
198
      ${$1_CPU_LDFLAGS} ${$1_CPU_LDFLAGS_JVM_ONLY} ${$2EXTRA_LDFLAGS} \
199
      $REPRODUCIBLE_LDFLAGS $FILE_MACRO_LDFLAGS"
200

201
  AC_SUBST($2LDFLAGS_JDKLIB)
202
  AC_SUBST($2LDFLAGS_JDKEXE)
203

204
  AC_SUBST($2JVM_LDFLAGS)
205
])
206

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.