aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 3295f9fc3c..00c5937394 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -81,6 +81,7 @@ verbose_llvm_cpu_features: bool,
disable_c_depfile: bool,
time_report: bool,
stack_report: bool,
+unwind_tables: bool,
c_source_files: []const CSourceFile,
clang_argv: []const []const u8,
@@ -665,6 +666,7 @@ pub const InitOptions = struct {
want_tsan: ?bool = null,
want_compiler_rt: ?bool = null,
want_lto: ?bool = null,
+ want_unwind_tables: ?bool = null,
use_llvm: ?bool = null,
use_lld: ?bool = null,
use_clang: ?bool = null,
@@ -823,8 +825,20 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
return error.MachineCodeModelNotSupported;
}
+ 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_libunwind = options.link_libunwind or
+ (link_libcpp and target_util.libcNeedsLibUnwind(options.target));
+ const unwind_tables = options.want_unwind_tables orelse
+ (link_libunwind or target_util.needUnwindTables(options.target));
+ const link_eh_frame_hdr = options.link_eh_frame_hdr or unwind_tables;
+
// Make a decision on whether to use LLD or our own linker.
- const use_lld = if (options.use_lld) |explicit| explicit else blk: {
+ const use_lld = options.use_lld orelse blk: {
if (!build_options.have_llvm)
break :blk false;
@@ -843,7 +857,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
options.frameworks.len != 0 or
options.system_libs.len != 0 or
options.link_libc or options.link_libcpp or
- options.link_eh_frame_hdr or
+ link_eh_frame_hdr or
options.link_emit_relocs or
options.output_mode == .Lib or
options.lld_argv.len != 0 or
@@ -902,15 +916,6 @@ 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_libunwind = options.link_libunwind or
- (link_libcpp and target_util.libcNeedsLibUnwind(options.target));
-
const must_dynamic_link = dl: {
if (target_util.cannotDynamicLink(options.target))
break :dl false;
@@ -1080,6 +1085,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
cache.hash.add(pic);
cache.hash.add(pie);
cache.hash.add(lto);
+ cache.hash.add(unwind_tables);
cache.hash.add(tsan);
cache.hash.add(stack_check);
cache.hash.add(red_zone);
@@ -1312,7 +1318,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
.linker_script = options.linker_script,
.version_script = options.version_script,
.gc_sections = options.linker_gc_sections,
- .eh_frame_hdr = options.link_eh_frame_hdr,
+ .eh_frame_hdr = link_eh_frame_hdr,
.emit_relocs = options.link_emit_relocs,
.rdynamic = options.rdynamic,
.extra_lld_args = options.lld_argv,
@@ -1376,6 +1382,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
.color = options.color,
.time_report = options.time_report,
.stack_report = options.stack_report,
+ .unwind_tables = unwind_tables,
.test_filter = options.test_filter,
.test_name_prefix = options.test_name_prefix,
.test_evented_io = options.test_evented_io,
@@ -2983,6 +2990,12 @@ pub fn addCCArgs(
if (target_util.supports_fpic(target) and comp.bin_file.options.pic) {
try argv.append("-fPIC");
}
+
+ if (comp.unwind_tables) {
+ try argv.append("-funwind-tables");
+ } else {
+ try argv.append("-fno-unwind-tables");
+ }
},
.shared_library, .ll, .bc, .unknown, .static_library, .object, .zig => {},
.assembly => {
@@ -3948,6 +3961,7 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
.pic = comp.bin_file.options.pic,
.pie = comp.bin_file.options.pie,
.lto = comp.bin_file.options.lto,
+ .unwind_tables = comp.unwind_tables,
.link_libc = comp.bin_file.options.link_libc,
.link_libcpp = comp.bin_file.options.link_libcpp,
.strip = comp.bin_file.options.strip,