Skip to content

Commit ff30240

Browse files
committed
8334239: Introduce macro for ubsan method/function exclusions
Reviewed-by: stefank, stuefe, kbarrett
1 parent 2d4185f commit ff30240

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

src/hotspot/share/cds/archiveHeapLoader.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "memory/iterator.inline.hpp"
3535
#include "memory/resourceArea.hpp"
3636
#include "memory/universe.hpp"
37+
#include "sanitizers/ub.hpp"
3738
#include "utilities/bitMap.inline.hpp"
3839
#include "utilities/copy.hpp"
3940

@@ -61,9 +62,7 @@ ptrdiff_t ArchiveHeapLoader::_mapped_heap_delta = 0;
6162

6263
// Every mapped region is offset by _mapped_heap_delta from its requested address.
6364
// See FileMapInfo::heap_region_requested_address().
64-
#if defined(__clang__) || defined(__GNUC__)
65-
__attribute__((no_sanitize("undefined")))
66-
#endif
65+
ATTRIBUTE_NO_UBSAN
6766
void ArchiveHeapLoader::init_mapped_heap_info(address mapped_heap_bottom, ptrdiff_t delta, int dumptime_oop_shift) {
6867
assert(!_mapped_heap_relocation_initialized, "only once");
6968
if (!UseCompressedOops) {

src/hotspot/share/prims/unsafe.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "runtime/threadSMR.hpp"
5656
#include "runtime/vmOperations.hpp"
5757
#include "runtime/vm_version.hpp"
58+
#include "sanitizers/ub.hpp"
5859
#include "services/threadService.hpp"
5960
#include "utilities/align.hpp"
6061
#include "utilities/copy.hpp"
@@ -244,9 +245,7 @@ class MemoryAccess : StackObj {
244245

245246
// we use this method at some places for writing to 0 e.g. to cause a crash;
246247
// ubsan does not know that this is the desired behavior
247-
#if defined(__clang__) || defined(__GNUC__)
248-
__attribute__((no_sanitize("undefined")))
249-
#endif
248+
ATTRIBUTE_NO_UBSAN
250249
void put(T x) {
251250
GuardUnsafeAccess guard(_thread);
252251
*addr() = normalize_for_write(x);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2024 SAP SE. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
26+
#ifndef SHARE_SANITIZERS_UB_HPP
27+
#define SHARE_SANITIZERS_UB_HPP
28+
29+
// ATTRIBUTE_NO_UBSAN
30+
//
31+
// Function attribute which informs the compiler to disable UBSan checks in the
32+
// following function or method.
33+
// Useful if the function or method is known to do something special or even 'dangerous', for
34+
// example causing desired signals/crashes.
35+
#if defined(__clang__) || defined(__GNUC__)
36+
#define ATTRIBUTE_NO_UBSAN __attribute__((no_sanitize("undefined")))
37+
#endif
38+
39+
#ifndef ATTRIBUTE_NO_UBSAN
40+
#define ATTRIBUTE_NO_UBSAN
41+
#endif
42+
43+
#endif // SHARE_SANITIZERS_UB_HPP

src/hotspot/share/utilities/vmError.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "runtime/vmOperations.hpp"
6161
#include "runtime/vmThread.hpp"
6262
#include "runtime/vm_version.hpp"
63+
#include "sanitizers/ub.hpp"
6364
#include "utilities/debug.hpp"
6465
#include "utilities/decoder.hpp"
6566
#include "utilities/defaultStream.hpp"
@@ -2086,9 +2087,7 @@ typedef void (*voidfun_t)();
20862087
// compared to one generated with raise (asynchronous vs synchronous). See JDK-8065895.
20872088
volatile int sigfpe_int = 0;
20882089

2089-
#if defined(__clang__) || defined(__GNUC__)
2090-
__attribute__((no_sanitize("undefined")))
2091-
#endif
2090+
ATTRIBUTE_NO_UBSAN
20922091
static void ALWAYSINLINE crash_with_sigfpe() {
20932092

20942093
// generate a native synchronous SIGFPE where possible;

0 commit comments

Comments
 (0)