aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-05-13 15:59:24 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-05-13 22:42:57 -0400
commit826179bff40fdbd8c3b11138897fcfbb3367def8 (patch)
tree23fcdea829179045785ac4303a3e694cc7e12170 /src/Compilation.zig
parent76a259799d5bac3effabd1df44c0dec9e4fa16d4 (diff)
downloadzig-826179bff40fdbd8c3b11138897fcfbb3367def8.tar.gz
zig-826179bff40fdbd8c3b11138897fcfbb3367def8.zip
stage2: -lunwind is handled specially
* `-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.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 0f04f02b7d..140e160b69 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -544,6 +544,7 @@ pub const InitOptions = struct {
system_libs: []const []const u8 = &[0][]const u8{},
link_libc: bool = false,
link_libcpp: bool = false,
+ link_libunwind: bool = false,
want_pic: ?bool = null,
/// This means that if the output mode is an executable it will be a
/// Position Independent Executable. If the output mode is not an
@@ -791,8 +792,13 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
};
const tsan = options.want_tsan orelse false;
+ // TSAN is implemented in C++ so it requires linking libc++.
+ const link_libcpp = options.link_libcpp or tsan;
+ const link_libc = link_libcpp or options.link_libc or
+ target_util.osRequiresLibC(options.target);
- const link_libc = options.link_libc or target_util.osRequiresLibC(options.target) or tsan;
+ const link_libunwind = options.link_libunwind or
+ (link_libcpp and target_util.libcNeedsLibUnwind(options.target));
const must_dynamic_link = dl: {
if (target_util.cannotDynamicLink(options.target))
@@ -878,9 +884,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
break :pic explicit;
} else pie or must_pic;
- // TSAN is implemented in C++ so it requires linking libc++.
- const link_libcpp = options.link_libcpp or tsan;
-
// Make a decision on whether to use Clang for translate-c and compiling C files.
const use_clang = if (options.use_clang) |explicit| explicit else blk: {
if (build_options.have_llvm) {
@@ -973,6 +976,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
cache.hash.add(strip);
cache.hash.add(link_libc);
cache.hash.add(link_libcpp);
+ cache.hash.add(link_libunwind);
cache.hash.add(options.output_mode);
cache.hash.add(options.machine_code_model);
cache.hash.addOptionalEmitLoc(options.emit_bin);
@@ -1157,6 +1161,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
.system_linker_hack = darwin_options.system_linker_hack,
.link_libc = link_libc,
.link_libcpp = link_libcpp,
+ .link_libunwind = link_libunwind,
.objects = options.link_objects,
.frameworks = options.frameworks,
.framework_dirs = options.framework_dirs,
@@ -3022,9 +3027,7 @@ fn wantBuildLibUnwindFromSource(comp: *Compilation) bool {
.Lib => comp.bin_file.options.link_mode == .Dynamic,
.Exe => true,
};
- return comp.bin_file.options.link_libc and is_exe_or_dyn_lib and
- comp.bin_file.options.link_libcpp and
- target_util.libcNeedsLibUnwind(comp.getTarget());
+ return is_exe_or_dyn_lib and comp.bin_file.options.link_libunwind;
}
fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) Allocator.Error!void {