diff --git a/make/autoconf/jdk-options.m4 b/make/autoconf/jdk-options.m4 index 3c71da95ca1..babe4639ccb 100644 --- a/make/autoconf/jdk-options.m4 +++ b/make/autoconf/jdk-options.m4 @@ -437,7 +437,6 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_ADDRESS_SANITIZER], LDFLAGS_JDKLIB="$LDFLAGS_JDKLIB $ASAN_LDFLAGS" LDFLAGS_JDKEXE="$LDFLAGS_JDKEXE $ASAN_LDFLAGS" ]) - AC_SUBST(ASAN_ENABLED) ]) diff --git a/make/common/TestFilesCompilation.gmk b/make/common/TestFilesCompilation.gmk index 06e1ce1347f..7075931d77c 100644 --- a/make/common/TestFilesCompilation.gmk +++ b/make/common/TestFilesCompilation.gmk @@ -45,6 +45,7 @@ include NativeCompilation.gmk # SOURCE_DIRS A list of source directories to search # OUTPUT_DIR Where to put the resulting files # EXCLUDE A list of filenames to exclude from compilation +# EXTRA_FILES List of extra files not in SOURCE_DIRS SetupTestFilesCompilation = $(NamedParamsMacroTemplate) define SetupTestFilesCompilationBody @@ -93,7 +94,7 @@ define SetupTestFilesCompilationBody $$(eval $$(call SetupNativeCompilation, BUILD_TEST_$$(name), \ NAME := $$(unprefixed_name), \ TYPE := $$($1_COMPILATION_TYPE), \ - EXTRA_FILES := $$(file), \ + EXTRA_FILES := $$(file) $$($1_EXTRA_FILES), \ OBJECT_DIR := $$($1_OUTPUT_DIR)/support/$$(name), \ OUTPUT_DIR := $$($1_OUTPUT_DIR)/$$($1_OUTPUT_SUBDIR), \ CFLAGS := $$($1_BASE_CFLAGS) $$($1_CFLAGS) $$($1_CFLAGS_$$(name)), \ diff --git a/make/data/asan/asan_default_options.cpp b/make/data/asan/asan_default_options.cpp new file mode 100644 index 00000000000..f84ebab27cb --- /dev/null +++ b/make/data/asan/asan_default_options.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +extern "C" { + +#include "./asan_default_options.c" + +} // extern "C" diff --git a/make/hotspot/lib/CompileGtest.gmk b/make/hotspot/lib/CompileGtest.gmk index 081ee95346f..d27cf53c054 100644 --- a/make/hotspot/lib/CompileGtest.gmk +++ b/make/hotspot/lib/CompileGtest.gmk @@ -28,6 +28,10 @@ $(eval $(call IncludeCustomExtension, hotspot/lib/CompileGtest.gmk)) GTEST_TEST_SRC += $(TOPDIR)/test/hotspot/gtest GTEST_LAUNCHER_SRC := $(TOPDIR)/test/hotspot/gtest/gtestLauncher.cpp +ifeq ($(ASAN_ENABLED), true) + GTEST_LAUNCHER_SRC += $(TOPDIR)/make/data/asan/asan_default_options.cpp +endif + # On Windows, there are no internal debug symbols so must set copying to true # to get any at all. ifeq ($(call isTargetOs, windows), true) diff --git a/make/test/JtregNativeHotspot.gmk b/make/test/JtregNativeHotspot.gmk index 83c9a2377ca..5c7126b6d84 100644 --- a/make/test/JtregNativeHotspot.gmk +++ b/make/test/JtregNativeHotspot.gmk @@ -1518,6 +1518,12 @@ else BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libnativeStack += -lpthread endif +ifeq ($(ASAN_ENABLED), true) + # Any executable which launches the JVM and uses a custom launcher needs to explicitly link in the + # default ASan options. + BUILD_HOTSPOT_JTREG_EXTRA_FILES := $(TOPDIR)/make/data/asan/asan_default_options.c +endif + # This evaluation is expensive and should only be done if this target was # explicitly called. ifneq ($(filter build-test-hotspot-jtreg-native, $(MAKECMDGOALS)), ) @@ -1533,6 +1539,7 @@ ifneq ($(filter build-test-hotspot-jtreg-native, $(MAKECMDGOALS)), ) SOURCE_DIRS := $(BUILD_HOTSPOT_JTREG_NATIVE_SRC), \ OUTPUT_DIR := $(BUILD_HOTSPOT_JTREG_OUTPUT_DIR), \ EXCLUDE := $(BUILD_HOTSPOT_JTREG_EXCLUDE), \ + EXTRA_FILES := $(BUILD_HOTSPOT_JTREG_EXTRA_FILES), \ )) endif diff --git a/make/test/JtregNativeJdk.gmk b/make/test/JtregNativeJdk.gmk index d1e27929759..ba3135bc9ff 100644 --- a/make/test/JtregNativeJdk.gmk +++ b/make/test/JtregNativeJdk.gmk @@ -132,6 +132,12 @@ ifeq ($(call isTargetOs, linux), true) BUILD_JDK_JTREG_LIBRARIES_STRIP_SYMBOLS_libFib := false endif +ifeq ($(ASAN_ENABLED), true) + # Any executable which launches the JVM and uses a custom launcher needs to explicitly link in the + # default ASan options. + BUILD_JDK_JTREG_EXTRA_FILES := $(TOPDIR)/make/data/asan/asan_default_options.c +endif + # This evaluation is expensive and should only be done if this target was # explicitly called. ifneq ($(filter build-test-jdk-jtreg-native, $(MAKECMDGOALS)), ) @@ -147,6 +153,7 @@ ifneq ($(filter build-test-jdk-jtreg-native, $(MAKECMDGOALS)), ) SOURCE_DIRS := $(BUILD_JDK_JTREG_NATIVE_SRC), \ OUTPUT_DIR := $(BUILD_JDK_JTREG_OUTPUT_DIR), \ EXCLUDE := $(BUILD_JDK_JTREG_EXCLUDE), \ + EXTRA_FILES := $(BUILD_JDK_JTREG_EXTRA_FILES), \ )) endif