authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-22 18:12:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-22 19:51:32-07:00
log80ba9f060d81e8c5674acb4eb07c833d26121462
tree92b3138a76cdf0a3befc721229501e286e7d5035
parent7c25390c957273ff43927608a45e257c4ed73549

fix double linking of compiler-rt symbols on wasm

The include_compiler_rt stored in the bin file options means that we need compiler-rt symbols *somehow*. However, in the context of using the stage1 backend we need to tell stage1 to include compiler-rt only if stage1 is the place that needs to provide those symbols. Otherwise the stage2 infrastructure will take care of it in the linker, by putting compiler_rt.o into a static archive, or linking compiler_rt.a against an executable. In other words we only want to set this flag for stage1 if we are using build-obj.

1 files changed, 12 insertions(+), 2 deletions(-)

src/Compilation.zig+12-2
......@@ -3973,6 +3973,16 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
39733973 const id_symlink_basename = "stage1.id";
39743974 const libs_txt_basename = "libs.txt";
39753975
3976 // The include_compiler_rt stored in the bin file options here means that we need
3977 // compiler-rt symbols *somehow*. However, in the context of using the stage1 backend
3978 // we need to tell stage1 to include compiler-rt only if stage1 is the place that
3979 // needs to provide those symbols. Otherwise the stage2 infrastructure will take care
3980 // of it in the linker, by putting compiler_rt.o into a static archive, or linking
3981 // compiler_rt.a against an executable. In other words we only want to set this flag
3982 // for stage1 if we are using build-obj.
3983 const include_compiler_rt = comp.bin_file.options.output_mode == .Obj and
3984 comp.bin_file.options.include_compiler_rt;
3985
39763986 // We are about to obtain this lock, so here we give other processes a chance first.
39773987 comp.releaseStage1Lock();
39783988
......@@ -3994,7 +4004,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
39944004 man.hash.add(target.os.getVersionRange());
39954005 man.hash.add(comp.bin_file.options.dll_export_fns);
39964006 man.hash.add(comp.bin_file.options.function_sections);
3997 man.hash.add(comp.bin_file.options.include_compiler_rt);
4007 man.hash.add(include_compiler_rt);
39984008 man.hash.add(comp.bin_file.options.is_test);
39994009 man.hash.add(comp.bin_file.options.emit != null);
40004010 man.hash.add(mod.emit_h != null);
......@@ -4175,7 +4185,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
41754185 .valgrind_enabled = comp.bin_file.options.valgrind,
41764186 .tsan_enabled = comp.bin_file.options.tsan,
41774187 .function_sections = comp.bin_file.options.function_sections,
4178 .include_compiler_rt = comp.bin_file.options.include_compiler_rt,
4188 .include_compiler_rt = include_compiler_rt,
41794189 .enable_stack_probing = comp.bin_file.options.stack_check,
41804190 .red_zone = comp.bin_file.options.red_zone,
41814191 .enable_time_report = comp.time_report,