| author | |
| committer | |
| log | 826179bff40fdbd8c3b11138897fcfbb3367def8 |
| tree | 23fcdea829179045785ac4303a3e694cc7e12170 |
| parent | 76a259799d5bac3effabd1df44c0dec9e4fa16d4 |
* `-lc++` now implies `-lc`.
* `-lunwind` is now pulled out into a separate `link_libunwind` flag in
the frontend driver code. This allows a project to request zig to
provide libunwind even if the default situation that causes it to be
implicitly added, is not active.
* build.zig: ask for -lunwind when building the self-hosted compiler on
Linux. Otherwise we get linker errors with unresolved symbols to
libunwind.5 files changed, 24 insertions(+), 12 deletions(-)
build.zig+1-2| ... | ... | @@ -397,8 +397,7 @@ fn addCmakeCfgOptionsToExe( |
| 397 | 397 | }, |
| 398 | 398 | else => |e| return e, |
| 399 | 399 | }; |
| 400 | ||
| 401 | exe.linkSystemLibrary("pthread"); | |
| 400 | exe.linkSystemLibrary("unwind"); | |
| 402 | 401 | } else if (exe.target.isFreeBSD()) { |
| 403 | 402 | try addCxxKnownPath(b, cfg, exe, "libc++.a", null, need_cpp_includes); |
| 404 | 403 | exe.linkSystemLibrary("pthread"); |
src/Compilation.zig+10-7| ... | ... | @@ -544,6 +544,7 @@ pub const InitOptions = struct { |
| 544 | 544 | system_libs: []const []const u8 = &[0][]const u8{}, |
| 545 | 545 | link_libc: bool = false, |
| 546 | 546 | link_libcpp: bool = false, |
| 547 | link_libunwind: bool = false, | |
| 547 | 548 | want_pic: ?bool = null, |
| 548 | 549 | /// This means that if the output mode is an executable it will be a |
| 549 | 550 | /// Position Independent Executable. If the output mode is not an |
| ... | ... | @@ -791,8 +792,13 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 791 | 792 | }; |
| 792 | 793 | |
| 793 | 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 | 803 | const must_dynamic_link = dl: { |
| 798 | 804 | if (target_util.cannotDynamicLink(options.target)) |
| ... | ... | @@ -878,9 +884,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 878 | 884 | break :pic explicit; |
| 879 | 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 | 887 | // Make a decision on whether to use Clang for translate-c and compiling C files. |
| 885 | 888 | const use_clang = if (options.use_clang) |explicit| explicit else blk: { |
| 886 | 889 | if (build_options.have_llvm) { |
| ... | ... | @@ -973,6 +976,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 973 | 976 | cache.hash.add(strip); |
| 974 | 977 | cache.hash.add(link_libc); |
| 975 | 978 | cache.hash.add(link_libcpp); |
| 979 | cache.hash.add(link_libunwind); | |
| 976 | 980 | cache.hash.add(options.output_mode); |
| 977 | 981 | cache.hash.add(options.machine_code_model); |
| 978 | 982 | cache.hash.addOptionalEmitLoc(options.emit_bin); |
| ... | ... | @@ -1157,6 +1161,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1157 | 1161 | .system_linker_hack = darwin_options.system_linker_hack, |
| 1158 | 1162 | .link_libc = link_libc, |
| 1159 | 1163 | .link_libcpp = link_libcpp, |
| 1164 | .link_libunwind = link_libunwind, | |
| 1160 | 1165 | .objects = options.link_objects, |
| 1161 | 1166 | .frameworks = options.frameworks, |
| 1162 | 1167 | .framework_dirs = options.framework_dirs, |
| ... | ... | @@ -3022,9 +3027,7 @@ fn wantBuildLibUnwindFromSource(comp: *Compilation) bool { |
| 3022 | 3027 | .Lib => comp.bin_file.options.link_mode == .Dynamic, |
| 3023 | 3028 | .Exe => true, |
| 3024 | 3029 | }; |
| 3025 | return comp.bin_file.options.link_libc and is_exe_or_dyn_lib and | |
| 3026 | comp.bin_file.options.link_libcpp and | |
| 3027 | target_util.libcNeedsLibUnwind(comp.getTarget()); | |
| 3030 | return is_exe_or_dyn_lib and comp.bin_file.options.link_libunwind; | |
| 3028 | 3031 | } |
| 3029 | 3032 | |
| 3030 | 3033 | fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) Allocator.Error!void { |
src/link.zig+1| ... | ... | @@ -63,6 +63,7 @@ pub const Options = struct { |
| 63 | 63 | system_linker_hack: bool, |
| 64 | 64 | link_libc: bool, |
| 65 | 65 | link_libcpp: bool, |
| 66 | link_libunwind: bool, | |
| 66 | 67 | function_sections: bool, |
| 67 | 68 | eh_frame_hdr: bool, |
| 68 | 69 | emit_relocs: bool, |
src/link/Elf.zig+5-3| ... | ... | @@ -1643,9 +1643,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { |
| 1643 | 1643 | if (self.base.options.link_libcpp) { |
| 1644 | 1644 | try argv.append(comp.libcxxabi_static_lib.?.full_object_path); |
| 1645 | 1645 | try argv.append(comp.libcxx_static_lib.?.full_object_path); |
| 1646 | if (target_util.libcNeedsLibUnwind(target)) { | |
| 1647 | try argv.append(comp.libunwind_static_lib.?.full_object_path); | |
| 1648 | } | |
| 1646 | } | |
| 1647 | ||
| 1648 | // libunwind dep | |
| 1649 | if (self.base.options.link_libunwind) { | |
| 1650 | try argv.append(comp.libunwind_static_lib.?.full_object_path); | |
| 1649 | 1651 | } |
| 1650 | 1652 | |
| 1651 | 1653 | // libc dep |
src/main.zig+7| ... | ... | @@ -520,6 +520,7 @@ fn buildOutputType( |
| 520 | 520 | var ensure_libcpp_on_non_freestanding = false; |
| 521 | 521 | var link_libc = false; |
| 522 | 522 | var link_libcpp = false; |
| 523 | var link_libunwind = false; | |
| 523 | 524 | var want_native_include_dirs = false; |
| 524 | 525 | var enable_cache: ?bool = null; |
| 525 | 526 | var want_pic: ?bool = null; |
| ... | ... | @@ -1532,6 +1533,11 @@ fn buildOutputType( |
| 1532 | 1533 | _ = system_libs.orderedRemove(i); |
| 1533 | 1534 | continue; |
| 1534 | 1535 | } |
| 1536 | if (mem.eql(u8, lib_name, "unwind")) { | |
| 1537 | link_libunwind = true; | |
| 1538 | _ = system_libs.orderedRemove(i); | |
| 1539 | continue; | |
| 1540 | } | |
| 1535 | 1541 | if (std.fs.path.isAbsolute(lib_name)) { |
| 1536 | 1542 | fatal("cannot use absolute path as a system library: {s}", .{lib_name}); |
| 1537 | 1543 | } |
| ... | ... | @@ -1847,6 +1853,7 @@ fn buildOutputType( |
| 1847 | 1853 | .system_libs = system_libs.items, |
| 1848 | 1854 | .link_libc = link_libc, |
| 1849 | 1855 | .link_libcpp = link_libcpp, |
| 1856 | .link_libunwind = link_libunwind, | |
| 1850 | 1857 | .want_pic = want_pic, |
| 1851 | 1858 | .want_pie = want_pie, |
| 1852 | 1859 | .want_lto = want_lto, |