From d44486b274a916823fcf6045a6400ef51e07d544 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Fri, 2 Oct 2020 16:48:18 +0200 Subject: std: Add libssp implementation for GNU/Windows targets Unlike glibc and musl, MinGW provides no libssp symbols leading to countless compile errors if FORTIFY_SOURCE is defined. Add a (incomplete) implementation of libssp written in Zig so that linking succeeds. Closes #6492 --- src/Compilation.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index eaec75d4fe..ad59bf352a 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -84,6 +84,9 @@ libcxxabi_static_lib: ?CRTFile = null, /// Populated when we build the libunwind static library. A Job to build this is placed in the queue /// and resolved before calling linker.flush(). libunwind_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, @@ -160,6 +163,7 @@ const Job = union(enum) { libunwind: void, libcxx: void, libcxxabi: void, + libssp: void, /// needed when producing a dynamic library or executable libcompiler_rt: void, /// needed when not linking libc and using LLVM for code generation because it generates @@ -927,6 +931,10 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { (comp.getTarget().isWasm() and comp.bin_file.options.output_mode != .Obj); if (needs_compiler_rt_and_c and build_options.is_stage1) { try comp.work_queue.writeItem(.{ .libcompiler_rt = {} }); + // MinGW provides no libssp, use our own implementation. + if (comp.getTarget().isMinGW()) { + try comp.work_queue.writeItem(.{ .libssp = {} }); + } if (!comp.bin_file.options.link_libc) { try comp.work_queue.writeItem(.{ .zig_libc = {} }); } @@ -978,6 +986,9 @@ pub fn destroy(self: *Compilation) void { if (self.compiler_rt_static_lib) |*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); } @@ -1329,6 +1340,12 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor fatal("unable to build compiler_rt: {}", .{@errorName(err)}); }; }, + .libssp => { + self.buildStaticLibFromZig("ssp.zig", &self.libssp_static_lib) catch |err| { + // TODO Expose this as a normal compile error rather than crashing here. + fatal("unable to build libssp: {}", .{@errorName(err)}); + }; + }, .zig_libc => { self.buildStaticLibFromZig("c.zig", &self.libc_static_lib) catch |err| { // TODO Expose this as a normal compile error rather than crashing here. -- cgit v1.2.3