jdk

Форк
0
/
flags-cflags.m4 
946 строк · 36.3 Кб
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
# Setup flags for C/C++ compiler
29
#
30

31
################################################################################
32
#
33
# How to compile shared libraries.
34
#
35
AC_DEFUN([FLAGS_SETUP_SHARED_LIBS],
36
[
37
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
38
    # Default works for linux, might work on other platforms as well.
39
    SHARED_LIBRARY_FLAGS='-shared'
40
    # --disable-new-dtags forces use of RPATH instead of RUNPATH for rpaths.
41
    # This protects internal library dependencies within the JDK from being
42
    # overridden using LD_LIBRARY_PATH. See JDK-8326891 for more information.
43
    SET_EXECUTABLE_ORIGIN='-Wl,-rpath,\$$ORIGIN[$]1 -Wl,--disable-new-dtags'
44
    SET_SHARED_LIBRARY_ORIGIN="-Wl,-z,origin $SET_EXECUTABLE_ORIGIN"
45
    SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
46

47
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
48
    if test "x$OPENJDK_TARGET_OS" = xmacosx; then
49
      # Linking is different on MacOSX
50
      SHARED_LIBRARY_FLAGS="-dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0"
51
      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,@loader_path$(or [$]1,/.)'
52
      SET_SHARED_LIBRARY_ORIGIN="$SET_EXECUTABLE_ORIGIN"
53
      SET_SHARED_LIBRARY_NAME='-Wl,-install_name,@rpath/[$]1'
54

55
    elif test "x$OPENJDK_TARGET_OS" = xaix; then
56
      # Linking is different on aix
57
      SHARED_LIBRARY_FLAGS="-shared -Wl,-bM:SRE -Wl,-bnoentry"
58
      SET_EXECUTABLE_ORIGIN=""
59
      SET_SHARED_LIBRARY_ORIGIN=''
60
      SET_SHARED_LIBRARY_NAME=''
61

62
    else
63
      # Default works for linux, might work on other platforms as well.
64
      SHARED_LIBRARY_FLAGS='-shared'
65
      SET_EXECUTABLE_ORIGIN='-Wl,-rpath,\$$ORIGIN[$]1'
66
      if test "x$OPENJDK_TARGET_OS" = xlinux; then
67
        SET_EXECUTABLE_ORIGIN="$SET_EXECUTABLE_ORIGIN -Wl,--disable-new-dtags"
68
      fi
69
      SET_SHARED_LIBRARY_NAME='-Wl,-soname=[$]1'
70

71
      # arm specific settings
72
      if test "x$OPENJDK_TARGET_CPU" = "xarm"; then
73
        # '-Wl,-z,origin' isn't used on arm.
74
        SET_SHARED_LIBRARY_ORIGIN='-Wl,-rpath,\$$$$ORIGIN[$]1'
75
      else
76
        SET_SHARED_LIBRARY_ORIGIN="-Wl,-z,origin $SET_EXECUTABLE_ORIGIN"
77
      fi
78
    fi
79

80
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
81
    SHARED_LIBRARY_FLAGS="-dll"
82
    SET_EXECUTABLE_ORIGIN=''
83
    SET_SHARED_LIBRARY_ORIGIN=''
84
    SET_SHARED_LIBRARY_NAME=''
85
  fi
86

87
  AC_SUBST(SET_EXECUTABLE_ORIGIN)
88
  AC_SUBST(SET_SHARED_LIBRARY_ORIGIN)
89
  AC_SUBST(SET_SHARED_LIBRARY_NAME)
90
  AC_SUBST(SHARED_LIBRARY_FLAGS)
91
])
92

93
AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS],
94
[
95
  # By default don't set any specific assembler debug
96
  # info flags for toolchains unless we know they work.
97
  # See JDK-8207057.
98
  ASFLAGS_DEBUG_SYMBOLS=""
99

100
  # Debug prefix mapping if supported by compiler
101
  DEBUG_PREFIX_CFLAGS=
102

103
  # Debug symbols
104
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
105
    if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
106
      # Check if compiler supports -fdebug-prefix-map. If so, use that to make
107
      # the debug symbol paths resolve to paths relative to the workspace root.
108
      workspace_root_trailing_slash="${WORKSPACE_ROOT%/}/"
109
      DEBUG_PREFIX_CFLAGS="-fdebug-prefix-map=${workspace_root_trailing_slash}="
110
      FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${DEBUG_PREFIX_CFLAGS}],
111
        IF_FALSE: [
112
            DEBUG_PREFIX_CFLAGS=
113
        ],
114
        IF_TRUE: [
115
            # Add debug prefix map gcc system include paths, as they cause
116
            # non-deterministic debug paths depending on gcc path location.
117
            DEBUG_PREFIX_MAP_GCC_INCLUDE_PATHS
118

119
            # Add debug prefix map for OUTPUTDIR to handle the scenario when
120
            # it is not located within WORKSPACE_ROOT
121
            outputdir_slash="${OUTPUTDIR%/}/"
122
            DEBUG_PREFIX_CFLAGS="$DEBUG_PREFIX_CFLAGS -fdebug-prefix-map=${outputdir_slash}="
123
        ]
124
      )
125
    fi
126

127
    CFLAGS_DEBUG_SYMBOLS="-g -gdwarf-4"
128
    ASFLAGS_DEBUG_SYMBOLS="-g"
129
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
130
    if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
131
      # Check if compiler supports -fdebug-prefix-map. If so, use that to make
132
      # the debug symbol paths resolve to paths relative to the workspace root.
133
      workspace_root_trailing_slash="${WORKSPACE_ROOT%/}/"
134
      DEBUG_PREFIX_CFLAGS="-fdebug-prefix-map=${workspace_root_trailing_slash}="
135
      FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${DEBUG_PREFIX_CFLAGS}],
136
        IF_FALSE: [
137
            DEBUG_PREFIX_CFLAGS=
138
        ]
139
      )
140
    fi
141

142
    # -gdwarf-4 and -gdwarf-aranges were introduced in clang 5.0
143
    GDWARF_FLAGS="-gdwarf-4 -gdwarf-aranges"
144
    FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${GDWARF_FLAGS}],
145
        IF_FALSE: [GDWARF_FLAGS=""])
146

147
    CFLAGS_DEBUG_SYMBOLS="-g ${GDWARF_FLAGS}"
148
    ASFLAGS_DEBUG_SYMBOLS="-g"
149
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
150
    CFLAGS_DEBUG_SYMBOLS="-Z7"
151
  fi
152

153
  if test "x$DEBUG_PREFIX_CFLAGS" != x; then
154
    CFLAGS_DEBUG_SYMBOLS="$CFLAGS_DEBUG_SYMBOLS $DEBUG_PREFIX_CFLAGS"
155
    ASFLAGS_DEBUG_SYMBOLS="$ASFLAGS_DEBUG_SYMBOLS $DEBUG_PREFIX_CFLAGS"
156
  fi
157

158
  AC_SUBST(CFLAGS_DEBUG_SYMBOLS)
159
  AC_SUBST(ASFLAGS_DEBUG_SYMBOLS)
160
])
161

162
# gcc will embed the full system include paths in the debug info
163
# resulting in non-deterministic debug symbol files and thus
164
# non-reproducible native libraries if gcc includes are located
165
# in different paths.
166
# Add -fdebug-prefix-map'ings for root and gcc include paths,
167
# pointing to a common set of folders so that the binaries are deterministic:
168
#  root include : /usr/include
169
#  gcc include  : /usr/local/gcc_include
170
#  g++ include  : /usr/local/gxx_include
171
AC_DEFUN([DEBUG_PREFIX_MAP_GCC_INCLUDE_PATHS],
172
[
173
    # Determine gcc system include paths.
174
    # Assume default roots to start with:
175
    GCC_ROOT_INCLUDE="/usr/include"
176

177
    # Determine is sysroot or devkit specified?
178
    if test "x$SYSROOT" != "x"; then
179
      GCC_ROOT_INCLUDE="${SYSROOT%/}/usr/include"
180
    fi
181

182
    # Add root include mapping => /usr/include
183
    GCC_INCLUDE_DEBUG_MAP_FLAGS="-fdebug-prefix-map=${GCC_ROOT_INCLUDE}/=/usr/include/"
184

185
    # Add gcc system include mapping => /usr/local/gcc_include
186
    #   Find location of stddef.h using build C compiler
187
    GCC_SYSTEM_INCLUDE=`$ECHO "#include <stddef.h>" | \
188
                        $CC $CFLAGS -v -E - 2>&1 | \
189
                        $GREP stddef | $TAIL -1 | $TR -s " " | $CUT -d'"' -f2`
190
    if test "x$GCC_SYSTEM_INCLUDE" != "x"; then
191
      GCC_SYSTEM_INCLUDE=`$DIRNAME $GCC_SYSTEM_INCLUDE`
192
      GCC_INCLUDE_DEBUG_MAP_FLAGS="$GCC_INCLUDE_DEBUG_MAP_FLAGS \
193
          -fdebug-prefix-map=${GCC_SYSTEM_INCLUDE}/=/usr/local/gcc_include/"
194
    fi
195

196
    # Add g++ system include mapping => /usr/local/gxx_include
197
    #   Find location of cstddef using build C++ compiler
198
    GXX_SYSTEM_INCLUDE=`$ECHO "#include <cstddef>" | \
199
                        $CXX $CXXFLAGS -v -E -x c++ - 2>&1 | \
200
                        $GREP cstddef | $TAIL -1 | $TR -s " " | $CUT -d'"' -f2`
201
    if test "x$GXX_SYSTEM_INCLUDE" != "x"; then
202
      GXX_SYSTEM_INCLUDE=`$DIRNAME $GXX_SYSTEM_INCLUDE`
203
      GCC_INCLUDE_DEBUG_MAP_FLAGS="$GCC_INCLUDE_DEBUG_MAP_FLAGS \
204
          -fdebug-prefix-map=${GXX_SYSTEM_INCLUDE}/=/usr/local/gxx_include/"
205
    fi
206

207
    # Add to debug prefix cflags
208
    DEBUG_PREFIX_CFLAGS="$DEBUG_PREFIX_CFLAGS $GCC_INCLUDE_DEBUG_MAP_FLAGS"
209
])
210

211
AC_DEFUN([FLAGS_SETUP_WARNINGS],
212
[
213
  # Set default value.
214
  WARNINGS_AS_ERRORS_DEFAULT=true
215

216
  UTIL_ARG_ENABLE(NAME: warnings-as-errors, DEFAULT: $WARNINGS_AS_ERRORS_DEFAULT,
217
      RESULT: WARNINGS_AS_ERRORS,
218
      DEFAULT_DESC: [auto],
219
      DESC: [consider native warnings to be an error])
220
  AC_SUBST(WARNINGS_AS_ERRORS)
221

222
  case "${TOOLCHAIN_TYPE}" in
223
    microsoft)
224
      DISABLE_WARNING_PREFIX="-wd"
225
      BUILD_CC_DISABLE_WARNING_PREFIX="-wd"
226
      CFLAGS_WARNINGS_ARE_ERRORS="-WX"
227

228
      WARNINGS_ENABLE_ALL="-W3"
229
      DISABLED_WARNINGS="4800 5105"
230
      ;;
231

232
    gcc)
233
      DISABLE_WARNING_PREFIX="-Wno-"
234
      BUILD_CC_DISABLE_WARNING_PREFIX="-Wno-"
235
      CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
236

237
      # Additional warnings that are not activated by -Wall and -Wextra
238
      WARNINGS_ENABLE_ADDITIONAL="-Wpointer-arith -Wsign-compare \
239
          -Wunused-function -Wundef -Wunused-value -Wreturn-type \
240
          -Wtrampolines"
241
      WARNINGS_ENABLE_ADDITIONAL_CXX="-Woverloaded-virtual -Wreorder"
242
      WARNINGS_ENABLE_ALL_CFLAGS="-Wall -Wextra -Wformat=2 $WARNINGS_ENABLE_ADDITIONAL"
243
      WARNINGS_ENABLE_ALL_CXXFLAGS="$WARNINGS_ENABLE_ALL_CFLAGS $WARNINGS_ENABLE_ADDITIONAL_CXX"
244

245
      DISABLED_WARNINGS="unused-parameter unused"
246
      # gcc10/11 on ppc generate lots of abi warnings about layout of aggregates containing vectors
247
      if test "x$OPENJDK_TARGET_CPU_ARCH" = "xppc"; then
248
        DISABLED_WARNINGS="$DISABLED_WARNINGS psabi"
249
      fi
250
      ;;
251

252
    clang)
253
      DISABLE_WARNING_PREFIX="-Wno-"
254
      BUILD_CC_DISABLE_WARNING_PREFIX="-Wno-"
255
      CFLAGS_WARNINGS_ARE_ERRORS="-Werror"
256

257
      # Additional warnings that are not activated by -Wall and -Wextra
258
      WARNINGS_ENABLE_ADDITIONAL="-Wpointer-arith -Wsign-compare -Wreorder \
259
          -Wunused-function -Wundef -Wunused-value -Woverloaded-virtual"
260
      WARNINGS_ENABLE_ALL="-Wall -Wextra -Wformat=2 $WARNINGS_ENABLE_ADDITIONAL"
261

262
      DISABLED_WARNINGS="unknown-warning-option unused-parameter unused"
263
      ;;
264
  esac
265
  AC_SUBST(DISABLE_WARNING_PREFIX)
266
  AC_SUBST(BUILD_CC_DISABLE_WARNING_PREFIX)
267
  AC_SUBST(CFLAGS_WARNINGS_ARE_ERRORS)
268
  AC_SUBST(DISABLED_WARNINGS)
269
  AC_SUBST(DISABLED_WARNINGS_C)
270
  AC_SUBST(DISABLED_WARNINGS_CXX)
271
])
272

273
AC_DEFUN([FLAGS_SETUP_QUALITY_CHECKS],
274
[
275
  # bounds, memory and behavior checking options
276
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
277
    case $DEBUG_LEVEL in
278
    release )
279
      # no adjustment
280
      ;;
281
    fastdebug )
282
      # no adjustment
283
      ;;
284
    slowdebug )
285
      # FIXME: By adding this to C(XX)FLAGS_DEBUG_OPTIONS/JVM_CFLAGS_SYMBOLS it
286
      # gets added conditionally on whether we produce debug symbols or not.
287
      # This is most likely not really correct.
288

289
      # Add runtime stack smashing and undefined behavior checks.
290
      CFLAGS_DEBUG_OPTIONS="-fstack-protector-all --param ssp-buffer-size=1"
291
      CXXFLAGS_DEBUG_OPTIONS="-fstack-protector-all --param ssp-buffer-size=1"
292

293
      JVM_CFLAGS_SYMBOLS="$JVM_CFLAGS_SYMBOLS -fstack-protector-all --param ssp-buffer-size=1"
294
      ;;
295
    esac
296
  fi
297
])
298

299
AC_DEFUN([FLAGS_SETUP_OPTIMIZATION],
300
[
301
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
302
    C_O_FLAG_HIGHEST_JVM="-O3"
303
    C_O_FLAG_HIGHEST="-O3"
304
    C_O_FLAG_HI="-O3"
305
    C_O_FLAG_NORM="-O2"
306
    C_O_FLAG_SIZE="-Os"
307
    C_O_FLAG_DEBUG="-O0"
308
    C_O_FLAG_DEBUG_JVM="-O0"
309
    C_O_FLAG_NONE="-O0"
310
    # -D_FORTIFY_SOURCE=2 hardening option needs optimization (at least -O1) enabled
311
    # set for lower O-levels -U_FORTIFY_SOURCE to overwrite previous settings
312
    if test "x$OPENJDK_TARGET_OS" = xlinux -a "x$DEBUG_LEVEL" = "xfastdebug"; then
313
      DISABLE_FORTIFY_CFLAGS="-U_FORTIFY_SOURCE"
314
      # ASan doesn't work well with _FORTIFY_SOURCE
315
      # See https://github.com/google/sanitizers/wiki/AddressSanitizer#faq
316
      if test "x$ASAN_ENABLED" = xyes; then
317
        ENABLE_FORTIFY_CFLAGS="${DISABLE_FORTIFY_CFLAGS}"
318
      else
319
        ENABLE_FORTIFY_CFLAGS="-D_FORTIFY_SOURCE=2"
320
      fi
321
      C_O_FLAG_HIGHEST_JVM="${C_O_FLAG_HIGHEST_JVM} ${ENABLE_FORTIFY_CFLAGS}"
322
      C_O_FLAG_HIGHEST="${C_O_FLAG_HIGHEST} ${ENABLE_FORTIFY_CFLAGS}"
323
      C_O_FLAG_HI="${C_O_FLAG_HI} ${ENABLE_FORTIFY_CFLAGS}"
324
      C_O_FLAG_NORM="${C_O_FLAG_NORM} ${ENABLE_FORTIFY_CFLAGS}"
325
      C_O_FLAG_SIZE="${C_O_FLAG_SIZE} ${DISABLE_FORTIFY_CFLAGS}"
326
      C_O_FLAG_DEBUG="${C_O_FLAG_DEBUG} ${DISABLE_FORTIFY_CFLAGS}"
327
      C_O_FLAG_DEBUG_JVM="${C_O_FLAG_DEBUG_JVM} ${DISABLE_FORTIFY_CFLAGS}"
328
      C_O_FLAG_NONE="${C_O_FLAG_NONE} ${DISABLE_FORTIFY_CFLAGS}"
329
    fi
330
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
331
    if test "x$OPENJDK_TARGET_OS" = xaix; then
332
      C_O_FLAG_HIGHEST_JVM="-O3 -finline-functions"
333
      C_O_FLAG_HIGHEST="-O3 -finline-functions"
334
      C_O_FLAG_HI="-O3 -finline-functions"
335
    else
336
      C_O_FLAG_HIGHEST_JVM="-O3"
337
      C_O_FLAG_HIGHEST="-O3"
338
      C_O_FLAG_HI="-O3"
339
    fi
340
    C_O_FLAG_NORM="-O2"
341
    C_O_FLAG_DEBUG_JVM="-O0"
342
    C_O_FLAG_SIZE="-Os"
343
    C_O_FLAG_DEBUG="-O0"
344
    C_O_FLAG_NONE="-O0"
345
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
346
    C_O_FLAG_HIGHEST_JVM="-O2 -Oy-"
347
    C_O_FLAG_HIGHEST="-O2"
348
    C_O_FLAG_HI="-O1"
349
    C_O_FLAG_NORM="-O1"
350
    C_O_FLAG_DEBUG="-Od"
351
    C_O_FLAG_DEBUG_JVM=""
352
    C_O_FLAG_NONE="-Od"
353
    C_O_FLAG_SIZE="-Os"
354
  fi
355

356
  # Now copy to C++ flags
357
  CXX_O_FLAG_HIGHEST_JVM="$C_O_FLAG_HIGHEST_JVM"
358
  CXX_O_FLAG_HIGHEST="$C_O_FLAG_HIGHEST"
359
  CXX_O_FLAG_HI="$C_O_FLAG_HI"
360
  CXX_O_FLAG_NORM="$C_O_FLAG_NORM"
361
  CXX_O_FLAG_DEBUG="$C_O_FLAG_DEBUG"
362
  CXX_O_FLAG_DEBUG_JVM="$C_O_FLAG_DEBUG_JVM"
363
  CXX_O_FLAG_NONE="$C_O_FLAG_NONE"
364
  CXX_O_FLAG_SIZE="$C_O_FLAG_SIZE"
365

366
  # Adjust optimization flags according to debug level.
367
  case $DEBUG_LEVEL in
368
    release )
369
      # no adjustment
370
      ;;
371
    fastdebug )
372
      # Not quite so much optimization
373
      C_O_FLAG_HI="$C_O_FLAG_NORM"
374
      CXX_O_FLAG_HI="$CXX_O_FLAG_NORM"
375
      ;;
376
    slowdebug )
377
      # Disable optimization
378
      C_O_FLAG_HIGHEST_JVM="$C_O_FLAG_DEBUG_JVM"
379
      C_O_FLAG_HIGHEST="$C_O_FLAG_DEBUG"
380
      C_O_FLAG_HI="$C_O_FLAG_DEBUG"
381
      C_O_FLAG_NORM="$C_O_FLAG_DEBUG"
382
      C_O_FLAG_SIZE="$C_O_FLAG_DEBUG"
383
      CXX_O_FLAG_HIGHEST_JVM="$CXX_O_FLAG_DEBUG_JVM"
384
      CXX_O_FLAG_HIGHEST="$CXX_O_FLAG_DEBUG"
385
      CXX_O_FLAG_HI="$CXX_O_FLAG_DEBUG"
386
      CXX_O_FLAG_NORM="$CXX_O_FLAG_DEBUG"
387
      CXX_O_FLAG_SIZE="$CXX_O_FLAG_DEBUG"
388
      ;;
389
  esac
390

391
  AC_SUBST(C_O_FLAG_HIGHEST_JVM)
392
  AC_SUBST(C_O_FLAG_HIGHEST)
393
  AC_SUBST(C_O_FLAG_HI)
394
  AC_SUBST(C_O_FLAG_NORM)
395
  AC_SUBST(C_O_FLAG_NONE)
396
  AC_SUBST(C_O_FLAG_SIZE)
397
  AC_SUBST(CXX_O_FLAG_HIGHEST_JVM)
398
  AC_SUBST(CXX_O_FLAG_HIGHEST)
399
  AC_SUBST(CXX_O_FLAG_HI)
400
  AC_SUBST(CXX_O_FLAG_NORM)
401
  AC_SUBST(CXX_O_FLAG_NONE)
402
  AC_SUBST(CXX_O_FLAG_SIZE)
403
])
404

405
AC_DEFUN([FLAGS_SETUP_CFLAGS],
406
[
407
  ### CFLAGS
408

409
  FLAGS_SETUP_CFLAGS_HELPER
410

411
  FLAGS_OS=$OPENJDK_TARGET_OS
412
  FLAGS_OS_TYPE=$OPENJDK_TARGET_OS_TYPE
413
  FLAGS_CPU=$OPENJDK_TARGET_CPU
414
  FLAGS_CPU_ARCH=$OPENJDK_TARGET_CPU_ARCH
415
  FLAGS_CPU_BITS=$OPENJDK_TARGET_CPU_BITS
416
  FLAGS_CPU_ENDIAN=$OPENJDK_TARGET_CPU_ENDIAN
417
  FLAGS_CPU_LEGACY=$OPENJDK_TARGET_CPU_LEGACY
418
  FLAGS_CPU_LEGACY_LIB=$OPENJDK_TARGET_CPU_LEGACY_LIB
419

420
  FLAGS_SETUP_CFLAGS_CPU_DEP([TARGET])
421

422
  # Repeat the check for the BUILD_CC and BUILD_CXX. Need to also reset CFLAGS
423
  # since any target specific flags will likely not work with the build compiler.
424
  CC_OLD="$CC"
425
  CXX_OLD="$CXX"
426
  CFLAGS_OLD="$CFLAGS"
427
  CXXFLAGS_OLD="$CXXFLAGS"
428
  CC="$BUILD_CC"
429
  CXX="$BUILD_CXX"
430
  CFLAGS=""
431
  CXXFLAGS=""
432

433
  FLAGS_OS=$OPENJDK_BUILD_OS
434
  FLAGS_OS_TYPE=$OPENJDK_BUILD_OS_TYPE
435
  FLAGS_CPU=$OPENJDK_BUILD_CPU
436
  FLAGS_CPU_ARCH=$OPENJDK_BUILD_CPU_ARCH
437
  FLAGS_CPU_BITS=$OPENJDK_BUILD_CPU_BITS
438
  FLAGS_CPU_ENDIAN=$OPENJDK_BUILD_CPU_ENDIAN
439
  FLAGS_CPU_LEGACY=$OPENJDK_BUILD_CPU_LEGACY
440
  FLAGS_CPU_LEGACY_LIB=$OPENJDK_BUILD_CPU_LEGACY_LIB
441

442
  FLAGS_SETUP_CFLAGS_CPU_DEP([BUILD], [OPENJDK_BUILD_], [BUILD_])
443

444
  CC="$CC_OLD"
445
  CXX="$CXX_OLD"
446
  CFLAGS="$CFLAGS_OLD"
447
  CXXFLAGS="$CXXFLAGS_OLD"
448
])
449

450
################################################################################
451
# platform independent
452
AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
453
[
454
  #### OS DEFINES, these should be independent on toolchain
455
  if test "x$OPENJDK_TARGET_OS" = xlinux; then
456
    CFLAGS_OS_DEF_JVM="-DLINUX -D_FILE_OFFSET_BITS=64"
457
    CFLAGS_OS_DEF_JDK="-D_GNU_SOURCE -D_REENTRANT -D_FILE_OFFSET_BITS=64"
458
  elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
459
    CFLAGS_OS_DEF_JVM="-D_ALLBSD_SOURCE -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE"
460
    CFLAGS_OS_DEF_JDK="-D_ALLBSD_SOURCE -D_DARWIN_UNLIMITED_SELECT"
461
  elif test "x$OPENJDK_TARGET_OS" = xaix; then
462
    CFLAGS_OS_DEF_JVM="-DAIX -D_LARGE_FILES"
463
    CFLAGS_OS_DEF_JDK="-D_LARGE_FILES"
464
  elif test "x$OPENJDK_TARGET_OS" = xbsd; then
465
    CFLAGS_OS_DEF_JDK="-D_ALLBSD_SOURCE"
466
  elif test "x$OPENJDK_TARGET_OS" = xwindows; then
467
    CFLAGS_OS_DEF_JVM="-D_WINDOWS -DWIN32 -D_JNI_IMPLEMENTATION_"
468
  fi
469

470
  CFLAGS_OS_DEF_JDK="$CFLAGS_OS_DEF_JDK -D$OPENJDK_TARGET_OS_UPPERCASE"
471

472
  #### GLOBAL DEFINES
473
  # Set some common defines. These works for all compilers, but assume
474
  # -D is universally accepted.
475

476
  # Always enable optional macros for VM.
477
  ALWAYS_CFLAGS_JVM="-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS"
478

479
  ###############################################################################
480

481
  # Adjust flags according to debug level.
482
  # Setup debug/release defines
483
  if test "x$DEBUG_LEVEL" = xrelease; then
484
    DEBUG_CFLAGS_JDK="-DNDEBUG"
485
  else
486
    DEBUG_CFLAGS_JDK="-DDEBUG"
487

488
    if test "x$TOOLCHAIN_TYPE" = xclang && test "x$OPENJDK_TARGET_OS" = xaix; then
489
      DEBUG_CFLAGS_JVM="-fpic -mcmodel=large"
490
    fi
491
  fi
492

493
  if test "x$DEBUG_LEVEL" != xrelease; then
494
    DEBUG_OPTIONS_FLAGS_JDK="$CFLAGS_DEBUG_OPTIONS"
495
    DEBUG_SYMBOLS_CFLAGS_JDK="$CFLAGS_DEBUG_SYMBOLS"
496
  fi
497

498
  #### TOOLCHAIN DEFINES
499

500
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
501
    ALWAYS_DEFINES_JVM="-D_GNU_SOURCE -D_REENTRANT"
502
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
503
    ALWAYS_DEFINES_JVM="-D_GNU_SOURCE"
504
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
505
    # _WIN32_WINNT=0x0602 means access APIs for Windows 8 and above. See
506
    # https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170
507
    ALWAYS_DEFINES="-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0602 \
508
        -D_CRT_DECLARE_NONSTDC_NAMES -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS"
509
    ALWAYS_DEFINES_JDK="$ALWAYS_DEFINES -DWIN32 -DIAL"
510
    ALWAYS_DEFINES_JVM="$ALWAYS_DEFINES -DNOMINMAX"
511
  fi
512

513
  ###############################################################################
514
  #
515
  #
516
  # CFLAGS BASIC
517
  if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
518
    # COMMON to gcc and clang
519
    TOOLCHAIN_CFLAGS_JVM="-pipe -fno-rtti -fno-exceptions \
520
        -fvisibility=hidden -fno-strict-aliasing -fno-omit-frame-pointer"
521
  fi
522

523
  if test "x$TOOLCHAIN_TYPE" = xclang && test "x$OPENJDK_TARGET_OS" = xaix; then
524
    # clang compiler on aix needs -ffunction-sections
525
    TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -ffunction-sections -ftls-model -fno-math-errno -fstack-protector"
526
    TOOLCHAIN_CFLAGS_JDK="-ffunction-sections -fsigned-char -fstack-protector"
527
  fi
528

529
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
530
    TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -fstack-protector"
531
    TOOLCHAIN_CFLAGS_JDK="-fvisibility=hidden -pipe -fstack-protector"
532
    # reduce lib size on linux in link step, this needs also special compile flags
533
    # do this on s390x also for libjvm (where serviceability agent is not supported)
534
    if test "x$ENABLE_LINKTIME_GC" = xtrue; then
535
      TOOLCHAIN_CFLAGS_JDK="$TOOLCHAIN_CFLAGS_JDK -ffunction-sections -fdata-sections"
536
      if test "x$OPENJDK_TARGET_CPU" = xs390x && test "x$DEBUG_LEVEL" == xrelease; then
537
        TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -ffunction-sections -fdata-sections"
538
      fi
539
    fi
540
    # technically NOT for CXX (but since this gives *worse* performance, use
541
    # no-strict-aliasing everywhere!)
542
    TOOLCHAIN_CFLAGS_JDK_CONLY="-fno-strict-aliasing"
543

544
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
545
    # Restrict the debug information created by Clang to avoid
546
    # too big object files and speed the build up a little bit
547
    # (see http://llvm.org/bugs/show_bug.cgi?id=7554)
548
    TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -flimit-debug-info"
549

550
    # In principle the stack alignment below is cpu- and ABI-dependent and
551
    # should agree with values of StackAlignmentInBytes in various
552
    # src/hotspot/cpu/*/globalDefinitions_*.hpp files, but this value currently
553
    # works for all platforms.
554
    TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -mno-omit-leaf-frame-pointer -mstack-alignment=16"
555

556
    if test "x$OPENJDK_TARGET_OS" = xlinux; then
557
      if test "x$DEBUG_LEVEL" = xrelease; then
558
        # Clang does not inline as much as GCC does for functions with "inline" keyword by default.
559
        # This causes noticeable slowdown in pause time for G1, and possibly in other areas.
560
        # Increasing the inline hint threshold avoids the slowdown for Clang-built JVM.
561
        TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM -mllvm -inlinehint-threshold=100000"
562
      fi
563
      TOOLCHAIN_CFLAGS_JDK="-pipe"
564
      TOOLCHAIN_CFLAGS_JDK_CONLY="-fno-strict-aliasing" # technically NOT for CXX
565
    fi
566
    TOOLCHAIN_CFLAGS_JDK="$TOOLCHAIN_CFLAGS_JDK -fvisibility=hidden"
567

568
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
569
    # The -utf-8 option sets source and execution character sets to UTF-8 to enable correct
570
    # compilation of all source files regardless of the active code page on Windows.
571
    TOOLCHAIN_CFLAGS_JVM="-nologo -MD -Zc:preprocessor -Zc:inline -permissive- -utf-8 -MP"
572
    TOOLCHAIN_CFLAGS_JDK="-nologo -MD -Zc:preprocessor -Zc:inline -permissive- -utf-8 -Zc:wchar_t-"
573
  fi
574

575
  # CFLAGS C language level for JDK sources (hotspot only uses C++)
576
  if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
577
    LANGSTD_CFLAGS="-std=c11"
578
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
579
    LANGSTD_CFLAGS="-std:c11"
580
  fi
581
  TOOLCHAIN_CFLAGS_JDK_CONLY="$LANGSTD_CFLAGS $TOOLCHAIN_CFLAGS_JDK_CONLY"
582

583
  # CXXFLAGS C++ language level for all of JDK, including Hotspot.
584
  if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
585
    LANGSTD_CXXFLAGS="-std=c++14"
586
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
587
    LANGSTD_CXXFLAGS="-std:c++14"
588
  else
589
    AC_MSG_ERROR([Cannot enable C++14 for this toolchain])
590
  fi
591
  TOOLCHAIN_CFLAGS_JDK_CXXONLY="$TOOLCHAIN_CFLAGS_JDK_CXXONLY $LANGSTD_CXXFLAGS"
592
  TOOLCHAIN_CFLAGS_JVM="$TOOLCHAIN_CFLAGS_JVM $LANGSTD_CXXFLAGS"
593
  ADLC_LANGSTD_CXXFLAGS="$LANGSTD_CXXFLAGS"
594

595
  # CFLAGS WARNINGS STUFF
596
  # Set JVM_CFLAGS warning handling
597
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
598
    WARNING_CFLAGS_JDK_CONLY="$WARNINGS_ENABLE_ALL_CFLAGS"
599
    WARNING_CFLAGS_JDK_CXXONLY="$WARNINGS_ENABLE_ALL_CXXFLAGS"
600
    WARNING_CFLAGS_JVM="$WARNINGS_ENABLE_ALL_CXXFLAGS"
601

602
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
603
    WARNING_CFLAGS="$WARNINGS_ENABLE_ALL"
604

605
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
606
    WARNING_CFLAGS="$WARNINGS_ENABLE_ALL"
607

608
  fi
609

610
  # Set some additional per-OS defines.
611

612
  # Additional macosx handling
613
  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
614
    OS_CFLAGS="-DMAC_OS_X_VERSION_MIN_REQUIRED=$MACOSX_VERSION_MIN_NODOTS \
615
        -mmacosx-version-min=$MACOSX_VERSION_MIN"
616

617
    if test -n "$MACOSX_VERSION_MAX"; then
618
        OS_CFLAGS="$OS_CFLAGS \
619
            -DMAC_OS_X_VERSION_MAX_ALLOWED=$MACOSX_VERSION_MAX_NODOTS"
620
    fi
621
  fi
622

623
  OS_CFLAGS="$OS_CFLAGS -DLIBC=$OPENJDK_TARGET_LIBC"
624
  if test "x$OPENJDK_TARGET_LIBC" = xmusl; then
625
    OS_CFLAGS="$OS_CFLAGS -DMUSL_LIBC"
626
  fi
627

628
  # Where does this really belong??
629
  if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
630
    PICFLAG="-fPIC"
631
    PIEFLAG="-fPIE"
632
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
633
    PICFLAG=""
634
  fi
635

636
  if test "x$TOOLCHAIN_TYPE" = xclang && test "x$OPENJDK_TARGET_OS" = xaix; then
637
    JVM_PICFLAG="-fpic -mcmodel=large"
638
  else
639
    JVM_PICFLAG="$PICFLAG"
640
  fi
641
  JDK_PICFLAG="$PICFLAG"
642

643
  if test "x$OPENJDK_TARGET_OS" = xmacosx; then
644
    # Linking is different on macOS
645
    JVM_PICFLAG=""
646
  fi
647

648
  # Extra flags needed when building optional static versions of certain
649
  # JDK libraries.
650
  STATIC_LIBS_CFLAGS="-DSTATIC_BUILD=1"
651
  if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
652
    STATIC_LIBS_CFLAGS="$STATIC_LIBS_CFLAGS -ffunction-sections -fdata-sections \
653
      -DJNIEXPORT='__attribute__((visibility(\"default\")))'"
654
  else
655
    STATIC_LIBS_CFLAGS="$STATIC_LIBS_CFLAGS -DJNIEXPORT="
656
  fi
657
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
658
    # Disable relax-relocation to enable compatibility with older linkers
659
    RELAX_RELOCATIONS_FLAG="-Xassembler -mrelax-relocations=no"
660
    FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${RELAX_RELOCATIONS_FLAG}],
661
        IF_TRUE: [STATIC_LIBS_CFLAGS="$STATIC_LIBS_CFLAGS ${RELAX_RELOCATIONS_FLAG}"])
662
  fi
663
  AC_SUBST(STATIC_LIBS_CFLAGS)
664
])
665

666
################################################################################
667
# $1 - Either BUILD or TARGET to pick the correct OS/CPU variables to check
668
#      conditionals against.
669
# $2 - Optional prefix for each variable defined.
670
# $3 - Optional prefix for compiler variables (either BUILD_ or nothing).
671
AC_DEFUN([FLAGS_SETUP_CFLAGS_CPU_DEP],
672
[
673
  #### CPU DEFINES, these should (in theory) be independent on toolchain
674

675
  # Setup target CPU
676
  # Setup endianness
677
  if test "x$FLAGS_CPU_ENDIAN" = xlittle; then
678
    $1_DEFINES_CPU_JVM="-DVM_LITTLE_ENDIAN"
679
    $1_DEFINES_CPU_JDK="-D_LITTLE_ENDIAN"
680
  else
681
    $1_DEFINES_CPU_JDK="-D_BIG_ENDIAN"
682
  fi
683

684
  # setup CPU bit size
685
  $1_DEFINES_CPU_JDK="${$1_DEFINES_CPU_JDK} -DARCH='\"$FLAGS_CPU_LEGACY\"' \
686
      -D$FLAGS_CPU_LEGACY"
687

688
  if test "x$FLAGS_CPU_BITS" = x64; then
689
    $1_DEFINES_CPU_JDK="${$1_DEFINES_CPU_JDK} -D_LP64=1"
690
    $1_DEFINES_CPU_JVM="${$1_DEFINES_CPU_JVM} -D_LP64=1"
691
  fi
692

693
  # toolchain dependent, per-cpu
694
  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
695
    if test "x$FLAGS_CPU" = xaarch64; then
696
      $1_DEFINES_CPU_JDK="${$1_DEFINES_CPU_JDK} -D_ARM64_ -Darm64"
697
    elif test "x$FLAGS_CPU" = xx86_64; then
698
      $1_DEFINES_CPU_JDK="${$1_DEFINES_CPU_JDK} -D_AMD64_ -Damd64"
699
    else
700
      $1_DEFINES_CPU_JDK="${$1_DEFINES_CPU_JDK} -D_X86_ -Dx86"
701
    fi
702
  fi
703

704
  # CFLAGS PER CPU
705
  if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
706
    # COMMON to gcc and clang
707
    AC_MSG_CHECKING([if $1 is x86])
708
    if test "x$FLAGS_CPU" = xx86; then
709
      AC_MSG_RESULT([yes])
710
      AC_MSG_CHECKING([if control flow protection is enabled by additional compiler flags])
711
      if echo "${EXTRA_CFLAGS}${EXTRA_CXXFLAGS}${EXTRA_ASFLAGS}" | ${GREP} -q 'fcf-protection' ; then
712
        # cf-protection requires CMOV and thus i686
713
        $1_CFLAGS_CPU="-march=i686"
714
        AC_MSG_RESULT([yes, forcing ${$1_CFLAGS_CPU}])
715
      else
716
        # Force compatibility with i586 on 32 bit intel platforms.
717
        $1_CFLAGS_CPU="-march=i586"
718
        AC_MSG_RESULT([no, forcing ${$1_CFLAGS_CPU}])
719
      fi
720
    else
721
      AC_MSG_RESULT([no])
722
    fi
723
  fi
724

725
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
726
    if test "x$FLAGS_CPU" = xaarch64; then
727
      # -Wno-psabi to get rid of annoying "note: parameter passing for argument of type '<type> changed in GCC 9.1"
728
      $1_CFLAGS_CPU="-Wno-psabi"
729
    elif test "x$FLAGS_CPU" = xarm; then
730
      # -Wno-psabi to get rid of annoying "note: the mangling of 'va_list' has changed in GCC 4.4"
731
      $1_CFLAGS_CPU="-fsigned-char -Wno-psabi $ARM_ARCH_TYPE_FLAGS $ARM_FLOAT_TYPE_FLAGS -DJDK_ARCH_ABI_PROP_NAME='\"\$(JDK_ARCH_ABI_PROP_NAME)\"'"
732
      $1_CFLAGS_CPU_JVM="-DARM"
733
    elif test "x$FLAGS_CPU_ARCH" = xppc; then
734
      $1_CFLAGS_CPU_JVM="-minsert-sched-nops=regroup_exact -mno-multiple -mno-string"
735
      if test "x$FLAGS_CPU" = xppc64; then
736
        # -mminimal-toc fixes `relocation truncated to fit' error for gcc 4.1.
737
        # Use ppc64 instructions, but schedule for power5
738
        $1_CFLAGS_CPU_JVM="${$1_CFLAGS_CPU_JVM} -mminimal-toc -mcpu=powerpc64 -mtune=power5"
739
      elif test "x$FLAGS_CPU" = xppc64le; then
740
        # Little endian machine uses ELFv2 ABI.
741
        # Use Power8, this is the first CPU to support PPC64 LE with ELFv2 ABI.
742
        $1_CFLAGS_CPU_JVM="${$1_CFLAGS_CPU_JVM} -DABI_ELFv2 -mcpu=power8 -mtune=power8"
743
      fi
744
    elif test "x$FLAGS_CPU" = xs390x; then
745
      $1_CFLAGS_CPU="-mbackchain -march=z10"
746
    fi
747

748
    if test "x$FLAGS_CPU_ARCH" != xarm &&  test "x$FLAGS_CPU_ARCH" != xppc; then
749
      # for all archs except arm and ppc, prevent gcc to omit frame pointer
750
      $1_CFLAGS_CPU_JDK="${$1_CFLAGS_CPU_JDK} -fno-omit-frame-pointer"
751
    fi
752

753
  elif test "x$TOOLCHAIN_TYPE" = xclang; then
754
    if test "x$FLAGS_OS" = xlinux; then
755
      # ppc test not really needed for clang
756
      if test "x$FLAGS_CPU_ARCH" != xarm &&  test "x$FLAGS_CPU_ARCH" != xppc; then
757
        # for all archs except arm and ppc, prevent gcc to omit frame pointer
758
        $1_CFLAGS_CPU_JDK="${$1_CFLAGS_CPU_JDK} -fno-omit-frame-pointer"
759
      fi
760
    fi
761
    if test "x$OPENJDK_TARGET_OS" = xaix; then
762
      $1_CFLAGS_CPU="-mcpu=pwr8"
763
    fi
764

765
  elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
766
    if test "x$FLAGS_CPU" = xx86; then
767
      $1_CFLAGS_CPU_JVM="-arch:IA32"
768
    elif test "x$OPENJDK_TARGET_CPU" = xx86_64; then
769
      if test "x$DEBUG_LEVEL" != xrelease; then
770
        # NOTE: This is probably redundant; -homeparams is default on
771
        # non-release builds.
772
        $1_CFLAGS_CPU_JVM="-homeparams"
773
      fi
774
    fi
775
  fi
776

777
  if test "x$TOOLCHAIN_TYPE" = xgcc; then
778
    FLAGS_SETUP_GCC6_COMPILER_FLAGS($1, $3)
779
    $1_TOOLCHAIN_CFLAGS="${$1_GCC6_CFLAGS}"
780

781
    $1_WARNING_CFLAGS_JVM="-Wno-format-zero-length -Wtype-limits -Wuninitialized"
782
  fi
783

784
  if test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
785
    REPRODUCIBLE_CFLAGS="-experimental:deterministic"
786
    FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${REPRODUCIBLE_CFLAGS}],
787
        PREFIX: $3,
788
        IF_FALSE: [
789
            REPRODUCIBLE_CFLAGS=
790
        ]
791
    )
792
    AC_SUBST(REPRODUCIBLE_CFLAGS)
793
  fi
794

795
  # Prevent the __FILE__ macro from generating absolute paths into the built
796
  # binaries. Depending on toolchain, different mitigations are possible.
797
  # * GCC and Clang of new enough versions have -fmacro-prefix-map.
798
  # * For most other toolchains, supplying all source files and -I flags as
799
  #   relative paths fixes the issue.
800
  FILE_MACRO_CFLAGS=
801
  if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
802
    if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
803
      # Check if compiler supports -fmacro-prefix-map. If so, use that to make
804
      # the __FILE__ macro resolve to paths relative to the workspace root.
805
      workspace_root_trailing_slash="${WORKSPACE_ROOT%/}/"
806
      FILE_MACRO_CFLAGS="-fmacro-prefix-map=${workspace_root_trailing_slash}="
807
      FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${FILE_MACRO_CFLAGS}],
808
          PREFIX: $3,
809
          IF_FALSE: [
810
              FILE_MACRO_CFLAGS=
811
          ]
812
      )
813
    elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
814
      # There is a known issue with the pathmap if the mapping is made to the
815
      # empty string. Add a minimal string "s" as prefix to work around this.
816
      # PATHMAP_FLAGS is also added to LDFLAGS in flags-ldflags.m4.
817
      PATHMAP_FLAGS="-pathmap:${WORKSPACE_ROOT}=s"
818
      FILE_MACRO_CFLAGS="$PATHMAP_FLAGS"
819
      FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${FILE_MACRO_CFLAGS}],
820
          PREFIX: $3,
821
          IF_FALSE: [
822
              PATHMAP_FLAGS=
823
              FILE_MACRO_CFLAGS=
824
          ]
825
      )
826
      if test "x$FILE_MACRO_CFLAGS" != x; then
827
        # Add -pathmap for all VS system include paths using Windows
828
        # full Long path name that is generated by the compiler
829
        # Not enabled under WSL as there is no easy way to obtain the
830
        # Windows full long paths, thus reproducible WSL builds will
831
        # depend on building with the same VS toolchain install location.
832
        if test "x$OPENJDK_BUILD_OS_ENV" != "xwindows.wsl1" && test "x$OPENJDK_BUILD_OS_ENV" != "xwindows.wsl2"; then
833
          for ipath in ${$3SYSROOT_CFLAGS}; do
834
              if test "x${ipath:0:2}" == "x-I"; then
835
                  ipath_path=${ipath#"-I"}
836
                  UTIL_FIXUP_WIN_LONG_PATH(ipath_path)
837
                  FILE_MACRO_CFLAGS="$FILE_MACRO_CFLAGS -pathmap:\"$ipath_path\"=vsi"
838
              fi
839
          done
840
        fi
841
      fi
842
    fi
843

844
    AC_MSG_CHECKING([how to prevent absolute paths in output])
845
    if test "x$FILE_MACRO_CFLAGS" != x; then
846
      AC_MSG_RESULT([using compiler options])
847
    else
848
      AC_MSG_RESULT([using relative paths])
849
    fi
850
  fi
851
  AC_SUBST(FILE_MACRO_CFLAGS)
852

853
  FLAGS_SETUP_BRANCH_PROTECTION
854

855
  # EXPORT to API
856
  CFLAGS_JVM_COMMON="$ALWAYS_CFLAGS_JVM $ALWAYS_DEFINES_JVM \
857
      $TOOLCHAIN_CFLAGS_JVM ${$1_TOOLCHAIN_CFLAGS_JVM} \
858
      $OS_CFLAGS $OS_CFLAGS_JVM $CFLAGS_OS_DEF_JVM $DEBUG_CFLAGS_JVM \
859
      $WARNING_CFLAGS $WARNING_CFLAGS_JVM $JVM_PICFLAG $FILE_MACRO_CFLAGS \
860
      $REPRODUCIBLE_CFLAGS $BRANCH_PROTECTION_CFLAGS"
861

862
  CFLAGS_JDK_COMMON="$ALWAYS_DEFINES_JDK $TOOLCHAIN_CFLAGS_JDK \
863
      $OS_CFLAGS $CFLAGS_OS_DEF_JDK $DEBUG_CFLAGS_JDK $DEBUG_OPTIONS_FLAGS_JDK \
864
      $WARNING_CFLAGS $WARNING_CFLAGS_JDK $DEBUG_SYMBOLS_CFLAGS_JDK \
865
      $FILE_MACRO_CFLAGS $REPRODUCIBLE_CFLAGS $BRANCH_PROTECTION_CFLAGS"
866

867
  # Use ${$2EXTRA_CFLAGS} to block EXTRA_CFLAGS to be added to build flags.
868
  # (Currently we don't have any OPENJDK_BUILD_EXTRA_CFLAGS, but that might
869
  # change in the future.)
870

871
  CFLAGS_JDK_COMMON_CONLY="$TOOLCHAIN_CFLAGS_JDK_CONLY  \
872
      $WARNING_CFLAGS_JDK_CONLY ${$2EXTRA_CFLAGS}"
873
  CFLAGS_JDK_COMMON_CXXONLY="$ALWAYS_DEFINES_JDK_CXXONLY \
874
      $TOOLCHAIN_CFLAGS_JDK_CXXONLY \
875
      ${$1_TOOLCHAIN_CFLAGS_JDK_CXXONLY} \
876
      $WARNING_CFLAGS_JDK_CXXONLY ${$2EXTRA_CXXFLAGS}"
877

878
  $1_CFLAGS_JVM="${$1_DEFINES_CPU_JVM} ${$1_CFLAGS_CPU} ${$1_CFLAGS_CPU_JVM} ${$1_TOOLCHAIN_CFLAGS} ${$1_WARNING_CFLAGS_JVM}"
879
  $1_CFLAGS_JDK="${$1_DEFINES_CPU_JDK} ${$1_CFLAGS_CPU} ${$1_CFLAGS_CPU_JDK} ${$1_TOOLCHAIN_CFLAGS}"
880

881
  $2JVM_CFLAGS="$CFLAGS_JVM_COMMON ${$1_CFLAGS_JVM} ${$2EXTRA_CXXFLAGS}"
882

883
  $2CFLAGS_JDKEXE="$CFLAGS_JDK_COMMON $CFLAGS_JDK_COMMON_CONLY ${$1_CFLAGS_JDK} $PIEFLAG"
884
  $2CXXFLAGS_JDKEXE="$CFLAGS_JDK_COMMON $CFLAGS_JDK_COMMON_CXXONLY ${$1_CFLAGS_JDK} $PIEFLAG"
885
  $2CFLAGS_JDKLIB="$CFLAGS_JDK_COMMON $CFLAGS_JDK_COMMON_CONLY ${$1_CFLAGS_JDK} \
886
      $JDK_PICFLAG ${$1_CFLAGS_CPU_JDK_LIBONLY}"
887
  $2CXXFLAGS_JDKLIB="$CFLAGS_JDK_COMMON $CFLAGS_JDK_COMMON_CXXONLY ${$1_CFLAGS_JDK} \
888
      $JDK_PICFLAG ${$1_CFLAGS_CPU_JDK_LIBONLY}"
889

890
  AC_SUBST($2JVM_CFLAGS)
891
  AC_SUBST($2CFLAGS_JDKLIB)
892
  AC_SUBST($2CFLAGS_JDKEXE)
893
  AC_SUBST($2CXXFLAGS_JDKLIB)
894
  AC_SUBST($2CXXFLAGS_JDKEXE)
895
  AC_SUBST($2ADLC_LANGSTD_CXXFLAGS)
896

897
  COMPILER_FP_CONTRACT_OFF_FLAG="-ffp-contract=off"
898
  # Check that the compiler supports -ffp-contract=off flag
899
  # Set FDLIBM_CFLAGS to -ffp-contract=off if it does. Empty
900
  # otherwise.
901
  # These flags are required for GCC-based builds of
902
  # fdlibm with optimization without losing precision.
903
  # Notably, -ffp-contract=off needs to be added for GCC >= 4.6.
904
  if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
905
    FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${COMPILER_FP_CONTRACT_OFF_FLAG}],
906
        PREFIX: $3,
907
        IF_TRUE: [$2FDLIBM_CFLAGS=${COMPILER_FP_CONTRACT_OFF_FLAG}],
908
        IF_FALSE: [$2FDLIBM_CFLAGS=""])
909
  fi
910
  AC_SUBST($2FDLIBM_CFLAGS)
911
])
912

913
# FLAGS_SETUP_GCC6_COMPILER_FLAGS([PREFIX])
914
# Arguments:
915
# $1 - Prefix for each variable defined.
916
# $2 - Prefix for compiler variables (either BUILD_ or nothing).
917
AC_DEFUN([FLAGS_SETUP_GCC6_COMPILER_FLAGS],
918
[
919
  # This flag is required for GCC 6 builds as undefined behavior in OpenJDK code
920
  # runs afoul of the more aggressive versions of this optimization.
921
  NO_LIFETIME_DSE_CFLAG="-fno-lifetime-dse"
922
  FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [$NO_LIFETIME_DSE_CFLAG],
923
      PREFIX: $2, IF_FALSE: [NO_LIFETIME_DSE_CFLAG=""])
924
  $1_GCC6_CFLAGS="${NO_LIFETIME_DSE_CFLAG}"
925
])
926

927
AC_DEFUN_ONCE([FLAGS_SETUP_BRANCH_PROTECTION],
928
[
929
  # Is branch protection available?
930
  BRANCH_PROTECTION_AVAILABLE=false
931
  BRANCH_PROTECTION_FLAG="-mbranch-protection=standard"
932

933
  if test "x$OPENJDK_TARGET_CPU" = xaarch64; then
934
    if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
935
      FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${BRANCH_PROTECTION_FLAG}],
936
          IF_TRUE: [BRANCH_PROTECTION_AVAILABLE=true])
937
    fi
938
  fi
939

940
  BRANCH_PROTECTION_CFLAGS=""
941
  UTIL_ARG_ENABLE(NAME: branch-protection, DEFAULT: false,
942
      RESULT: USE_BRANCH_PROTECTION, AVAILABLE: $BRANCH_PROTECTION_AVAILABLE,
943
      DESC: [enable branch protection when compiling C/C++],
944
      IF_ENABLED: [ BRANCH_PROTECTION_CFLAGS=${BRANCH_PROTECTION_FLAG}])
945
  AC_SUBST(BRANCH_PROTECTION_CFLAGS)
946
])
947

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

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

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

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