Skip to content

Commit 1d1527a

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm] Report the current sanitizer in the compiler environment.
TEST=ci Change-Id: I56585a1fdb1bb6b92eab706fd0a66f78888bc55d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464620 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 6b500b2 commit 1d1527a

File tree

8 files changed

+120
-4
lines changed

8 files changed

+120
-4
lines changed

pkg/dart2native/lib/dart2native.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ Future<ProcessResult> generateKernelHelper({
104104
final args = [
105105
sdk.genKernelSnapshot,
106106
'--platform=${product ? sdk.vmPlatformProductDill : sdk.vmPlatformDill}',
107-
if (product) '-Ddart.vm.product=true',
107+
'-Ddart.vm.product=$product',
108+
'-Ddart.vm.asan=${const bool.fromEnvironment("dart.vm.asan")}',
109+
'-Ddart.vm.msan=${const bool.fromEnvironment("dart.vm.msan")}',
110+
'-Ddart.vm.tsan=${const bool.fromEnvironment("dart.vm.tsan")}',
108111
if (enableExperiment.isNotEmpty) '--enable-experiment=$enableExperiment',
109112
if (targetOS != null) '--target-os=$targetOS',
110113
if (fromDill) '--from-dill=$sourceFile',

pkg/test_runner/lib/src/compiler_configuration.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,9 @@ abstract mixin class VMKernelCompilerMixin {
14451445
var dillFile = tempKernelFile(tempDir);
14461446

14471447
var isProductMode = _configuration.configuration.mode == Mode.product;
1448+
var isAsan = _configuration.configuration.sanitizer == Sanitizer.asan;
1449+
var isMsan = _configuration.configuration.sanitizer == Sanitizer.msan;
1450+
var isTsan = _configuration.configuration.sanitizer == Sanitizer.tsan;
14481451

14491452
var args = [
14501453
_isAot ? '--aot' : '--no-aot',
@@ -1459,6 +1462,9 @@ abstract mixin class VMKernelCompilerMixin {
14591462
name.startsWith('--enable-experiment=') ||
14601463
name.startsWith('--keep-class-names-implementing=')),
14611464
'-Ddart.vm.product=$isProductMode',
1465+
'-Ddart.vm.asan=$isAsan',
1466+
'-Ddart.vm.msan=$isMsan',
1467+
'-Ddart.vm.tsan=$isTsan',
14621468
if (_enableAsserts ||
14631469
arguments.contains('--enable-asserts') ||
14641470
arguments.contains('--enable_asserts'))
@@ -1609,6 +1615,9 @@ class BytecodeCompilerConfiguration extends CompilerConfiguration {
16091615
Map<String, String> environmentOverrides) {
16101616
final bytecodeFile = tempBytecodeFile(tempDir);
16111617
final isProductMode = _configuration.configuration.mode == Mode.product;
1618+
final isAsan = _configuration.configuration.sanitizer == Sanitizer.asan;
1619+
final isMsan = _configuration.configuration.sanitizer == Sanitizer.msan;
1620+
final isTsan = _configuration.configuration.sanitizer == Sanitizer.tsan;
16121621

16131622
final args = [
16141623
dart2bytecodeSnapshot(),
@@ -1622,6 +1631,9 @@ class BytecodeCompilerConfiguration extends CompilerConfiguration {
16221631
name.startsWith('--packages=') ||
16231632
name.startsWith('--enable-experiment=')),
16241633
'-Ddart.vm.product=$isProductMode',
1634+
'-Ddart.vm.asan=$isAsan',
1635+
'-Ddart.vm.msan=$isMsan',
1636+
'-Ddart.vm.tsan=$isTsan',
16251637
if (_enableAsserts ||
16261638
arguments.contains('--enable-asserts') ||
16271639
arguments.contains('--enable_asserts'))
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "dart:io";
6+
import "package:expect/expect.dart";
7+
8+
main() {
9+
print("new dart.vm.asan = ${new bool.fromEnvironment('dart.vm.asan')}");
10+
print("new dart.vm.msan = ${new bool.fromEnvironment('dart.vm.msan')}");
11+
print("new dart.vm.tsan = ${new bool.fromEnvironment('dart.vm.tsan')}");
12+
print("new dart.vm.product = ${new bool.fromEnvironment('dart.vm.product')}");
13+
print("const dart.vm.asan = ${const bool.fromEnvironment('dart.vm.asan')}");
14+
print("const dart.vm.msan = ${const bool.fromEnvironment('dart.vm.msan')}");
15+
print("const dart.vm.tsan = ${const bool.fromEnvironment('dart.vm.tsan')}");
16+
print(
17+
"const dart.vm.product = ${const bool.fromEnvironment('dart.vm.product')}",
18+
);
19+
20+
// From package:test_runner.
21+
print("DART_CONFIGURATION = ${Platform.environment['DART_CONFIGURATION']}");
22+
23+
Expect.equals(
24+
Platform.environment["DART_CONFIGURATION"]!.contains("ASAN"),
25+
new bool.fromEnvironment("dart.vm.asan"),
26+
"new dart.vm.asan",
27+
);
28+
Expect.equals(
29+
Platform.environment["DART_CONFIGURATION"]!.contains("MSAN"),
30+
new bool.fromEnvironment("dart.vm.msan"),
31+
"new dart.vm.msan",
32+
);
33+
Expect.equals(
34+
Platform.environment["DART_CONFIGURATION"]!.contains("TSAN"),
35+
new bool.fromEnvironment("dart.vm.tsan"),
36+
"new dart.vm.tsan",
37+
);
38+
Expect.equals(
39+
Platform.environment["DART_CONFIGURATION"]!.contains("Product"),
40+
new bool.fromEnvironment("dart.vm.product"),
41+
"new dart.vm.product",
42+
);
43+
44+
Expect.equals(
45+
Platform.environment["DART_CONFIGURATION"]!.contains("ASAN"),
46+
const bool.fromEnvironment("dart.vm.asan"),
47+
"const dart.vm.asan",
48+
);
49+
Expect.equals(
50+
Platform.environment["DART_CONFIGURATION"]!.contains("MSAN"),
51+
const bool.fromEnvironment("dart.vm.msan"),
52+
"const dart.vm.msan",
53+
);
54+
Expect.equals(
55+
Platform.environment["DART_CONFIGURATION"]!.contains("TSAN"),
56+
const bool.fromEnvironment("dart.vm.tsan"),
57+
"const dart.vm.tsan",
58+
);
59+
Expect.equals(
60+
Platform.environment["DART_CONFIGURATION"]!.contains("Product"),
61+
const bool.fromEnvironment("dart.vm.product"),
62+
"const dart.vm.product",
63+
);
64+
}

runtime/vm/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ template("gen_vm_platform") {
177177
args = [ "dart:core" ]
178178
args += [
179179
"-Ddart.vm.product=$is_product_flag",
180+
"-Ddart.vm.asan=$is_asan",
181+
"-Ddart.vm.msan=$is_msan",
182+
"-Ddart.vm.tsan=$is_tsan",
180183
"-Ddart.isVM=true",
181184
]
182185
if (defined(invoker.exclude_source) && invoker.exclude_source) {

runtime/vm/dart_api_impl.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
#include <utility>
1111

1212
#include "lib/stacktrace.h"
13+
#include "platform/address_sanitizer.h"
1314
#include "platform/assert.h"
15+
#include "platform/memory_sanitizer.h"
16+
#include "platform/thread_sanitizer.h"
1417
#include "platform/unicode.h"
1518
#include "vm/app_snapshot.h"
1619
#include "vm/bytecode_reader.h"
@@ -5415,6 +5418,30 @@ StringPtr Api::GetEnvironmentValue(Thread* thread, const String& name) {
54155418
#endif
54165419
}
54175420

5421+
if (name.Equals(Symbols::DartVMASAN())) {
5422+
#ifdef USING_ADDRESS_SANITIZER
5423+
return Symbols::True().ptr();
5424+
#else
5425+
return Symbols::False().ptr();
5426+
#endif
5427+
}
5428+
5429+
if (name.Equals(Symbols::DartVMMSAN())) {
5430+
#ifdef USING_MEMORY_SANITIZER
5431+
return Symbols::True().ptr();
5432+
#else
5433+
return Symbols::False().ptr();
5434+
#endif
5435+
}
5436+
5437+
if (name.Equals(Symbols::DartVMTSAN())) {
5438+
#ifdef USING_THREAD_SANITIZER
5439+
return Symbols::True().ptr();
5440+
#else
5441+
return Symbols::False().ptr();
5442+
#endif
5443+
}
5444+
54185445
if (name.Equals(Symbols::DartDeveloperTimeline())) {
54195446
#ifdef SUPPORT_TIMELINE
54205447
return Symbols::True().ptr();

runtime/vm/symbols.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class ObjectPointerVisitor;
7676
V(DartTypedData, "dart:typed_data") \
7777
V(DartVM, "dart:_vm") \
7878
V(DartVMProduct, "dart.vm.product") \
79+
V(DartVMASAN, "dart.vm.asan") \
80+
V(DartVMMSAN, "dart.vm.msan") \
81+
V(DartVMTSAN, "dart.vm.tsan") \
7982
V(DartVMService, "dart:_vmservice") \
8083
V(DebugProcedureName, ":Eval") \
8184
V(Default, "Default") \

utils/aot_snapshot.gni

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,13 @@ template("aot_snapshot") {
9292
# (Instead of ensuring every user of the "application_snapshot" /
9393
# "kernel_snapshot" passes this if needed, we always pass it)
9494
"-Dsdk_hash=$sdk_hash",
95+
"-Ddart.vm.product=$product_mode",
96+
"-Ddart.vm.asan=$is_asan",
97+
"-Ddart.vm.msan=$is_msan",
98+
"-Ddart.vm.tsan=$is_tsan",
9599
]
96100
args += gen_kernel_args
97101
args += [ rebase_path(main_dart, root_build_dir) ]
98-
if (product_mode) {
99-
args += [ "-Ddart.vm.product=true" ]
100-
}
101102
if (defined(invoker.args)) {
102103
args += invoker.args
103104
}

utils/application_snapshot.gni

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ template("application_snapshot") {
168168
# "kernel_snapshot" passes this if needed, we always pass it)
169169
"-Dsdk_hash=$sdk_hash",
170170
"-Ddart.vm.product=$is_product_flag",
171+
"-Ddart.vm.asan=$is_asan",
172+
"-Ddart.vm.msan=$is_msan",
173+
"-Ddart.vm.tsan=$is_tsan",
171174
]
172175
args += gen_kernel_args
173176
args += [ rebase_path(main_dart, root_build_dir) ]

0 commit comments

Comments
 (0)