aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2020-10-02 16:48:18 +0200
committerAndrew Kelley <andrew@ziglang.org>2020-10-16 21:22:14 -0400
commitd44486b274a916823fcf6045a6400ef51e07d544 (patch)
treec12a3a3923b644d219f815630941073d99d31889 /src/Compilation.zig
parent2aff27d92247eed3b64ffc68da8fae9e5994ea0b (diff)
downloadzig-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/Compilation.zig')
-rw-r--r--src/Compilation.zig17
1 files changed, 17 insertions, 0 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.