Skip to content

Commit

Permalink
Tell rustc that we will always be providing clangrt libraries
Browse files Browse the repository at this point in the history
This prevents rustc from trying to link sanitizer runtimes, so we don't
need to make fake ones in our sysroot anymore. And this avoids rustc
trying to link the Linux runtime when we're targeting Windows due to
rust-lang/rust#131363.

When this flag is specified, rustc avoids adding sanitizer libraries
here:
https://github.com/rust-lang/rust/blob/7caad6925314911eefe54b040d4bc5be940e8f92/compiler/rustc_codegen_ssa/src/back/link.rs#L1263-L1267

R=hans@chromium.org

Bug: 371512562
Cq-Include-Trybots: luci.chromium.try:win-asan,android-rust-arm32-rel,android-rust-arm64-dbg,android-rust-arm64-rel,linux-rust-x64-rel,linux-rust-x64-dbg,mac-rust-x64-dbg,win-rust-x64-dbg,win-rust-x64-rel,mac_chromium_asan_rel_ng,linux_chromium_asan_rel_ng
Change-Id: Ifcc6cb841af2697c6ca5ab3b64adcc995683fbc6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5913992
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: Arthur Eubanks <aeubanks@google.com>
Cr-Commit-Position: refs/heads/main@{#1365077}
NOKEYCHECK=True
GitOrigin-RevId: 7d029cad43d3bf03b0464d9e3c55cc0f8b5474e2
  • Loading branch information
danakj authored and copybara-github committed Oct 7, 2024
1 parent 884faaf commit 6ebc685
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 46 deletions.
3 changes: 3 additions & 0 deletions config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,9 @@ config("compiler") {
# For deterministic builds, keep the local machine's current working
# directory from appearing in build outputs.
"-Zremap-cwd-prefix=.",

# We use clang-rt sanitizer runtimes.
"-Zexternal-clangrt",
]

if (!is_win || force_rustc_color_output) {
Expand Down
46 changes: 0 additions & 46 deletions rust/std/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -236,51 +236,6 @@ if (toolchain_has_rust) {
visibility = [ ":*" ]
}

# When given -Zsanitize=..., rustc insists on passing a sanitizer runtime to
# the linker it invokes. Unfortunately, our C++ ldflags already tell the
# linker to link against a C++ sanitizer runtime - which contains the same
# symbols. So, make a blank library.
# The list of relevant sanitizers here is taken from
# https://github.com/rust-lang/rust/blob/7e7483d26e3cec7a44ef00cf7ae6c9c8c918bec6/compiler/rustc_codegen_ssa/src/back/link.rs#L1148
template("rustc_sanitizer_runtime") {
rt_name = target_name
not_needed([ "invoker" ])
static_library("sanitizer_rt_$rt_name") {
sources = []
output_name = "librustc-${rust_channel}_rt.$rt_name"
output_dir = "$local_rustc_sysroot/$sysroot_lib_subdir"
if (is_win) {
arflags = [ "/llvmlibempty" ]
}
}
}
rustc_sanitizer_runtimes = []
if (is_asan) {
rustc_sanitizer_runtime("asan") {
}
rustc_sanitizer_runtimes += [ ":sanitizer_rt_asan" ]
}
if (is_lsan) {
rustc_sanitizer_runtime("lsan") {
}
rustc_sanitizer_runtimes += [ ":sanitizer_rt_lsan" ]
}
if (is_msan) {
rustc_sanitizer_runtime("msan") {
}
rustc_sanitizer_runtimes += [ ":sanitizer_rt_msan" ]
}
if (is_tsan) {
rustc_sanitizer_runtime("tsan") {
}
rustc_sanitizer_runtimes += [ ":sanitizer_rt_tsan" ]
}
if (is_hwasan) {
rustc_sanitizer_runtime("hwasan") {
}
rustc_sanitizer_runtimes += [ ":sanitizer_rt_hwasan" ]
}

# Builds and links against the Rust stdlib. Both Rust and C++ targets should
# depend on this, as it provides the path to the library and includes the
# allocator hooks.
Expand All @@ -299,7 +254,6 @@ if (toolchain_has_rust) {
foreach(libname, stdlib_files + skip_stdlib_files) {
deps += [ "rules:$libname" ]
}
deps += rustc_sanitizer_runtimes

public_deps = [ ":remap_alloc" ]
}
Expand Down

0 comments on commit 6ebc685

Please sign in to comment.