Skip to content

Commit 52f47da

Browse files
rmacnak-googledart-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
Setup Android sanitizer builders.
- Fix leak of compressed heap address space for non-Fuchsia compressed pointers - Fix TSAN with compressed pointers TEST=ci Bug: flutter/flutter#188507 Bug: #63699 Change-Id: I160f9920c764a3d0686b735c44c1da7bc85b7179 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/518400 Reviewed-by: Alexander Aprelev <aam@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
1 parent a245f98 commit 52f47da

7 files changed

Lines changed: 101 additions & 22 deletions

File tree

build/config/compiler/BUILD.gn

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,6 @@ config("compiler") {
389389
"-funwind-tables",
390390
"-fno-short-enums",
391391
]
392-
if (is_asan) {
393-
# Android build relies on -Wl,--gc-sections removing unreachable code.
394-
# ASan instrumentation for globals inhibits this and results in a library
395-
# with unresolvable relocations.
396-
# TODO(eugenis): find a way to reenable this.
397-
cflags += [ "-mllvm -asan-globals=0" ]
398-
}
399392

400393
defines += [ "ANDROID" ]
401394

@@ -643,9 +636,7 @@ if (is_win) {
643636
"-Wno-unused-value", # crashpad
644637
"-Wno-deprecated-non-prototype", # zlib
645638
]
646-
default_warning_flags_cc += [
647-
"-Wno-microsoft-unqualified-friend",
648-
]
639+
default_warning_flags_cc += [ "-Wno-microsoft-unqualified-friend" ]
649640
} else {
650641
default_warning_flags += [
651642
# Permanent.
@@ -795,7 +786,11 @@ config("no_rtti") {
795786
if (is_win) {
796787
cflags_cc = [ "/GR-" ]
797788
} else {
798-
rtti_flags = [ "-fno-rtti" ]
789+
if (is_android && is_asan) {
790+
rtti_flags = [ "-frtti" ]
791+
} else {
792+
rtti_flags = [ "-fno-rtti" ]
793+
}
799794
cflags_cc = rtti_flags
800795
cflags_objcc = rtti_flags
801796
}

pkg/test_runner/lib/src/process_queue.dart

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,26 @@ class CommandExecutorImpl implements CommandExecutor {
658658
return steps;
659659
}
660660

661+
static final _compilerRT = {
662+
'ASANX64': 'libclang_rt.asan-x86_64-android.so',
663+
'HWASANX64': 'libclang_rt.hwasan-x86_64-android.so',
664+
'TSANX64': 'libclang_rt.tsan-x86_64-android.so',
665+
'LSANX64': 'libclang_rt.lsan-x86_64-android.so',
666+
'UBSANX64': 'libclang_rt.ubsan_standalone-x86_64-android.so',
667+
668+
'ASANARM64': 'libclang_rt.asan-aarch64-android.so',
669+
'HWASANARM64': 'libclang_rt.hwasan-aarch64-android.so',
670+
'TSANARM64': 'libclang_rt.tsan-aarch64-android.so',
671+
'LSANARM64': 'libclang_rt.lsan-aarch64-android.so',
672+
'UBSANARM64': 'libclang_rt.ubsan_standalone-aarch64-android.so',
673+
674+
'ASANRISCV64': 'libclang_rt.asan-riscv64-android.so',
675+
'HWASANRISCV64': 'libclang_rt.hwasan-riscv64-android.so',
676+
'TSANRISCV64': 'libclang_rt.tsan-riscv64-android.so',
677+
'LSANRISCV64': 'libclang_rt.lsan-riscv64-android.so',
678+
'UBSANRISCV64': 'libclang_rt.ubsan_standalone-riscv64-android.so',
679+
};
680+
661681
Future<CommandOutput> _runAdbPrecompilationCommand(
662682
AdbDevice device,
663683
AdbPrecompilationCommand command,
@@ -687,6 +707,16 @@ class CommandExecutorImpl implements CommandExecutor {
687707

688708
steps.add(() => device.runAdbShellCommand(['rm', '-Rf', deviceTestDir]));
689709
steps.add(() => device.runAdbShellCommand(['mkdir', '-p', deviceTestDir]));
710+
_compilerRT.forEach((k, v) {
711+
if (buildPath.contains(k)) {
712+
steps.add(
713+
() => device.pushCachedData(
714+
'./third_party/android_tools/ndk/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/19/lib/linux/$v',
715+
'$deviceDir/$v',
716+
),
717+
);
718+
}
719+
});
690720
steps.add(
691721
() => device.pushCachedData(
692722
'$buildPath/exe.stripped/dartaotruntime',
@@ -730,7 +760,7 @@ class CommandExecutorImpl implements CommandExecutor {
730760

731761
steps.add(
732762
() => device.runAdbShellCommand([
733-
'export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$deviceTestDir;'
763+
'export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$deviceTestDir:$deviceDir;'
734764
'export TEST_COMPILATION_DIR=$deviceTestDir;'
735765
'$deviceDir/dartaotruntime',
736766
'--android-log-to-stderr',
@@ -806,6 +836,16 @@ class CommandExecutorImpl implements CommandExecutor {
806836

807837
steps.add(() => device.runAdbShellCommand(['rm', '-Rf', deviceTestDir]));
808838
steps.add(() => device.runAdbShellCommand(['mkdir', '-p', deviceTestDir]));
839+
_compilerRT.forEach((k, v) {
840+
if (buildPath.contains(k)) {
841+
steps.add(
842+
() => device.pushCachedData(
843+
'./third_party/android_tools/ndk/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/19/lib/linux/$v',
844+
'$deviceDir/$v',
845+
),
846+
);
847+
}
848+
});
809849
steps.add(
810850
() => device.pushCachedData('$buildPath/dartvm', '$deviceDir/dartvm'),
811851
);
@@ -827,7 +867,7 @@ class CommandExecutorImpl implements CommandExecutor {
827867

828868
steps.add(
829869
() => device.runAdbShellCommand([
830-
'export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$deviceTestDir;'
870+
'export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$deviceTestDir:$deviceDir;'
831871
'$deviceDir/dartvm',
832872
'--android-log-to-stderr',
833873
...arguments,

runtime/vm/compiler/assembler/assembler_arm64.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ void Assembler::TsanLoadAcquire(Register dst, Register addr, OperandSize size) {
304304
ldr(TMP, compiler::Address(
305305
THR, kTsanAtomic64LoadRuntimeEntry.OffsetFromThread()));
306306
break;
307+
case kFourBytes:
307308
case kUnsignedFourBytes:
308309
ldr(TMP, compiler::Address(
309310
THR, kTsanAtomic32LoadRuntimeEntry.OffsetFromThread()));
@@ -317,7 +318,7 @@ void Assembler::TsanLoadAcquire(Register dst, Register addr, OperandSize size) {
317318
str(TMP, compiler::Address(THR, target::Thread::vm_tag_offset()));
318319
SetupCSPFromThread(THR);
319320

320-
MoveRegister(dst, R0);
321+
ExtendValue(dst, R0, size);
321322

322323
AddImmediate(SP, FP, -registers.SpillSize());
323324
PopRegisters(registers);

runtime/vm/compiler/assembler/assembler_x64.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,7 @@ void Assembler::TsanLoadAcquire(Register dst, Address addr, OperandSize size) {
21692169
movq(RAX, compiler::Address(
21702170
THR, kTsanAtomic64LoadRuntimeEntry.OffsetFromThread()));
21712171
break;
2172+
case kFourBytes:
21722173
case kUnsignedFourBytes:
21732174
movq(RAX, compiler::Address(
21742175
THR, kTsanAtomic32LoadRuntimeEntry.OffsetFromThread()));
@@ -2182,7 +2183,7 @@ void Assembler::TsanLoadAcquire(Register dst, Address addr, OperandSize size) {
21822183
movq(compiler::Assembler::VMTagAddress(),
21832184
compiler::Immediate(VMTag::kDartTagId));
21842185

2185-
MoveRegister(dst, RAX);
2186+
ExtendValue(dst, RAX, size);
21862187

21872188
// RSP might have been modified to reserve space for arguments
21882189
// and ensure proper alignment of the stack frame.

runtime/vm/virtual_memory_compressed.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Cage::~Cage() {
170170
size_ = 0;
171171
pages_ = nullptr;
172172
minimum_free_page_id_ = 0;
173+
delete reservation_;
173174
}
174175

175176
void* Cage::GetRegion() {

tools/bots/test_matrix.json

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,23 @@
368368
"gen-snapshot-format": "elf"
369369
}
370370
},
371-
"vm-asan-(fuchsia|linux|mac|win)-(debug|product|release)-(ia32|x64|arm64|simarm|simarm64|simriscv32|simriscv64)": {},
371+
"vm-(asan|hwasan|lsan|tsan|ubsan)-android-(debug|product|release)-(x64|x64c|arm64|arm64c)": {},
372+
"vm-aot-(asan|hwasan|lsan|tsan|ubsan)-android-(debug|product|release)-(x64|x64c|arm64|arm64c)": {
373+
"options": {
374+
"gen-snapshot-format": "elf"
375+
}
376+
},
377+
"vm-asan-(fuchsia|linux|mac|win)-(debug|product|release)-(ia32|x64|x64c|arm64|arm64c|simarm|simarm64|simriscv32|simriscv64)": {},
372378
"vm-lsan-(linux|mac)-(debug|product|release)-(ia32|x64|arm64|simarm|simarm64|simriscv32|simriscv64)": {},
373379
"vm-msan-linux-(debug|product|release)-(x64|arm64|simarm64|simriscv64)": {},
374-
"vm-tsan-(linux|mac)-(debug|product|release)-(x64|arm64|simarm64|simriscv64)": {},
375-
"vm-ubsan-(fuchsia|linux|mac|win)-(debug|product|release)-(ia32|x64|arm64|simarm|simarm64|simriscv32|simriscv64)": {},
380+
"vm-tsan-(linux|mac)-(debug|product|release)-(x64|x64c|arm64|arm64c|simarm64|simriscv64)": {},
381+
"vm-ubsan-(fuchsia|linux|mac|win)-(debug|product|release)-(ia32|x64|x64c|arm64|arm64c|simarm|simarm64|simriscv32|simriscv64)": {},
376382
"vm-aot-(asan|lsan|tsan|ubsan)-mac-(debug|product|release)-(x64|arm64|simarm64)": {
377383
"options": {
378384
"gen-snapshot-format": "macho-dylib"
379385
}
380386
},
381-
"vm-aot-asan-(fuchsia|linux|win)-(debug|product|release)-(x64|arm64|simarm|simarm64|simriscv32|simriscv64)": {
387+
"vm-aot-asan-(fuchsia|linux|win)-(debug|product|release)-(x64|x64c|arm64|arm64c|simarm|simarm64|simriscv32|simriscv64)": {
382388
"options": {
383389
"gen-snapshot-format": "elf"
384390
}
@@ -393,12 +399,12 @@
393399
"gen-snapshot-format": "elf"
394400
}
395401
},
396-
"vm-aot-tsan-linux-(debug|product|release)-(x64|arm64|simarm64|simriscv64)": {
402+
"vm-aot-tsan-linux-(debug|product|release)-(x64|x64c|arm64|arm64c|simarm64|simriscv64)": {
397403
"options": {
398404
"gen-snapshot-format": "elf"
399405
}
400406
},
401-
"vm-aot-ubsan-(fuchsia|linux|win)-(debug|product|release)-(x64|arm64|simarm|simarm64|simriscv32|simriscv64)": {
407+
"vm-aot-ubsan-(fuchsia|linux|win)-(debug|product|release)-(x64|x64c|arm64|arm64c|simarm|simarm64|simriscv32|simriscv64)": {
402408
"options": {
403409
"gen-snapshot-format": "elf"
404410
}
@@ -864,6 +870,41 @@
864870
}
865871
]
866872
},
873+
{
874+
"builders": [
875+
"vm-hwasan-android-release-x64c",
876+
"vm-ubsan-android-release-x64c"
877+
],
878+
"meta": {
879+
"description": "This configuration is used by the vm precomp builders on Android."
880+
},
881+
"steps": [
882+
{
883+
"name": "build dart",
884+
"script": "tools/build.py",
885+
"arguments": [
886+
"--os=android",
887+
"android_bot"
888+
]
889+
},
890+
{
891+
"name": "vm jit tests",
892+
"arguments": [
893+
"-nvm-${sanitizer}-android-${mode}-${arch}",
894+
"ffi",
895+
"standalone/io/"
896+
]
897+
},
898+
{
899+
"name": "vm aot tests",
900+
"arguments": [
901+
"-nvm-aot-${sanitizer}-android-${mode}-${arch}",
902+
"ffi",
903+
"standalone/io/"
904+
]
905+
}
906+
]
907+
},
867908
{
868909
"builders": [
869910
"vm-aot-android-debug-arm64c",

tools/task_kill.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def Main():
320320
if options.kill_browsers == 'True':
321321
status += KillBrowsers()
322322
if options.kill_android == 'True':
323-
status += KillAndroid()
323+
status += KillAndroidEmulator()
324324
return status
325325

326326

0 commit comments

Comments
 (0)