Skip to content

Commit b1e778d

Browse files
author
Joachim Kern
committed
8354686: [AIX] now ubsan is possible
Reviewed-by: mbaesken, clanger
1 parent 66358fa commit b1e778d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

make/autoconf/jdk-options.m4

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,16 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_UNDEFINED_BEHAVIOR_SANITIZER],
522522
$ADDITIONAL_UBSAN_CHECKS"
523523
UBSAN_CFLAGS="$UBSAN_CHECKS -Wno-stringop-truncation -Wno-format-overflow -Wno-array-bounds -Wno-stringop-overflow -fno-omit-frame-pointer -DUNDEFINED_BEHAVIOR_SANITIZER"
524524
UBSAN_LDFLAGS="$UBSAN_CHECKS"
525+
# On AIX, the llvm_symbolizer is not found out of the box, so we have to provide the
526+
# full qualified llvm_symbolizer path in the __ubsan_default_options() function in
527+
# make/data/ubsan/ubsan_default_options.c. To get it there we compile our sources
528+
# with an additional define LLVM_SYMBOLIZER, which we set here.
529+
# To calculate the correct llvm_symbolizer path we can use the location of the compiler, because
530+
# their relation is fixed.
531+
if test "x$TOOLCHAIN_TYPE" = "xclang" && test "x$OPENJDK_TARGET_OS" = "xaix"; then
532+
UBSAN_CFLAGS="$UBSAN_CFLAGS -fno-sanitize=function,vptr -DLLVM_SYMBOLIZER=$(dirname $(dirname $CC))/tools/ibm-llvm-symbolizer"
533+
UBSAN_LDFLAGS="$UBSAN_LDFLAGS -fno-sanitize=function,vptr -Wl,-bbigtoc"
534+
fi
525535
UTIL_ARG_ENABLE(NAME: ubsan, DEFAULT: false, RESULT: UBSAN_ENABLED,
526536
DESC: [enable UndefinedBehaviorSanitizer],
527537
CHECK_AVAILABLE: [

make/data/ubsan/ubsan_default_options.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -43,12 +43,24 @@
4343
#define ATTRIBUTE_USED
4444
#endif
4545

46+
// On AIX, the llvm_symbolizer is not found out of the box, so we have to provide the
47+
// full qualified llvm_symbolizer path in the __ubsan_default_options() function.
48+
// To get it here we compile our sources with an additional define LLVM_SYMBOLIZER
49+
// containing the path, which we set in make/autoconf/jdk-options.m4.
50+
#ifdef LLVM_SYMBOLIZER
51+
#define _LLVM_SYMBOLIZER(X) ",external_symbolizer_path=" X_LLVM_SYMBOLIZER(X)
52+
#define X_LLVM_SYMBOLIZER(X) #X
53+
#else
54+
#define LLVM_SYMBOLIZER
55+
#define _LLVM_SYMBOLIZER(X)
56+
#endif
57+
4658
// Override weak symbol exposed by UBSan to override default options. This is called by UBSan
4759
// extremely early during library loading, before main is called. We need to override the default
4860
// options because by default UBSan only prints a warning for each occurrence. We want jtreg tests
4961
// to fail when undefined behavior is encountered. We also want a full stack trace for the offending
5062
// thread so it is easier to track down. You can override these options by setting the environment
5163
// variable UBSAN_OPTIONS.
5264
ATTRIBUTE_DEFAULT_VISIBILITY ATTRIBUTE_USED const char* __ubsan_default_options() {
53-
return "halt_on_error=1,print_stacktrace=1";
65+
return "halt_on_error=1,print_stacktrace=1" _LLVM_SYMBOLIZER(LLVM_SYMBOLIZER);
5466
}

0 commit comments

Comments
 (0)