authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-14 00:24:03-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-14 00:24:03-07:00
logf2e380380e034a3f1a3e35857220edd78439a949
tree7c6db2effb81bea2c8c7b675956532480319ff0a
parent060c91b97f25e22781f4b9e7c90bd0642594b722

stage2: building glibc Scrt1.o


2 files changed, 61 insertions(+), 61 deletions(-)

src-self-hosted/Compilation.zig-2
......@@ -1552,8 +1552,6 @@ fn addBuildingGLibCWorkItems(comp: *Compilation) !void {
15521552 const static_file_work_items = [_]WorkItem{
15531553 .{ .glibc_crt_file = .crti_o },
15541554 .{ .glibc_crt_file = .crtn_o },
1555 .{ .glibc_crt_file = .start_os },
1556 .{ .glibc_crt_file = .abi_note_o },
15571555 .{ .glibc_crt_file = .scrt1_o },
15581556 .{ .glibc_crt_file = .libc_nonshared_a },
15591557 };
src-self-hosted/glibc.zig+61-59
......@@ -240,8 +240,6 @@ fn findLib(name: []const u8) ?*const Lib {
240240pub const CRTFile = enum {
241241 crti_o,
242242 crtn_o,
243 start_os,
244 abi_note_o,
245243 scrt1_o,
246244 libc_nonshared_a,
247245};
......@@ -272,76 +270,76 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
272270 "-g",
273271 "-Wa,--noexecstack",
274272 });
275 const c_source_file: Compilation.CSourceFile = .{
276 .src_path = try start_asm_path(comp, arena, "crti.S"),
277 .extra_flags = args.items,
278 };
279 return build_libc_object(comp, "crti.o", c_source_file);
280 },
281 .crtn_o => {
282 var args = std.ArrayList([]const u8).init(arena);
283 try add_include_dirs(comp, arena, &args);
284 try args.appendSlice(&[_][]const u8{
285 "-D_LIBC_REENTRANT",
286 "-DMODULE_NAME=libc",
287 "-DTOP_NAMESPACE=glibc",
288 "-DASSEMBLER",
289 "-g",
290 "-Wa,--noexecstack",
273 return build_libc_object(comp, "crti.o", &[1]Compilation.CSourceFile{
274 .{
275 .src_path = try start_asm_path(comp, arena, "crti.S"),
276 .extra_flags = args.items,
277 },
291278 });
292 const c_source_file: Compilation.CSourceFile = .{
293 .src_path = try start_asm_path(comp, arena, "crtn.S"),
294 .extra_flags = args.items,
295 };
296 return build_libc_object(comp, "crtn.o", c_source_file);
297279 },
298 .start_os => {
280 .crtn_o => {
299281 var args = std.ArrayList([]const u8).init(arena);
300282 try add_include_dirs(comp, arena, &args);
301283 try args.appendSlice(&[_][]const u8{
302284 "-D_LIBC_REENTRANT",
303 "-include",
304 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-modules.h"),
305285 "-DMODULE_NAME=libc",
306 "-Wno-nonportable-include-path",
307 "-include",
308 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-symbols.h"),
309 "-DPIC",
310 "-DSHARED",
311286 "-DTOP_NAMESPACE=glibc",
312287 "-DASSEMBLER",
313288 "-g",
314289 "-Wa,--noexecstack",
315290 });
316 const c_source_file: Compilation.CSourceFile = .{
317 .src_path = try start_asm_path(comp, arena, "start.S"),
318 .extra_flags = args.items,
319 };
320 return build_libc_object(comp, "start.os", c_source_file);
321 },
322 .abi_note_o => {
323 var args = std.ArrayList([]const u8).init(arena);
324 try args.appendSlice(&[_][]const u8{
325 "-I",
326 try lib_path(comp, arena, lib_libc_glibc ++ "csu"),
291 return build_libc_object(comp, "crtn.o", &[1]Compilation.CSourceFile{
292 .{
293 .src_path = try start_asm_path(comp, arena, "crtn.S"),
294 .extra_flags = args.items,
295 },
327296 });
328 try add_include_dirs(comp, arena, &args);
329 try args.appendSlice(&[_][]const u8{
330 "-D_LIBC_REENTRANT",
331 "-DMODULE_NAME=libc",
332 "-DTOP_NAMESPACE=glibc",
333 "-DASSEMBLER",
334 "-g",
335 "-Wa,--noexecstack",
336 });
337 const c_source_file: Compilation.CSourceFile = .{
338 .src_path = try lib_path(comp, arena, lib_libc_glibc ++ "csu" ++ path.sep_str ++ "abi-note.S"),
339 .extra_flags = args.items,
340 };
341 return build_libc_object(comp, "abi-note.o", c_source_file);
342297 },
343298 .scrt1_o => {
344 return error.Unimplemented; // TODO
299 const start_os: Compilation.CSourceFile = blk: {
300 var args = std.ArrayList([]const u8).init(arena);
301 try add_include_dirs(comp, arena, &args);
302 try args.appendSlice(&[_][]const u8{
303 "-D_LIBC_REENTRANT",
304 "-include",
305 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-modules.h"),
306 "-DMODULE_NAME=libc",
307 "-Wno-nonportable-include-path",
308 "-include",
309 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-symbols.h"),
310 "-DPIC",
311 "-DSHARED",
312 "-DTOP_NAMESPACE=glibc",
313 "-DASSEMBLER",
314 "-g",
315 "-Wa,--noexecstack",
316 });
317 break :blk .{
318 .src_path = try start_asm_path(comp, arena, "start.S"),
319 .extra_flags = args.items,
320 };
321 };
322 const abi_note_o: Compilation.CSourceFile = blk: {
323 var args = std.ArrayList([]const u8).init(arena);
324 try args.appendSlice(&[_][]const u8{
325 "-I",
326 try lib_path(comp, arena, lib_libc_glibc ++ "csu"),
327 });
328 try add_include_dirs(comp, arena, &args);
329 try args.appendSlice(&[_][]const u8{
330 "-D_LIBC_REENTRANT",
331 "-DMODULE_NAME=libc",
332 "-DTOP_NAMESPACE=glibc",
333 "-DASSEMBLER",
334 "-g",
335 "-Wa,--noexecstack",
336 });
337 break :blk .{
338 .src_path = try lib_path(comp, arena, lib_libc_glibc ++ "csu" ++ path.sep_str ++ "abi-note.S"),
339 .extra_flags = args.items,
340 };
341 };
342 return build_libc_object(comp, "Scrt1.o", &[_]Compilation.CSourceFile{ start_os, abi_note_o });
345343 },
346344 .libc_nonshared_a => {
347345 return error.Unimplemented; // TODO
......@@ -587,7 +585,11 @@ fn lib_path(comp: *Compilation, arena: *Allocator, sub_path: []const u8) ![]cons
587585 return path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, sub_path });
588586}
589587
590fn build_libc_object(comp: *Compilation, basename: []const u8, c_source_file: Compilation.CSourceFile) !void {
588fn build_libc_object(
589 comp: *Compilation,
590 basename: []const u8,
591 c_source_files: []const Compilation.CSourceFile,
592) !void {
591593 const tracy = trace(@src());
592594 defer tracy.end();
593595
......@@ -616,7 +618,7 @@ fn build_libc_object(comp: *Compilation, basename: []const u8, c_source_file: Co
616618 .strip = comp.bin_file.options.strip,
617619 .is_native_os = comp.bin_file.options.is_native_os,
618620 .self_exe_path = comp.self_exe_path,
619 .c_source_files = &[1]Compilation.CSourceFile{c_source_file},
621 .c_source_files = c_source_files,
620622 .debug_cc = comp.debug_cc,
621623 .debug_link = comp.bin_file.options.debug_link,
622624 .clang_passthrough_mode = comp.clang_passthrough_mode,