hotspot/make/linux/makefiles/gcc.make
Print this page
rev 6070 : 8032045: Enable compiler and linker safety switches for debug builds
Reviewed-by: duke
*** 60,70 ****
# prints the numbers (e.g. "2.95", "3.2.1")
CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1)
CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2)
endif
-
ifeq ($(USE_CLANG), true)
# Clang has precompiled headers support by default, but the user can switch
# it off by using 'USE_PRECOMPILED_HEADER=0'.
ifdef LP64
ifeq ($(USE_PRECOMPILED_HEADER),)
--- 60,69 ----
*** 102,112 ****
# There are some files which don't like precompiled headers
# The following files are build with 'OPT_CFLAGS/NOOPT' (-O0) in the opt build.
# But Clang doesn't support a precompiled header which was compiled with -O3
# to be used in a compilation unit which uses '-O0'. We could also prepare an
# extra '-O0' PCH file for the opt build and use it here, but it's probably
! # not worth the effoert as long as only two files need this special handling.
PCH_FLAG/loopTransform.o = $(PCH_FLAG/NO_PCH)
PCH_FLAG/sharedRuntimeTrig.o = $(PCH_FLAG/NO_PCH)
PCH_FLAG/sharedRuntimeTrans.o = $(PCH_FLAG/NO_PCH)
endif
--- 101,111 ----
# There are some files which don't like precompiled headers
# The following files are build with 'OPT_CFLAGS/NOOPT' (-O0) in the opt build.
# But Clang doesn't support a precompiled header which was compiled with -O3
# to be used in a compilation unit which uses '-O0'. We could also prepare an
# extra '-O0' PCH file for the opt build and use it here, but it's probably
! # not worth the effort as long as only two files need this special handling.
PCH_FLAG/loopTransform.o = $(PCH_FLAG/NO_PCH)
PCH_FLAG/sharedRuntimeTrig.o = $(PCH_FLAG/NO_PCH)
PCH_FLAG/sharedRuntimeTrans.o = $(PCH_FLAG/NO_PCH)
endif
*** 224,247 ****
WARNING_FLAGS += -Wconversion
endif
endif
CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS)
# Special cases
CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@))
! # The flags to use for an Optimized g++ build
OPT_CFLAGS/SIZE=-Os
OPT_CFLAGS/SPEED=-O3
# Hotspot uses very unstrict aliasing turn this optimization off
# This option is added to CFLAGS rather than OPT_CFLAGS
# so that OPT_CFLAGS overrides get this option too.
CFLAGS += -fno-strict-aliasing
- OPT_CFLAGS_DEFAULT ?= SPEED
-
ifdef OPT_CFLAGS
ifneq ("$(origin OPT_CFLAGS)", "command line")
$(error " Use OPT_EXTRAS instead of OPT_CFLAGS to add extra flags to OPT_CFLAGS.")
endif
endif
--- 223,255 ----
WARNING_FLAGS += -Wconversion
endif
endif
CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS)
+
# Special cases
CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@))
! # optimization control flags (Used by fastdebug and release variants)
! OPT_CFLAGS/NOOPT=-O0
! ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 8 \) \))" "1"
! # Allow basic optimizations which don't distrupt debugging. (Principally dead code elimination)
! OPT_CFLAGS/DEBUG=-Og
! else
! # Allow no optimizations.
! OPT_CFLAGS/DEBUG=-O0
! endif
OPT_CFLAGS/SIZE=-Os
OPT_CFLAGS/SPEED=-O3
+ OPT_CFLAGS_DEFAULT ?= SPEED
+
# Hotspot uses very unstrict aliasing turn this optimization off
# This option is added to CFLAGS rather than OPT_CFLAGS
# so that OPT_CFLAGS overrides get this option too.
CFLAGS += -fno-strict-aliasing
ifdef OPT_CFLAGS
ifneq ("$(origin OPT_CFLAGS)", "command line")
$(error " Use OPT_EXTRAS instead of OPT_CFLAGS to add extra flags to OPT_CFLAGS.")
endif
endif
*** 252,263 ****
# if we use expensive-optimizations
ifeq ($(BUILDARCH), ia64)
OPT_CFLAGS += -fno-expensive-optimizations
endif
- OPT_CFLAGS/NOOPT=-O0
-
# Work around some compiler bugs.
ifeq ($(USE_CLANG), true)
ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 2), 1)
OPT_CFLAGS/loopTransform.o += $(OPT_CFLAGS/NOOPT)
endif
--- 260,269 ----
*** 269,279 ****
endif
# Flags for generating make dependency flags.
DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d)
ifeq ($(USE_CLANG),)
! ifneq ("${CC_VER_MAJOR}", "2")
DEPFLAGS += -fpch-deps
endif
endif
#------------------------------------------------------------------------
--- 275,285 ----
endif
# Flags for generating make dependency flags.
DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d)
ifeq ($(USE_CLANG),)
! ifneq ($(CC_VER_MAJOR), 2)
DEPFLAGS += -fpch-deps
endif
endif
#------------------------------------------------------------------------
*** 282,304 ****
# statically link libstdc++.so, work with gcc but ignored by g++
STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
ifeq ($(USE_CLANG),)
# statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x.
! ifneq ("${CC_VER_MAJOR}", "2")
STATIC_LIBGCC += -static-libgcc
endif
ifeq ($(BUILDARCH), ia64)
LFLAGS += -Wl,-relax
endif
- endif
-
- # Enable linker optimization
- LFLAGS += -Xlinker -O1
- ifeq ($(USE_CLANG),)
# If this is a --hash-style=gnu system, use --hash-style=both
# The gnu .hash section won't work on some Linux systems like SuSE 10.
_HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu')
ifneq ($(_HAS_HASH_STYLE_GNU),)
LDFLAGS_HASH_STYLE = -Wl,--hash-style=both
--- 288,318 ----
# statically link libstdc++.so, work with gcc but ignored by g++
STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
ifeq ($(USE_CLANG),)
# statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x.
! ifneq ($(CC_VER_MAJOR), 2)
STATIC_LIBGCC += -static-libgcc
endif
+ # Enable linker optimization
+ LFLAGS += -Xlinker -O1
+
+ ifeq ($(VARIANT), DBG)
+ # for relocations read-only
+ LFLAGS += -Xlinker -z -Xlinker relro
+
+ ifeq ($(FASTDEBUG), false)
+ # disable incremental relocations linking
+ LFLAGS += -Xlinker -z -Xlinker now
+ endif
+ endif
+
ifeq ($(BUILDARCH), ia64)
LFLAGS += -Wl,-relax
endif
# If this is a --hash-style=gnu system, use --hash-style=both
# The gnu .hash section won't work on some Linux systems like SuSE 10.
_HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu')
ifneq ($(_HAS_HASH_STYLE_GNU),)
LDFLAGS_HASH_STYLE = -Wl,--hash-style=both
*** 331,340 ****
--- 345,362 ----
# too big object files and speed the build up a little bit
# (see http://llvm.org/bugs/show_bug.cgi?id=7554)
CFLAGS += -flimit-debug-info
endif
+ ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 8 \) \))" "1"
+ # Allow basic optimizations which don't distrupt debugging. (Principally dead code elimination)
+ DEBUG_CFLAGS=-Og
+ else
+ # Allow no optimizations.
+ DEBUG_CFLAGS=-O0
+ endif
+
# DEBUG_BINARIES uses full -g debug information for all configs
ifeq ($(DEBUG_BINARIES), true)
CFLAGS += -g
else
# Use the stabs format for debugging information (this is the default
*** 362,372 ****
FASTDEBUG_CFLAGS/ia64 = -g
FASTDEBUG_CFLAGS/amd64 = -g
FASTDEBUG_CFLAGS/arm = -g
FASTDEBUG_CFLAGS/ppc = -g
FASTDEBUG_CFLAGS/ppc64 = -g
! FASTDEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH))
ifeq ($(FASTDEBUG_CFLAGS/$(BUILDARCH)),)
ifeq ($(USE_CLANG), true)
# Clang doesn't understand -gstabs
FASTDEBUG_CFLAGS += -g
else
--- 384,394 ----
FASTDEBUG_CFLAGS/ia64 = -g
FASTDEBUG_CFLAGS/amd64 = -g
FASTDEBUG_CFLAGS/arm = -g
FASTDEBUG_CFLAGS/ppc = -g
FASTDEBUG_CFLAGS/ppc64 = -g
! FASTDEBUG_CFLAGS += $(FASTDEBUG_CFLAGS/$(BUILDARCH))
ifeq ($(FASTDEBUG_CFLAGS/$(BUILDARCH)),)
ifeq ($(USE_CLANG), true)
# Clang doesn't understand -gstabs
FASTDEBUG_CFLAGS += -g
else
*** 389,398 ****
--- 411,434 ----
endif
endif
endif
endif
+ # Enable bounds checking.
+ ifeq ($(VARIANT), DBG)
+ # _FORTIFY_SOURCE appears in GCC 4.0+
+ ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) )" "0"
+ ifeq ($(FASTDEBUG), true)
+ # compile time size bounds checks
+ CFLAGS += -D_FORTIFY_SOURCE=1
+ else
+ # and runtime size bounds checks and paranoid stack smashing checks.
+ CFLAGS += -D_FORTIFY_SOURCE=2 -fstack-protector-all --param ssp-buffer-size=1
+ endif
+ endif
+ endif
+
# If we are building HEADLESS, pass on to VM
# so it can set the java.awt.headless property
ifdef HEADLESS
CFLAGS += -DHEADLESS
endif