Skip to content

Commit 7508d7f

Browse files
committed
Add memcpy override library for ARM + GPU use cases
b/277618912 show what appeared to be glibc's memcpy using unaligned accesses during command buffer recording which caused SIGBUSs on some Nvidia GPUs. This little stub library provides a memcpy override that can be be used via LD_PRELOAD. Bug: b/277618912 Bug: b/453027517 Test: (On ARM workstation) tools/buildutils/build_packages.sh sudo apt install ./cuttlefish-base_*.deb ./cuttlefish-user_*.deb sudo reboot cvd create --gpu_mode=gfxstream_guest_angle <play around with device for 5 minutes>
1 parent 705c349 commit 7508d7f

File tree

6 files changed

+108
-0
lines changed

6 files changed

+108
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package(
2+
default_visibility = [
3+
"@//:android_cuttlefish",
4+
],
5+
)
6+
7+
# Some of the `.h` and `.S` files are treated like `.inl` files.
8+
cc_library(
9+
name = "string_internal_textual_headers",
10+
includes = select({
11+
"@platforms//cpu:arm": ["string/arm"],
12+
"@platforms//cpu:aarch64": ["string/aarch64"],
13+
"@platforms//cpu:x86_64": ["string/x86_64"],
14+
"//conditions:default": [],
15+
}),
16+
textual_hdrs = select({
17+
"@platforms//cpu:arm": glob([
18+
"string/arm/*.h",
19+
"string/arm/*.S",
20+
]),
21+
"@platforms//cpu:aarch64": glob([
22+
"string/aarch64/*.h",
23+
"string/aarch64/*.S",
24+
]),
25+
"@platforms//cpu:x86_64": glob([
26+
"string/x86_64/*.S",
27+
]),
28+
"//conditions:default": [],
29+
}),
30+
visibility = ["//visibility:private"],
31+
)
32+
33+
cc_library(
34+
name = "string",
35+
srcs = select({
36+
"@platforms//cpu:arm": glob([
37+
"string/arm/*.c",
38+
"string/arm/*.S",
39+
]),
40+
"@platforms//cpu:aarch64": glob([
41+
"string/aarch64/*.S",
42+
]),
43+
"@platforms//cpu:x86_64": glob([
44+
"string/x86_64/*.S",
45+
]),
46+
"//conditions:default": [],
47+
}),
48+
hdrs = glob(["string/include/*.h"]),
49+
deps = [":string_internal_textual_headers"],
50+
includes = ["string/include"],
51+
)

base/cvd/MODULE.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,3 +769,11 @@ git_repository(
769769
commit = "f785e9275ee5ed85f98e7b850783ca0559ee1799",
770770
remote = "https://github.com/google/casimir",
771771
)
772+
773+
git_repository(
774+
name = "arm_optimized_routines",
775+
build_file = "@//:BUILD.arm_optimized_routines.bazel",
776+
commit = "3bc8091d03e002e25332fcbbd9a754538cb1109e",
777+
remote = "https://github.com/ARM-software/optimized-routines.git",
778+
)
779+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
load("//cuttlefish/bazel:rules.bzl", "cf_cc_binary")
2+
3+
package(
4+
default_visibility = ["//:android_cuttlefish"],
5+
)
6+
7+
cf_cc_binary(
8+
name = "libmem_overrides.so",
9+
srcs = select({
10+
"@platforms//cpu:arm64": [
11+
"mem_overrides.cpp",
12+
],
13+
"//conditions:default": [
14+
"mem_overrides_noop.cpp",
15+
],
16+
}),
17+
copts = [
18+
"-fPIC",
19+
],
20+
linkopts = [
21+
"-Wl,-no-undefined",
22+
],
23+
linkshared = 1,
24+
deps = select({
25+
"@platforms//cpu:arm64": [
26+
"@arm_optimized_routines//:string",
27+
],
28+
"//conditions:default": [],
29+
}),
30+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extern "C" {
2+
#include "string/include/stringlib.h"
3+
}
4+
5+
// b/277618912: glibc's aarch64 memcpy uses unaligned accesses which seems to
6+
// cause SIGBUS errors on some Nvidia GPUs. Override memcpy here:
7+
8+
void* memcpy(void* dest, const void* src, size_t n) {
9+
return __memcpy_aarch64(dest, src, n);
10+
}
11+
12+
void* memmove(void* dest, const void* src, size_t n) {
13+
return __memmove_aarch64(dest, src, n);
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Empty library to avoid some conditional `select()`s in `BUILD` files which
2+
// have trouble being modified by buildozer during automated imports:
3+
// https://github.com/bazelbuild/buildtools/issues/1421.

base/cvd/cuttlefish/package/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package_files(
88
"cuttlefish-common/bin/mmd": "cuttlefish-common/bin/mtools",
99
"cuttlefish-common/bin/resize.f2fs": "cuttlefish-common/bin/fsck.f2fs",
1010
"cuttlefish-common/bin/aarch64-linux-gnu/gfxstream_graphics_detector": "cuttlefish-common/bin/graphics_detector",
11+
"cuttlefish-common/bin/aarch64-linux-gnu/libmem_overrides.so": "cuttlefish-common/bin/libmem_overrides.so",
1112
"cuttlefish-common/bin/aarch64-linux-gnu/libvk_swiftshader.so": "cuttlefish-common/bin/libvk_swiftshader.so",
1213
"cuttlefish-common/bin/x86_64-linux-gnu/gfxstream_graphics_detector": "cuttlefish-common/bin/graphics_detector",
1314
"cuttlefish-common/lib64/vulkan.lvp.so": "cuttlefish-common/bin/libvk_lavapipe.so",
@@ -52,6 +53,7 @@ package_files(
5253
"cuttlefish-common/bin/graphics_detector": "//cuttlefish/host/graphics_detector",
5354
"cuttlefish-common/bin/health": "//cuttlefish/host/commands/health",
5455
"cuttlefish-common/bin/kernel_log_monitor": "//cuttlefish/host/commands/kernel_log_monitor",
56+
"cuttlefish-common/bin/libmem_overrides.so": "//cuttlefish/host/graphics/mem_overrides:libmem_overrides.so",
5557
"cuttlefish-common/bin/libgfxstream_backend.so": "@gfxstream//host:gfxstream_backend",
5658
"cuttlefish-common/bin/libvk_lavapipe.so": "@mesa//:vk_lavapipe",
5759
"cuttlefish-common/bin/libvk_swiftshader.so": "@swiftshader//:vk_swiftshader",

0 commit comments

Comments
 (0)