authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-15 00:41:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-15 00:41:02-07:00
log1da9e0fcaf05fb78e4634278f51b6fe43509bd6f
treedbed6e32b0455c3f2683972da3b94ffe495a9037
parent4fa8cc736966544da381c90a6111158179fc550b

stage2: building glibc libc_nonshared.a CRT file


1 files changed, 93 insertions(+), 5 deletions(-)

src-self-hosted/glibc.zig+93-5
...@@ -270,7 +270,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -270,7 +270,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
270 "-g",270 "-g",
271 "-Wa,--noexecstack",271 "-Wa,--noexecstack",
272 });272 });
273 return build_crt_file(comp, "crti.o", &[1]Compilation.CSourceFile{273 return build_crt_file(comp, "crti.o", .Obj, &[1]Compilation.CSourceFile{
274 .{274 .{
275 .src_path = try start_asm_path(comp, arena, "crti.S"),275 .src_path = try start_asm_path(comp, arena, "crti.S"),
276 .extra_flags = args.items,276 .extra_flags = args.items,
...@@ -288,7 +288,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -288,7 +288,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
288 "-g",288 "-g",
289 "-Wa,--noexecstack",289 "-Wa,--noexecstack",
290 });290 });
291 return build_crt_file(comp, "crtn.o", &[1]Compilation.CSourceFile{291 return build_crt_file(comp, "crtn.o", .Obj, &[1]Compilation.CSourceFile{
292 .{292 .{
293 .src_path = try start_asm_path(comp, arena, "crtn.S"),293 .src_path = try start_asm_path(comp, arena, "crtn.S"),
294 .extra_flags = args.items,294 .extra_flags = args.items,
...@@ -339,10 +339,97 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {...@@ -339,10 +339,97 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void {
339 .extra_flags = args.items,339 .extra_flags = args.items,
340 };340 };
341 };341 };
342 return build_crt_file(comp, "Scrt1.o", &[_]Compilation.CSourceFile{ start_os, abi_note_o });342 return build_crt_file(comp, "Scrt1.o", .Obj, &[_]Compilation.CSourceFile{ start_os, abi_note_o });
343 },343 },
344 .libc_nonshared_a => {344 .libc_nonshared_a => {
345 return error.Unimplemented; // TODO345 const deps = [_][]const u8{
346 lib_libc_glibc ++ "stdlib" ++ path.sep_str ++ "atexit.c",
347 lib_libc_glibc ++ "stdlib" ++ path.sep_str ++ "at_quick_exit.c",
348 lib_libc_glibc ++ "io" ++ path.sep_str ++ "stat.c",
349 lib_libc_glibc ++ "io" ++ path.sep_str ++ "fstat.c",
350 lib_libc_glibc ++ "io" ++ path.sep_str ++ "lstat.c",
351 lib_libc_glibc ++ "io" ++ path.sep_str ++ "stat64.c",
352 lib_libc_glibc ++ "io" ++ path.sep_str ++ "fstat64.c",
353 lib_libc_glibc ++ "io" ++ path.sep_str ++ "lstat64.c",
354 lib_libc_glibc ++ "io" ++ path.sep_str ++ "fstatat.c",
355 lib_libc_glibc ++ "io" ++ path.sep_str ++ "fstatat64.c",
356 lib_libc_glibc ++ "io" ++ path.sep_str ++ "mknod.c",
357 lib_libc_glibc ++ "io" ++ path.sep_str ++ "mknodat.c",
358 lib_libc_glibc ++ "nptl" ++ path.sep_str ++ "pthread_atfork.c",
359 lib_libc_glibc ++ "debug" ++ path.sep_str ++ "stack_chk_fail_local.c",
360 };
361
362 var c_source_files: [deps.len + 1]Compilation.CSourceFile = undefined;
363
364 c_source_files[0] = blk: {
365 var args = std.ArrayList([]const u8).init(arena);
366 try args.appendSlice(&[_][]const u8{
367 "-std=gnu11",
368 "-fgnu89-inline",
369 "-g",
370 "-O2",
371 "-fmerge-all-constants",
372 "-fno-stack-protector",
373 "-fmath-errno",
374 "-fno-stack-protector",
375 "-I",
376 try lib_path(comp, arena, lib_libc_glibc ++ "csu"),
377 });
378 try add_include_dirs(comp, arena, &args);
379 try args.appendSlice(&[_][]const u8{
380 "-DSTACK_PROTECTOR_LEVEL=0",
381 "-fPIC",
382 "-fno-stack-protector",
383 "-ftls-model=initial-exec",
384 "-D_LIBC_REENTRANT",
385 "-include",
386 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-modules.h"),
387 "-DMODULE_NAME=libc",
388 "-Wno-nonportable-include-path",
389 "-include",
390 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-symbols.h"),
391 "-DPIC",
392 "-DLIBC_NONSHARED=1",
393 "-DTOP_NAMESPACE=glibc",
394 });
395 break :blk .{
396 .src_path = try lib_path(comp, arena, lib_libc_glibc ++ "csu" ++ path.sep_str ++ "elf-init.c"),
397 .extra_flags = args.items,
398 };
399 };
400
401 for (deps) |dep, i| {
402 var args = std.ArrayList([]const u8).init(arena);
403 try args.appendSlice(&[_][]const u8{
404 "-std=gnu11",
405 "-fgnu89-inline",
406 "-g",
407 "-O2",
408 "-fmerge-all-constants",
409 "-fno-stack-protector",
410 "-fmath-errno",
411 "-ftls-model=initial-exec",
412 "-Wno-ignored-attributes",
413 });
414 try add_include_dirs(comp, arena, &args);
415 try args.appendSlice(&[_][]const u8{
416 "-D_LIBC_REENTRANT",
417 "-include",
418 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-modules.h"),
419 "-DMODULE_NAME=libc",
420 "-Wno-nonportable-include-path",
421 "-include",
422 try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-symbols.h"),
423 "-DPIC",
424 "-DLIBC_NONSHARED=1",
425 "-DTOP_NAMESPACE=glibc",
426 });
427 c_source_files[i + 1] = .{
428 .src_path = try lib_path(comp, arena, dep),
429 .extra_flags = args.items,
430 };
431 }
432 return build_crt_file(comp, "libc_nonshared.a", .Lib, &c_source_files);
346 },433 },
347 }434 }
348}435}
...@@ -588,6 +675,7 @@ fn lib_path(comp: *Compilation, arena: *Allocator, sub_path: []const u8) ![]cons...@@ -588,6 +675,7 @@ fn lib_path(comp: *Compilation, arena: *Allocator, sub_path: []const u8) ![]cons
588fn build_crt_file(675fn build_crt_file(
589 comp: *Compilation,676 comp: *Compilation,
590 basename: []const u8,677 basename: []const u8,
678 output_mode: std.builtin.OutputMode,
591 c_source_files: []const Compilation.CSourceFile,679 c_source_files: []const Compilation.CSourceFile,
592) !void {680) !void {
593 const tracy = trace(@src());681 const tracy = trace(@src());
...@@ -605,7 +693,7 @@ fn build_crt_file(...@@ -605,7 +693,7 @@ fn build_crt_file(
605 .target = comp.getTarget(),693 .target = comp.getTarget(),
606 .root_name = mem.split(basename, ".").next().?,694 .root_name = mem.split(basename, ".").next().?,
607 .root_pkg = null,695 .root_pkg = null,
608 .output_mode = .Obj,696 .output_mode = output_mode,
609 .rand = comp.rand,697 .rand = comp.rand,
610 .libc_installation = comp.bin_file.options.libc_installation,698 .libc_installation = comp.bin_file.options.libc_installation,
611 .emit_bin = emit_bin,699 .emit_bin = emit_bin,