[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 <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak
2025-12-01 15:10:50 -08:00
committed by Commit Queue
parent 6b500b2517
commit 1d1527adf9
8 changed files with 120 additions and 4 deletions
+4 -1
View File
@@ -104,7 +104,10 @@ Future<ProcessResult> generateKernelHelper({
final args = [
sdk.genKernelSnapshot,
'--platform=${product ? sdk.vmPlatformProductDill : sdk.vmPlatformDill}',
if (product) '-Ddart.vm.product=true',
'-Ddart.vm.product=$product',
'-Ddart.vm.asan=${const bool.fromEnvironment("dart.vm.asan")}',
'-Ddart.vm.msan=${const bool.fromEnvironment("dart.vm.msan")}',
'-Ddart.vm.tsan=${const bool.fromEnvironment("dart.vm.tsan")}',
if (enableExperiment.isNotEmpty) '--enable-experiment=$enableExperiment',
if (targetOS != null) '--target-os=$targetOS',
if (fromDill) '--from-dill=$sourceFile',
@@ -1445,6 +1445,9 @@ abstract mixin class VMKernelCompilerMixin {
var dillFile = tempKernelFile(tempDir);
var isProductMode = _configuration.configuration.mode == Mode.product;
var isAsan = _configuration.configuration.sanitizer == Sanitizer.asan;
var isMsan = _configuration.configuration.sanitizer == Sanitizer.msan;
var isTsan = _configuration.configuration.sanitizer == Sanitizer.tsan;
var args = [
_isAot ? '--aot' : '--no-aot',
@@ -1459,6 +1462,9 @@ abstract mixin class VMKernelCompilerMixin {
name.startsWith('--enable-experiment=') ||
name.startsWith('--keep-class-names-implementing=')),
'-Ddart.vm.product=$isProductMode',
'-Ddart.vm.asan=$isAsan',
'-Ddart.vm.msan=$isMsan',
'-Ddart.vm.tsan=$isTsan',
if (_enableAsserts ||
arguments.contains('--enable-asserts') ||
arguments.contains('--enable_asserts'))
@@ -1609,6 +1615,9 @@ class BytecodeCompilerConfiguration extends CompilerConfiguration {
Map<String, String> environmentOverrides) {
final bytecodeFile = tempBytecodeFile(tempDir);
final isProductMode = _configuration.configuration.mode == Mode.product;
final isAsan = _configuration.configuration.sanitizer == Sanitizer.asan;
final isMsan = _configuration.configuration.sanitizer == Sanitizer.msan;
final isTsan = _configuration.configuration.sanitizer == Sanitizer.tsan;
final args = [
dart2bytecodeSnapshot(),
@@ -1622,6 +1631,9 @@ class BytecodeCompilerConfiguration extends CompilerConfiguration {
name.startsWith('--packages=') ||
name.startsWith('--enable-experiment=')),
'-Ddart.vm.product=$isProductMode',
'-Ddart.vm.asan=$isAsan',
'-Ddart.vm.msan=$isMsan',
'-Ddart.vm.tsan=$isTsan',
if (_enableAsserts ||
arguments.contains('--enable-asserts') ||
arguments.contains('--enable_asserts'))
@@ -0,0 +1,64 @@
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "dart:io";
import "package:expect/expect.dart";
main() {
print("new dart.vm.asan = ${new bool.fromEnvironment('dart.vm.asan')}");
print("new dart.vm.msan = ${new bool.fromEnvironment('dart.vm.msan')}");
print("new dart.vm.tsan = ${new bool.fromEnvironment('dart.vm.tsan')}");
print("new dart.vm.product = ${new bool.fromEnvironment('dart.vm.product')}");
print("const dart.vm.asan = ${const bool.fromEnvironment('dart.vm.asan')}");
print("const dart.vm.msan = ${const bool.fromEnvironment('dart.vm.msan')}");
print("const dart.vm.tsan = ${const bool.fromEnvironment('dart.vm.tsan')}");
print(
"const dart.vm.product = ${const bool.fromEnvironment('dart.vm.product')}",
);
// From package:test_runner.
print("DART_CONFIGURATION = ${Platform.environment['DART_CONFIGURATION']}");
Expect.equals(
Platform.environment["DART_CONFIGURATION"]!.contains("ASAN"),
new bool.fromEnvironment("dart.vm.asan"),
"new dart.vm.asan",
);
Expect.equals(
Platform.environment["DART_CONFIGURATION"]!.contains("MSAN"),
new bool.fromEnvironment("dart.vm.msan"),
"new dart.vm.msan",
);
Expect.equals(
Platform.environment["DART_CONFIGURATION"]!.contains("TSAN"),
new bool.fromEnvironment("dart.vm.tsan"),
"new dart.vm.tsan",
);
Expect.equals(
Platform.environment["DART_CONFIGURATION"]!.contains("Product"),
new bool.fromEnvironment("dart.vm.product"),
"new dart.vm.product",
);
Expect.equals(
Platform.environment["DART_CONFIGURATION"]!.contains("ASAN"),
const bool.fromEnvironment("dart.vm.asan"),
"const dart.vm.asan",
);
Expect.equals(
Platform.environment["DART_CONFIGURATION"]!.contains("MSAN"),
const bool.fromEnvironment("dart.vm.msan"),
"const dart.vm.msan",
);
Expect.equals(
Platform.environment["DART_CONFIGURATION"]!.contains("TSAN"),
const bool.fromEnvironment("dart.vm.tsan"),
"const dart.vm.tsan",
);
Expect.equals(
Platform.environment["DART_CONFIGURATION"]!.contains("Product"),
const bool.fromEnvironment("dart.vm.product"),
"const dart.vm.product",
);
}
+3
View File
@@ -177,6 +177,9 @@ template("gen_vm_platform") {
args = [ "dart:core" ]
args += [
"-Ddart.vm.product=$is_product_flag",
"-Ddart.vm.asan=$is_asan",
"-Ddart.vm.msan=$is_msan",
"-Ddart.vm.tsan=$is_tsan",
"-Ddart.isVM=true",
]
if (defined(invoker.exclude_source) && invoker.exclude_source) {
+27
View File
@@ -10,7 +10,10 @@
#include <utility>
#include "lib/stacktrace.h"
#include "platform/address_sanitizer.h"
#include "platform/assert.h"
#include "platform/memory_sanitizer.h"
#include "platform/thread_sanitizer.h"
#include "platform/unicode.h"
#include "vm/app_snapshot.h"
#include "vm/bytecode_reader.h"
@@ -5415,6 +5418,30 @@ StringPtr Api::GetEnvironmentValue(Thread* thread, const String& name) {
#endif
}
if (name.Equals(Symbols::DartVMASAN())) {
#ifdef USING_ADDRESS_SANITIZER
return Symbols::True().ptr();
#else
return Symbols::False().ptr();
#endif
}
if (name.Equals(Symbols::DartVMMSAN())) {
#ifdef USING_MEMORY_SANITIZER
return Symbols::True().ptr();
#else
return Symbols::False().ptr();
#endif
}
if (name.Equals(Symbols::DartVMTSAN())) {
#ifdef USING_THREAD_SANITIZER
return Symbols::True().ptr();
#else
return Symbols::False().ptr();
#endif
}
if (name.Equals(Symbols::DartDeveloperTimeline())) {
#ifdef SUPPORT_TIMELINE
return Symbols::True().ptr();
+3
View File
@@ -76,6 +76,9 @@ class ObjectPointerVisitor;
V(DartTypedData, "dart:typed_data") \
V(DartVM, "dart:_vm") \
V(DartVMProduct, "dart.vm.product") \
V(DartVMASAN, "dart.vm.asan") \
V(DartVMMSAN, "dart.vm.msan") \
V(DartVMTSAN, "dart.vm.tsan") \
V(DartVMService, "dart:_vmservice") \
V(DebugProcedureName, ":Eval") \
V(Default, "Default") \
+4 -3
View File
@@ -92,12 +92,13 @@ template("aot_snapshot") {
# (Instead of ensuring every user of the "application_snapshot" /
# "kernel_snapshot" passes this if needed, we always pass it)
"-Dsdk_hash=$sdk_hash",
"-Ddart.vm.product=$product_mode",
"-Ddart.vm.asan=$is_asan",
"-Ddart.vm.msan=$is_msan",
"-Ddart.vm.tsan=$is_tsan",
]
args += gen_kernel_args
args += [ rebase_path(main_dart, root_build_dir) ]
if (product_mode) {
args += [ "-Ddart.vm.product=true" ]
}
if (defined(invoker.args)) {
args += invoker.args
}
+3
View File
@@ -168,6 +168,9 @@ template("application_snapshot") {
# "kernel_snapshot" passes this if needed, we always pass it)
"-Dsdk_hash=$sdk_hash",
"-Ddart.vm.product=$is_product_flag",
"-Ddart.vm.asan=$is_asan",
"-Ddart.vm.msan=$is_msan",
"-Ddart.vm.tsan=$is_tsan",
]
args += gen_kernel_args
args += [ rebase_path(main_dart, root_build_dir) ]