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...@@ -3973,6 +3973,16 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
3973 const id_symlink_basename = "stage1.id";3973 const id_symlink_basename = "stage1.id";
3974 const libs_txt_basename = "libs.txt";3974 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
3976 // We are about to obtain this lock, so here we give other processes a chance first.3986 // We are about to obtain this lock, so here we give other processes a chance first.
3977 comp.releaseStage1Lock();3987 comp.releaseStage1Lock();
39783988
...@@ -3994,7 +4004,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -3994,7 +4004,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
3994 man.hash.add(target.os.getVersionRange());4004 man.hash.add(target.os.getVersionRange());
3995 man.hash.add(comp.bin_file.options.dll_export_fns);4005 man.hash.add(comp.bin_file.options.dll_export_fns);
3996 man.hash.add(comp.bin_file.options.function_sections);4006 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);
3998 man.hash.add(comp.bin_file.options.is_test);4008 man.hash.add(comp.bin_file.options.is_test);
3999 man.hash.add(comp.bin_file.options.emit != null);4009 man.hash.add(comp.bin_file.options.emit != null);
4000 man.hash.add(mod.emit_h != null);4010 man.hash.add(mod.emit_h != null);
...@@ -4175,7 +4185,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -4175,7 +4185,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
4175 .valgrind_enabled = comp.bin_file.options.valgrind,4185 .valgrind_enabled = comp.bin_file.options.valgrind,
4176 .tsan_enabled = comp.bin_file.options.tsan,4186 .tsan_enabled = comp.bin_file.options.tsan,
4177 .function_sections = comp.bin_file.options.function_sections,4187 .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,
4179 .enable_stack_probing = comp.bin_file.options.stack_check,4189 .enable_stack_probing = comp.bin_file.options.stack_check,
4180 .red_zone = comp.bin_file.options.red_zone,4190 .red_zone = comp.bin_file.options.red_zone,
4181 .enable_time_report = comp.time_report,4191 .enable_time_report = comp.time_report,