diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-11-06 23:21:06 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-11-10 13:12:10 -0700 |
| commit | 53f74d6a04377c9e0d7c3affd32fceea0fd51454 (patch) | |
| tree | 1aaeb813b4f799b72449179c14367c5ff6d3644c /src/Compilation.zig | |
| parent | 2a81a0f388fcf1b3ddbb55dce03fa93f4eecd804 (diff) | |
| download | zig-53f74d6a04377c9e0d7c3affd32fceea0fd51454.tar.gz zig-53f74d6a04377c9e0d7c3affd32fceea0fd51454.zip | |
move libssp into libcompiler_rt
closes #7265
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 121 |
1 files changed, 22 insertions, 99 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 32eab4cbfd..00b7c50357 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -152,9 +152,6 @@ libunwind_static_lib: ?CRTFile = null, /// Populated when we build the TSAN static library. A Job to build this is placed in the queue /// and resolved before calling linker.flush(). tsan_static_lib: ?CRTFile = null, -/// Populated when we build the libssp static library. A Job to build this is placed in the queue -/// and resolved before calling linker.flush(). -libssp_static_lib: ?CRTFile = null, /// Populated when we build the libc static library. A Job to build this is placed in the queue /// and resolved before calling linker.flush(). libc_static_lib: ?CRTFile = null, @@ -286,7 +283,6 @@ const Job = union(enum) { libcxx: void, libcxxabi: void, libtsan: void, - libssp: void, /// needed when not linking libc and using LLVM for code generation because it generates /// calls to, for example, memcpy and memset. zig_libc: void, @@ -683,7 +679,6 @@ pub const MiscTask = enum { libtsan, wasi_libc_crt_file, compiler_rt, - libssp, zig_libc, analyze_mod, @@ -1353,10 +1348,14 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { if (stack_check and !target_util.supportsStackProbing(options.target)) return error.StackCheckUnsupportedByTarget; - const capable_of_building_ssp = canBuildLibSsp(options.target, use_llvm); - - const stack_protector: u32 = options.want_stack_protector orelse b: { - if (!target_util.supportsStackProtector(options.target)) break :b @as(u32, 0); + const stack_protector: u32 = sp: { + const zig_backend = zigBackend(options.target, use_llvm); + if (!target_util.supportsStackProtector(options.target, zig_backend)) { + if (options.want_stack_protector) |x| { + if (x > 0) return error.StackProtectorUnsupportedByTarget; + } + break :sp 0; + } // This logic is checking for linking libc because otherwise our start code // which is trying to set up TLS (i.e. the fs/gs registers) but the stack @@ -1365,19 +1364,17 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { // as being exempt from stack protection checks, we could change this logic // to supporting stack protection even when not linking libc. // TODO file issue about this - if (!link_libc) break :b 0; - if (!capable_of_building_ssp) break :b 0; - if (is_safe_mode) break :b default_stack_protector_buffer_size; - break :b 0; + if (!link_libc) { + if (options.want_stack_protector) |x| { + if (x > 0) return error.StackProtectorUnavailableWithoutLibC; + } + break :sp 0; + } + + if (options.want_stack_protector) |x| break :sp x; + if (is_safe_mode) break :sp default_stack_protector_buffer_size; + break :sp 0; }; - if (stack_protector != 0) { - if (!target_util.supportsStackProtector(options.target)) - return error.StackProtectorUnsupportedByTarget; - if (!capable_of_building_ssp) - return error.StackProtectorUnsupportedByBackend; - if (!link_libc) - return error.StackProtectorUnavailableWithoutLibC; - } const include_compiler_rt = options.want_compiler_rt orelse (!options.skip_linker_dependencies and is_exe_or_dyn_lib); @@ -2195,24 +2192,11 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { comp.job_queued_compiler_rt_obj = true; } } - if (needsCSymbols( - options.skip_linker_dependencies, - options.output_mode, - options.link_mode, - options.target, - comp.bin_file.options.use_llvm, - )) { - // Related: https://github.com/ziglang/zig/issues/7265. - if (comp.bin_file.options.stack_protector != 0 and - (!comp.bin_file.options.link_libc or - !target_util.libcProvidesStackProtector(target))) - { - try comp.work_queue.writeItem(.{ .libssp = {} }); - } - if (!comp.bin_file.options.link_libc and capable_of_building_zig_libc) { - try comp.work_queue.writeItem(.{ .zig_libc = {} }); - } + if (!comp.bin_file.options.skip_linker_dependencies and is_exe_or_dyn_lib and + !comp.bin_file.options.link_libc and capable_of_building_zig_libc) + { + try comp.work_queue.writeItem(.{ .zig_libc = {} }); } } @@ -2258,9 +2242,6 @@ pub fn destroy(self: *Compilation) void { if (self.compiler_rt_obj) |*crt_file| { crt_file.deinit(gpa); } - if (self.libssp_static_lib) |*crt_file| { - crt_file.deinit(gpa); - } if (self.libc_static_lib) |*crt_file| { crt_file.deinit(gpa); } @@ -4027,26 +4008,6 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v ); }; }, - .libssp => { - const named_frame = tracy.namedFrame("libssp"); - defer named_frame.end(); - - comp.buildOutputFromZig( - "ssp.zig", - .Lib, - &comp.libssp_static_lib, - .libssp, - prog_node, - ) catch |err| switch (err) { - error.OutOfMemory => return error.OutOfMemory, - error.SubCompilationFailed => return, // error reported already - else => comp.lockAndSetMiscFailure( - .libssp, - "unable to build libssp: {s}", - .{@errorName(err)}, - ), - }; - }, .zig_libc => { const named_frame = tracy.namedFrame("zig_libc"); defer named_frame.end(); @@ -6531,21 +6492,6 @@ fn canBuildLibCompilerRt(target: std.Target, use_llvm: bool) bool { }; } -fn canBuildLibSsp(target: std.Target, use_llvm: bool) bool { - switch (target.os.tag) { - .plan9 => return false, - else => {}, - } - switch (target.cpu.arch) { - .spirv32, .spirv64 => return false, - else => {}, - } - return switch (zigBackend(target, use_llvm)) { - .stage2_llvm => true, - else => build_options.have_llvm, - }; -} - /// Not to be confused with canBuildLibC, which builds musl, glibc, and similar. /// This one builds lib/c.zig. fn canBuildZigLibC(target: std.Target, use_llvm: bool) bool { @@ -6585,29 +6531,6 @@ fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBackend { }; } -fn needsCSymbols( - skip_linker_dependencies: bool, - output_mode: std.builtin.OutputMode, - link_mode: ?std.builtin.LinkMode, - target: std.Target, - use_llvm: bool, -) bool { - if (skip_linker_dependencies) - return false; - - switch (output_mode) { - .Obj => return false, - .Lib => if (link_mode != .Dynamic) return false, - .Exe => {}, - } - - // LLVM might generate calls to libc symbols. - if (zigBackend(target, use_llvm) == .stage2_llvm) - return true; - - return false; -} - pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Allocator.Error![:0]u8 { const tracy_trace = trace(@src()); defer tracy_trace.end(); |
