diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-07-29 14:18:32 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-29 14:18:32 -0700 |
| commit | 3cf8f283d3f271b6d0b5de39f55e4ea40b83eece (patch) | |
| tree | 473271314571f59d4e0c0154acf078d1445b5fdb /src/main.zig | |
| parent | 4fc2acdaa4f2b649b17ddf958d2608abc4787a4e (diff) | |
| parent | 58540f968a2ae53b4b1ff5a917fdb404088a222a (diff) | |
| download | zig-3cf8f283d3f271b6d0b5de39f55e4ea40b83eece.tar.gz zig-3cf8f283d3f271b6d0b5de39f55e4ea40b83eece.zip | |
Merge pull request #12085 from topolarity/dyn-link-libcpp
Dynamically link `libc++` if integrating with system LLVM
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig index f2291a0646..f192137b3c 100644 --- a/src/main.zig +++ b/src/main.zig @@ -174,6 +174,17 @@ pub fn main() anyerror!void { return mainArgs(gpa, arena, args); } +/// Check that LLVM and Clang have been linked properly so that they are using the same +/// libc++ and can safely share objects with pointers to static variables in libc++ +fn verifyLibcxxCorrectlyLinked() void { + if (build_options.have_llvm and ZigClangIsLLVMUsingSeparateLibcxx()) { + fatal( + \\Zig was built/linked incorrectly: LLVM and Clang have separate copies of libc++ + \\ If you are dynamically linking LLVM, make sure you dynamically link libc++ too + , .{}); + } +} + pub fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { if (args.len <= 1) { std.log.info("{s}", .{usage}); @@ -261,8 +272,12 @@ pub fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi const stdout = io.getStdOut().writer(); return @import("print_targets.zig").cmdTargets(arena, cmd_args, stdout, info.target); } else if (mem.eql(u8, cmd, "version")) { - return std.io.getStdOut().writeAll(build_options.version ++ "\n"); + try std.io.getStdOut().writeAll(build_options.version ++ "\n"); + // Check libc++ linkage to make sure Zig was built correctly, but only for "env" and "version" + // to avoid affecting the startup time for build-critical commands (check takes about ~10 μs) + return verifyLibcxxCorrectlyLinked(); } else if (mem.eql(u8, cmd, "env")) { + verifyLibcxxCorrectlyLinked(); return @import("print_env.zig").cmdEnv(arena, cmd_args, io.getStdOut().writer()); } else if (mem.eql(u8, cmd, "zen")) { return io.getStdOut().writeAll(info_zen); @@ -4487,6 +4502,8 @@ pub const info_zen = \\ ; +extern fn ZigClangIsLLVMUsingSeparateLibcxx() bool; + extern "c" fn ZigClang_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int; extern "c" fn ZigLlvmAr_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int; |
