authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-21 21:42:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-21 21:42:27-07:00
log974333faaf70eb67b78d3fa83bdc92e91379631a
treef7f59ef4df3bc2390ff2d06af25fba213f9fc9ce
parent0c70bb4fce8b0460f86ed218f54ba31b291f2bfb

stage2: fix linking libc trying to depend on itself


4 files changed, 9 insertions(+), 3 deletions(-)

src/Compilation.zig+4-2
...@@ -324,6 +324,8 @@ pub const InitOptions = struct {...@@ -324,6 +324,8 @@ pub const InitOptions = struct {
324 verbose_cimport: bool = false,324 verbose_cimport: bool = false,
325 verbose_llvm_cpu_features: bool = false,325 verbose_llvm_cpu_features: bool = false,
326 is_test: bool = false,326 is_test: bool = false,
327 test_evented_io: bool = false,
328 is_compiler_rt_or_libc: bool = false,
327 stack_size_override: ?u64 = null,329 stack_size_override: ?u64 = null,
328 self_exe_path: ?[]const u8 = null,330 self_exe_path: ?[]const u8 = null,
329 version: ?std.builtin.Version = null,331 version: ?std.builtin.Version = null,
...@@ -333,7 +335,6 @@ pub const InitOptions = struct {...@@ -333,7 +335,6 @@ pub const InitOptions = struct {
333 color: @import("main.zig").Color = .Auto,335 color: @import("main.zig").Color = .Auto,
334 test_filter: ?[]const u8 = null,336 test_filter: ?[]const u8 = null,
335 test_name_prefix: ?[]const u8 = null,337 test_name_prefix: ?[]const u8 = null,
336 test_evented_io: bool = false,
337};338};
338339
339pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {340pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
...@@ -704,9 +705,9 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -704,9 +705,9 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
704 .dll_export_fns = dll_export_fns,705 .dll_export_fns = dll_export_fns,
705 .error_return_tracing = error_return_tracing,706 .error_return_tracing = error_return_tracing,
706 .llvm_cpu_features = llvm_cpu_features,707 .llvm_cpu_features = llvm_cpu_features,
708 .is_compiler_rt_or_libc = options.is_compiler_rt_or_libc,
707 });709 });
708 errdefer bin_file.destroy();710 errdefer bin_file.destroy();
709
710 comp.* = .{711 comp.* = .{
711 .gpa = gpa,712 .gpa = gpa,
712 .arena_state = arena_allocator.state,713 .arena_state = arena_allocator.state,
...@@ -2116,6 +2117,7 @@ fn buildStaticLibFromZig(comp: *Compilation, basename: []const u8, out: *?CRTFil...@@ -2116,6 +2117,7 @@ fn buildStaticLibFromZig(comp: *Compilation, basename: []const u8, out: *?CRTFil
2116 .verbose_cimport = comp.verbose_cimport,2117 .verbose_cimport = comp.verbose_cimport,
2117 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,2118 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
2118 .clang_passthrough_mode = comp.clang_passthrough_mode,2119 .clang_passthrough_mode = comp.clang_passthrough_mode,
2120 .is_compiler_rt_or_libc = true,
2119 });2121 });
2120 defer sub_compilation.destroy();2122 defer sub_compilation.destroy();
21212123
src/glibc.zig+2
...@@ -720,6 +720,7 @@ fn build_crt_file(...@@ -720,6 +720,7 @@ fn build_crt_file(
720 .verbose_cimport = comp.verbose_cimport,720 .verbose_cimport = comp.verbose_cimport,
721 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,721 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
722 .clang_passthrough_mode = comp.clang_passthrough_mode,722 .clang_passthrough_mode = comp.clang_passthrough_mode,
723 .is_compiler_rt_or_libc = true,
723 });724 });
724 defer sub_compilation.destroy();725 defer sub_compilation.destroy();
725726
...@@ -1006,6 +1007,7 @@ fn buildSharedLib(...@@ -1006,6 +1007,7 @@ fn buildSharedLib(
1006 .version_script = map_file_path,1007 .version_script = map_file_path,
1007 .override_soname = override_soname,1008 .override_soname = override_soname,
1008 .c_source_files = &c_source_files,1009 .c_source_files = &c_source_files,
1010 .is_compiler_rt_or_libc = true,
1009 });1011 });
1010 defer sub_compilation.destroy();1012 defer sub_compilation.destroy();
10111013
src/link.zig+1
...@@ -64,6 +64,7 @@ pub const Options = struct {...@@ -64,6 +64,7 @@ pub const Options = struct {
64 verbose_link: bool = false,64 verbose_link: bool = false,
65 dll_export_fns: bool,65 dll_export_fns: bool,
66 error_return_tracing: bool,66 error_return_tracing: bool,
67 is_compiler_rt_or_libc: bool,
67 gc_sections: ?bool = null,68 gc_sections: ?bool = null,
68 allow_shlib_undefined: ?bool = null,69 allow_shlib_undefined: ?bool = null,
69 linker_script: ?[]const u8 = null,70 linker_script: ?[]const u8 = null,
src/link/Elf.zig+2-1
...@@ -1272,6 +1272,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1272,6 +1272,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1272 ch.hash.add(self.base.options.rdynamic);1272 ch.hash.add(self.base.options.rdynamic);
1273 ch.hash.addListOfBytes(self.base.options.extra_lld_args);1273 ch.hash.addListOfBytes(self.base.options.extra_lld_args);
1274 ch.hash.addListOfBytes(self.base.options.lib_dirs);1274 ch.hash.addListOfBytes(self.base.options.lib_dirs);
1275 ch.hash.add(self.base.options.is_compiler_rt_or_libc);
1275 ch.hash.add(self.base.options.z_nodelete);1276 ch.hash.add(self.base.options.z_nodelete);
1276 ch.hash.add(self.base.options.z_defs);1277 ch.hash.add(self.base.options.z_defs);
1277 if (self.base.options.link_libc) {1278 if (self.base.options.link_libc) {
...@@ -1491,7 +1492,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {...@@ -1491,7 +1492,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
1491 }1492 }
14921493
1493 // compiler-rt and libc1494 // compiler-rt and libc
1494 if (is_exe_or_dyn_lib) {1495 if (is_exe_or_dyn_lib and !self.base.options.is_compiler_rt_or_libc) {
1495 if (!self.base.options.link_libc) {1496 if (!self.base.options.link_libc) {
1496 try argv.append(comp.libc_static_lib.?.full_object_path);1497 try argv.append(comp.libc_static_lib.?.full_object_path);
1497 }1498 }