| ... | @@ -544,6 +544,7 @@ pub const InitOptions = struct { | ... | @@ -544,6 +544,7 @@ pub const InitOptions = struct { |
| 544 | system_libs: []const []const u8 = &[0][]const u8{}, | 544 | system_libs: []const []const u8 = &[0][]const u8{}, |
| 545 | link_libc: bool = false, | 545 | link_libc: bool = false, |
| 546 | link_libcpp: bool = false, | 546 | link_libcpp: bool = false, |
| | 547 | link_libunwind: bool = false, |
| 547 | want_pic: ?bool = null, | 548 | want_pic: ?bool = null, |
| 548 | /// This means that if the output mode is an executable it will be a | 549 | /// This means that if the output mode is an executable it will be a |
| 549 | /// Position Independent Executable. If the output mode is not an | 550 | /// Position Independent Executable. If the output mode is not an |
| ... | @@ -791,8 +792,13 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -791,8 +792,13 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 791 | }; | 792 | }; |
| 792 | | 793 | |
| 793 | const tsan = options.want_tsan orelse false; | 794 | const tsan = options.want_tsan orelse false; |
| | 795 | // TSAN is implemented in C++ so it requires linking libc++. |
| | 796 | const link_libcpp = options.link_libcpp or tsan; |
| | 797 | const link_libc = link_libcpp or options.link_libc or |
| | 798 | target_util.osRequiresLibC(options.target); |
| 794 | | 799 | |
| 795 | const link_libc = options.link_libc or target_util.osRequiresLibC(options.target) or tsan; | 800 | const link_libunwind = options.link_libunwind or |
| | 801 | (link_libcpp and target_util.libcNeedsLibUnwind(options.target)); |
| 796 | | 802 | |
| 797 | const must_dynamic_link = dl: { | 803 | const must_dynamic_link = dl: { |
| 798 | if (target_util.cannotDynamicLink(options.target)) | 804 | if (target_util.cannotDynamicLink(options.target)) |
| ... | @@ -878,9 +884,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -878,9 +884,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 878 | break :pic explicit; | 884 | break :pic explicit; |
| 879 | } else pie or must_pic; | 885 | } else pie or must_pic; |
| 880 | | 886 | |
| 881 | // TSAN is implemented in C++ so it requires linking libc++. | | |
| 882 | const link_libcpp = options.link_libcpp or tsan; | | |
| 883 | | | |
| 884 | // Make a decision on whether to use Clang for translate-c and compiling C files. | 887 | // Make a decision on whether to use Clang for translate-c and compiling C files. |
| 885 | const use_clang = if (options.use_clang) |explicit| explicit else blk: { | 888 | const use_clang = if (options.use_clang) |explicit| explicit else blk: { |
| 886 | if (build_options.have_llvm) { | 889 | if (build_options.have_llvm) { |
| ... | @@ -973,6 +976,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -973,6 +976,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 973 | cache.hash.add(strip); | 976 | cache.hash.add(strip); |
| 974 | cache.hash.add(link_libc); | 977 | cache.hash.add(link_libc); |
| 975 | cache.hash.add(link_libcpp); | 978 | cache.hash.add(link_libcpp); |
| | 979 | cache.hash.add(link_libunwind); |
| 976 | cache.hash.add(options.output_mode); | 980 | cache.hash.add(options.output_mode); |
| 977 | cache.hash.add(options.machine_code_model); | 981 | cache.hash.add(options.machine_code_model); |
| 978 | cache.hash.addOptionalEmitLoc(options.emit_bin); | 982 | cache.hash.addOptionalEmitLoc(options.emit_bin); |
| ... | @@ -1157,6 +1161,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1157,6 +1161,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1157 | .system_linker_hack = darwin_options.system_linker_hack, | 1161 | .system_linker_hack = darwin_options.system_linker_hack, |
| 1158 | .link_libc = link_libc, | 1162 | .link_libc = link_libc, |
| 1159 | .link_libcpp = link_libcpp, | 1163 | .link_libcpp = link_libcpp, |
| | 1164 | .link_libunwind = link_libunwind, |
| 1160 | .objects = options.link_objects, | 1165 | .objects = options.link_objects, |
| 1161 | .frameworks = options.frameworks, | 1166 | .frameworks = options.frameworks, |
| 1162 | .framework_dirs = options.framework_dirs, | 1167 | .framework_dirs = options.framework_dirs, |
| ... | @@ -3022,9 +3027,7 @@ fn wantBuildLibUnwindFromSource(comp: *Compilation) bool { | ... | @@ -3022,9 +3027,7 @@ fn wantBuildLibUnwindFromSource(comp: *Compilation) bool { |
| 3022 | .Lib => comp.bin_file.options.link_mode == .Dynamic, | 3027 | .Lib => comp.bin_file.options.link_mode == .Dynamic, |
| 3023 | .Exe => true, | 3028 | .Exe => true, |
| 3024 | }; | 3029 | }; |
| 3025 | return comp.bin_file.options.link_libc and is_exe_or_dyn_lib and | 3030 | return is_exe_or_dyn_lib and comp.bin_file.options.link_libunwind; |
| 3026 | comp.bin_file.options.link_libcpp and | | |
| 3027 | target_util.libcNeedsLibUnwind(comp.getTarget()); | | |
| 3028 | } | 3031 | } |
| 3029 | | 3032 | |
| 3030 | fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) Allocator.Error!void { | 3033 | fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) Allocator.Error!void { |