Skip to content

Commit 2f6f2b2

Browse files
committed
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 emscripten-core/emscripten#22758 Unblocks #131736
1 parent 06d261d commit 2f6f2b2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,21 @@ impl<'a> Linker for EmLinker<'a> {
11591159
}
11601160

11611161
fn link_staticlib_by_name(&mut self, name: &str, _verbatim: bool, _whole_archive: bool) {
1162+
if name == "c" {
1163+
// Hack: drop -lc to work around buggy Emscripten behaviors when -lc
1164+
// is passed. See
1165+
// https://github.com/emscripten-core/emscripten/issues/22758
1166+
//
1167+
// Question: Does this bug affect any other libraries? Why this
1168+
// special case for libc?
1169+
//
1170+
// Answer: We think it's specific to libc. Emscripten can link
1171+
// binaries with many different ABIs and it has to build an
1172+
// appropriate libc depending on the target ABI. Passing -lc
1173+
// explicitly causes bugs in this process. If we find out other
1174+
// libraries are affected, we can reevaluate this approach.
1175+
return;
1176+
}
11621177
self.link_or_cc_args(&["-l", name]);
11631178
}
11641179

0 commit comments

Comments
 (0)