Skip to content

Commit 6a8aae0

Browse files
sjindel-googlecommit-bot@chromium.org
authored andcommitted
[vm] Enable Dart VM to run in QEMU user-mode emulation for ARM.
Normally we consult /proc to determine the host architecture. However, this reports the actual host architecture, not the QEMU-simulated one. Also, GDB cannot debug position-independent executables in QEMU, so we disable PIE when compiling for execution in QEMU. Pass '--use-qemu' to 'gn.py' to build for QEMU. Change-Id: Ib125127ceb0582b66754cfc0da22e09d224ee1e9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125267 Commit-Queue: Samir Jindel <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent 1ae6f1b commit 6a8aae0

4 files changed

Lines changed: 25 additions & 3 deletions

File tree

build/config/BUILDCONFIG.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ declare_args() {
133133

134134
# Compile for Undefined Behavior Sanitizer to find reliance on undefined behavior.
135135
is_ubsan = false
136+
137+
# Compile for execution in user-mode QEMU.
138+
is_qemu = false
136139
}
137140

138141
# =============================================================================

build/config/linux/BUILD.gn

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import("//build/config/sysroot.gni")
66

77
config("sdk") {
88
ldflags = []
9+
cflags = []
910

1011
if (is_asan || is_lsan || is_msan || is_tsan || is_ubsan) {
1112
ldflags += [ "-lrt" ]
@@ -23,7 +24,7 @@ config("sdk") {
2324
}
2425

2526
if (sysroot != "") {
26-
cflags = [ "--sysroot=" + sysroot ]
27+
cflags += [ "--sysroot=" + sysroot ]
2728
ldflags += [ "--sysroot=" + sysroot ]
2829

2930
# Need to get some linker flags out of the sysroot.
@@ -44,10 +45,18 @@ config("sdk") {
4445
]
4546
}
4647
}
48+
49+
if (is_qemu) {
50+
cflags += ["-DDART_RUN_IN_QEMU_ARMv7"]
51+
}
4752
}
4853

4954
config("executable_config") {
50-
if (current_cpu != "x86") {
55+
# GDB cannot find the executable's mapping in QEMU when PIE is enabled.
56+
if (is_qemu) {
57+
cflags = [ "-fno-pie" ]
58+
ldflags = [ "-no-pie" ]
59+
} else if (current_cpu != "x86") {
5160
cflags = [ "-fPIE" ]
5261
ldflags = [ "-pie" ]
5362
}

runtime/vm/cpu_arm.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ void HostCPUFeatures::Init() {
175175
CpuInfo::FieldContains(kCpuInfoModel, "ARMv7")) {
176176
arm_version_ = ARMv7;
177177
} else {
178-
FATAL("Unsupported ARM CPU architecture.");
178+
#if defined(DART_RUN_IN_QEMU_ARMv7)
179+
arm_version_ = ARMv7;
180+
#else
181+
FATAL("Unrecognized ARM CPU architecture.");
182+
#endif
179183
}
180184

181185
// Has floating point unit.

tools/gn.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def ToGnArgs(args, mode, arch, target_os, use_nnbd):
247247
gn_args['is_tsan'] = args.tsan
248248
gn_args['is_ubsan'] = args.ubsan
249249
gn_args['include_dart2native'] = True
250+
gn_args['is_qemu'] = args.use_qemu
250251

251252
if not args.platform_sdk and not gn_args['target_cpu'].startswith('arm'):
252253
gn_args['dart_platform_sdk'] = args.platform_sdk
@@ -522,6 +523,11 @@ def parse_args(args):
522523
default=False,
523524
dest='use_crashpad',
524525
action='store_true')
526+
other_group.add_argument(
527+
'--use-qemu',
528+
default=False,
529+
dest='use_qemu',
530+
action='store_true')
525531

526532
options = parser.parse_args(args)
527533
if not ProcessOptions(options):

0 commit comments

Comments
 (0)