Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions make/autoconf/jdk-options.m4
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,23 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_ADDRESS_SANITIZER],
# It's harmless to be suppressed in clang as well.
ASAN_CFLAGS="-fsanitize=address -Wno-stringop-truncation -fno-omit-frame-pointer -fno-common -DADDRESS_SANITIZER"
ASAN_LDFLAGS="-fsanitize=address"
# detect_stack_use_after_return causes ASAN to offload stack-local
# variables to c-heap and therefore breaks assumptions in hotspot
# that rely on data (e.g. Marks) living in thread stacks.
Comment on lines +441 to +443
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Now I understand what it is doing. Ouch!

if test "x$TOOLCHAIN_TYPE" = "xgcc"; then
ASAN_CFLAGS="$ASAN_CFLAGS --param asan-use-after-return=0"
fi
if test "x$TOOLCHAIN_TYPE" = "xclang"; then
ASAN_CFLAGS="$ASAN_CFLAGS -fsanitize-address-use-after-return=never"
fi

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is JDK-wide configuration. Do we need that? Or would it be sufficient to limit this to the JVM?
I'm not sure what would happen with fake stacks at the JVM boundary (in either direction). I also don't
know what happens at the boundary with non-JDK native code.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it some more, global disable seems like the only safe thing to do. So never mind my musings
about whether the disable could be limited to the JVM.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no change being made for the microsoft toolchain. It seems like the same issues with the fake stack
should arise there.

Copy link
Contributor Author

@jankratochvil jankratochvil Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I have tried it in AWS and added the new comment about it as MSVC has it off by default.
Microsoft documentation even implies it is off by default.
But I have filed JDK-8335228 as the MS-Windows OpenJDK build crashes if one explicitly enables -fsanitize-address-use-after-return there.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we'll have to monitor this in future VS updates, which might start enabling it. But this seems okay for now.

elif test "x$TOOLCHAIN_TYPE" = "xmicrosoft"; then
# -Oy- is equivalent to -fno-omit-frame-pointer in GCC/Clang.
ASAN_CFLAGS="-fsanitize=address -Oy- -DADDRESS_SANITIZER"
# MSVC produces a warning if you pass -fsanitize=address to the linker. It also complains
$ if -DEBUG is not passed to the linker when building with ASan.
ASAN_LDFLAGS="-debug"
# -fsanitize-address-use-after-return is off by default in MS Visual Studio 22 (19.37.32824).
# cl : Command line warning D9002 : ignoring unknown option '-fno-sanitize-address-use-after-return'
fi
JVM_CFLAGS="$JVM_CFLAGS $ASAN_CFLAGS"
JVM_LDFLAGS="$JVM_LDFLAGS $ASAN_LDFLAGS"
Expand Down