From 2f6f2b258484e07947bc36e91698eb8f14df3718 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Fri, 18 Oct 2024 12:00:07 +0200 Subject: [PATCH] Do not pass -lc to the Emscripten linker Hack: drop -lc to work around buggy Emscripten behaviors when -lc is passed. This can be removed when the problems are resolved in Emscripten and we drop support for the currently existing versions of Emscripten. See https://github.com/emscripten-core/emscripten/issues/22758 Unblocks https://github.com/rust-lang/rust/pull/131736 --- compiler/rustc_codegen_ssa/src/back/linker.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index c4bb82d0dd7b1..d1e6c7ed6bf81 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -1159,6 +1159,21 @@ impl<'a> Linker for EmLinker<'a> { } fn link_staticlib_by_name(&mut self, name: &str, _verbatim: bool, _whole_archive: bool) { + if name == "c" { + // Hack: drop -lc to work around buggy Emscripten behaviors when -lc + // is passed. See + // https://github.com/emscripten-core/emscripten/issues/22758 + // + // Question: Does this bug affect any other libraries? Why this + // special case for libc? + // + // Answer: We think it's specific to libc. Emscripten can link + // binaries with many different ABIs and it has to build an + // appropriate libc depending on the target ABI. Passing -lc + // explicitly causes bugs in this process. If we find out other + // libraries are affected, we can reevaluate this approach. + return; + } self.link_or_cc_args(&["-l", name]); }