diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-11-10 22:27:45 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-10 22:27:45 -0500 |
| commit | 97e23896a9168132b6d36ca22ae1af10dd53d80d (patch) | |
| tree | b7d25c4231838edf980b7de7eec317f0a23371ee /src | |
| parent | 138a35df8f434115be04641b1df29514b0ef1cb8 (diff) | |
| parent | dfee782d7c30e2ff84060833be375e8cdf92e3be (diff) | |
| download | zig-97e23896a9168132b6d36ca22ae1af10dd53d80d.tar.gz zig-97e23896a9168132b6d36ca22ae1af10dd53d80d.zip | |
Merge pull request #17962 from ziglang/libssp
move libssp into libcompiler_rt
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 97 | ||||
| -rw-r--r-- | src/link/Coff/lld.zig | 6 | ||||
| -rw-r--r-- | src/link/Elf.zig | 18 | ||||
| -rw-r--r-- | src/target.zig | 15 |
4 files changed, 37 insertions, 99 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 3bd7d1506c..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, @@ -1072,8 +1067,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { .Exe => true, }; - const needs_c_symbols = !options.skip_linker_dependencies and is_exe_or_dyn_lib; - // WASI-only. Resolve the optional exec-model option, defaults to command. const wasi_exec_model = if (options.target.os.tag != .wasi) undefined else options.wasi_exec_model orelse .command; @@ -1355,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 @@ -1367,21 +1364,20 @@ 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 needs_c_symbols; + const include_compiler_rt = options.want_compiler_rt orelse + (!options.skip_linker_dependencies and is_exe_or_dyn_lib); const single_threaded = st: { if (target_util.isSingleThreaded(options.target)) { @@ -2196,18 +2192,11 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { comp.job_queued_compiler_rt_obj = true; } } - if (needs_c_symbols) { - // 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 = {} }); } } @@ -2253,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); } @@ -4022,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(); @@ -6526,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 { diff --git a/src/link/Coff/lld.zig b/src/link/Coff/lld.zig index cbefcbd91e..573a85e167 100644 --- a/src/link/Coff/lld.zig +++ b/src/link/Coff/lld.zig @@ -483,12 +483,6 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod try argv.append(lib.full_object_path); } } - // MinGW doesn't provide libssp symbols - if (target.abi.isGnu()) { - if (comp.libssp_static_lib) |lib| { - try argv.append(lib.full_object_path); - } - } // MSVC compiler_rt is missing some stuff, so we build it unconditionally but // and rely on weak linkage to allow MSVC compiler_rt functions to override ours. if (comp.compiler_rt_obj) |obj| try argv.append(obj.full_object_path); diff --git a/src/link/Elf.zig b/src/link/Elf.zig index d210292bf9..b21a7254ff 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1040,12 +1040,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node } } - // stack-protector. - // Related: https://github.com/ziglang/zig/issues/7265 - if (comp.libssp_static_lib) |ssp| { - try positionals.append(.{ .path = ssp.full_object_path }); - } - for (positionals.items) |obj| { var parse_ctx: ParseErrorCtx = .{ .detected_cpu_arch = undefined }; self.parsePositional(obj.path, obj.must_link, &parse_ctx) catch |err| @@ -1689,12 +1683,6 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { } } - // stack-protector. - // Related: https://github.com/ziglang/zig/issues/7265 - if (comp.libssp_static_lib) |ssp| { - try argv.append(ssp.full_object_path); - } - // Shared libraries. // Worst-case, we need an --as-needed argument for every lib, as well // as one before and one after. @@ -2729,12 +2717,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v } } - // stack-protector. - // Related: https://github.com/ziglang/zig/issues/7265 - if (comp.libssp_static_lib) |ssp| { - try argv.append(ssp.full_object_path); - } - // Shared libraries. if (is_exe_or_dyn_lib) { const system_libs = self.base.options.system_libs.keys(); diff --git a/src/target.zig b/src/target.zig index 7f85113040..59528ed139 100644 --- a/src/target.zig +++ b/src/target.zig @@ -328,8 +328,19 @@ pub fn supportsStackProbing(target: std.Target) bool { (target.cpu.arch == .x86 or target.cpu.arch == .x86_64); } -pub fn supportsStackProtector(target: std.Target) bool { - return !target.isSpirV(); +pub fn supportsStackProtector(target: std.Target, backend: std.builtin.CompilerBackend) bool { + switch (target.os.tag) { + .plan9 => return false, + else => {}, + } + switch (target.cpu.arch) { + .spirv32, .spirv64 => return false, + else => {}, + } + return switch (backend) { + .stage2_llvm => true, + else => false, + }; } pub fn libcProvidesStackProtector(target: std.Target) bool { |
