diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-10-02 16:48:18 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-10-16 21:22:14 -0400 |
| commit | d44486b274a916823fcf6045a6400ef51e07d544 (patch) | |
| tree | c12a3a3923b644d219f815630941073d99d31889 /src | |
| parent | 2aff27d92247eed3b64ffc68da8fae9e5994ea0b (diff) | |
| download | zig-d44486b274a916823fcf6045a6400ef51e07d544.tar.gz zig-d44486b274a916823fcf6045a6400ef51e07d544.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 17 | ||||
| -rw-r--r-- | src/link/Coff.zig | 6 |
2 files changed, 22 insertions, 1 deletions
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. diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 334492e164..3eb4d32c95 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -1117,11 +1117,15 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { try argv.append(comp.libunwind_static_lib.?.full_object_path); } - // compiler-rt and libc + // compiler-rt, libc and libssp if (is_exe_or_dyn_lib and !self.base.options.is_compiler_rt_or_libc) { if (!self.base.options.link_libc) { try argv.append(comp.libc_static_lib.?.full_object_path); } + // MinGW doesn't provide libssp symbols + if (target.abi.isGnu()) { + try argv.append(comp.libssp_static_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. try argv.append(comp.compiler_rt_static_lib.?.full_object_path); |
