about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-01-14 18:59:31 +0100
committerGitHub <noreply@github.com>2025-01-14 18:59:31 +0100
commit6ef458207f9ef16ac8c1e5c23eaff17e52ff2461 (patch)
tree8f4af2ad23734328ba167c8125199f32a796a9a1
parenta6426510a5097b5b5d90bde73cfcc4f78855e76f (diff)
parente7609d61e54e155c7394f9327e17c3c81511fa59 (diff)
downloadrust-6ef458207f9ef16ac8c1e5c23eaff17e52ff2461.tar.gz
rust-6ef458207f9ef16ac8c1e5c23eaff17e52ff2461.zip
Merge pull request #1554 from rust-lang/fix_msvc_linker_hang
Disable -Zfunction-sections by default on Windows
-rw-r--r--src/driver/aot.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/driver/aot.rs b/src/driver/aot.rs
index fe578e44770..7d5592daac1 100644
--- a/src/driver/aot.rs
+++ b/src/driver/aot.rs
@@ -333,9 +333,17 @@ fn make_module(sess: &Session, name: String) -> UnwindModule<ObjectModule> {
 
     let mut builder =
         ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();
+
+    // Disable function sections by default on MSVC as it causes significant slowdowns with link.exe.
+    // Maybe link.exe has exponential behavior when there are many sections with the same name? Also
+    // explicitly disable it on MinGW as rustc already disables it by default on MinGW and as such
+    // isn't tested. If rustc enables it in the future on MinGW, we can re-enable it too once it has
+    // been on MinGW.
+    let default_function_sections = sess.target.function_sections && !sess.target.is_like_windows;
     builder.per_function_section(
-        sess.opts.unstable_opts.function_sections.unwrap_or(sess.target.function_sections),
+        sess.opts.unstable_opts.function_sections.unwrap_or(default_function_sections),
     );
+
     UnwindModule::new(ObjectModule::new(builder), true)
 }