| ... | ... | @@ -240,8 +240,6 @@ fn findLib(name: []const u8) ?*const Lib { |
| 240 | 240 | pub const CRTFile = enum { |
| 241 | 241 | crti_o, |
| 242 | 242 | crtn_o, |
| 243 | | start_os, |
| 244 | | abi_note_o, |
| 245 | 243 | scrt1_o, |
| 246 | 244 | libc_nonshared_a, |
| 247 | 245 | }; |
| ... | ... | @@ -272,76 +270,76 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 272 | 270 | "-g", |
| 273 | 271 | "-Wa,--noexecstack", |
| 274 | 272 | }); |
| 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 | }, |
| 291 | 278 | }); |
| 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); |
| 297 | 279 | }, |
| 298 | | .start_os => { |
| 280 | .crtn_o => { |
| 299 | 281 | var args = std.ArrayList([]const u8).init(arena); |
| 300 | 282 | try add_include_dirs(comp, arena, &args); |
| 301 | 283 | try args.appendSlice(&[_][]const u8{ |
| 302 | 284 | "-D_LIBC_REENTRANT", |
| 303 | | "-include", |
| 304 | | try lib_path(comp, arena, lib_libc_glibc ++ "include" ++ path.sep_str ++ "libc-modules.h"), |
| 305 | 285 | "-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", |
| 311 | 286 | "-DTOP_NAMESPACE=glibc", |
| 312 | 287 | "-DASSEMBLER", |
| 313 | 288 | "-g", |
| 314 | 289 | "-Wa,--noexecstack", |
| 315 | 290 | }); |
| 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 | }, |
| 327 | 296 | }); |
| 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); |
| 342 | 297 | }, |
| 343 | 298 | .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 }); |
| 345 | 343 | }, |
| 346 | 344 | .libc_nonshared_a => { |
| 347 | 345 | return error.Unimplemented; // TODO |
| ... | ... | @@ -587,7 +585,11 @@ fn lib_path(comp: *Compilation, arena: *Allocator, sub_path: []const u8) ![]cons |
| 587 | 585 | return path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, sub_path }); |
| 588 | 586 | } |
| 589 | 587 | |
| 590 | | fn build_libc_object(comp: *Compilation, basename: []const u8, c_source_file: Compilation.CSourceFile) !void { |
| 588 | fn build_libc_object( |
| 589 | comp: *Compilation, |
| 590 | basename: []const u8, |
| 591 | c_source_files: []const Compilation.CSourceFile, |
| 592 | ) !void { |
| 591 | 593 | const tracy = trace(@src()); |
| 592 | 594 | defer tracy.end(); |
| 593 | 595 | |
| ... | ... | @@ -616,7 +618,7 @@ fn build_libc_object(comp: *Compilation, basename: []const u8, c_source_file: Co |
| 616 | 618 | .strip = comp.bin_file.options.strip, |
| 617 | 619 | .is_native_os = comp.bin_file.options.is_native_os, |
| 618 | 620 | .self_exe_path = comp.self_exe_path, |
| 619 | | .c_source_files = &[1]Compilation.CSourceFile{c_source_file}, |
| 621 | .c_source_files = c_source_files, |
| 620 | 622 | .debug_cc = comp.debug_cc, |
| 621 | 623 | .debug_link = comp.bin_file.options.debug_link, |
| 622 | 624 | .clang_passthrough_mode = comp.clang_passthrough_mode, |