Skip to content

Commit

Permalink
Merge pull request #1554 from rust-lang/fix_msvc_linker_hang
Browse files Browse the repository at this point in the history
Disable -Zfunction-sections by default on Windows
  • Loading branch information
bjorn3 authored Jan 14, 2025
2 parents a642651 + e7609d6 commit 6ef4582
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 6ef4582

Please sign in to comment.