| author | |
| committer | |
| log | 66d86eccbe43e01500bd57dba13a4ce68aba8921 |
| tree | 5b695c1cc8f10d1d153411d5ee6ff0ddf7e56dc2 |
| parent | c1793d61061a112dc3d58c33ac0d3a1ebc8fb35e |
| parent | 7330a6102f7a8108ee364b9de79efe4a70049167 |
| signature |
5 files changed, 45 insertions(+), 67 deletions(-)
src/cache_hash.cpp+2| ... | ... | @@ -470,6 +470,8 @@ Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) { |
| 470 | 470 | Error err; |
| 471 | 471 | Buf *contents = buf_alloc(); |
| 472 | 472 | if ((err = os_fetch_file_path(dep_file_path, contents))) { |
| 473 | if (err == ErrorFileNotFound) | |
| 474 | return err; | |
| 473 | 475 | if (verbose) { |
| 474 | 476 | fprintf(stderr, "unable to read .d file: %s\n", err_str(err)); |
| 475 | 477 | } |
src/codegen.cpp+10-27| ... | ... | @@ -8334,8 +8334,6 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa |
| 8334 | 8334 | for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) { |
| 8335 | 8335 | args.append(g->clang_argv[arg_i]); |
| 8336 | 8336 | } |
| 8337 | ||
| 8338 | ||
| 8339 | 8337 | } |
| 8340 | 8338 | |
| 8341 | 8339 | void codegen_translate_c(CodeGen *g, Buf *full_path, FILE *out_file, bool use_userland_implementation) { |
| ... | ... | @@ -8582,24 +8580,6 @@ static void gen_root_source(CodeGen *g) { |
| 8582 | 8580 | |
| 8583 | 8581 | } |
| 8584 | 8582 | |
| 8585 | void codegen_add_assembly(CodeGen *g, Buf *path) { | |
| 8586 | g->assembly_files.append(path); | |
| 8587 | } | |
| 8588 | ||
| 8589 | static void gen_global_asm(CodeGen *g) { | |
| 8590 | Buf contents = BUF_INIT; | |
| 8591 | Error err; | |
| 8592 | for (size_t i = 0; i < g->assembly_files.length; i += 1) { | |
| 8593 | Buf *asm_file = g->assembly_files.at(i); | |
| 8594 | // No need to use the caching system for these fetches because they | |
| 8595 | // are handled separately. | |
| 8596 | if ((err = os_fetch_file_path(asm_file, &contents))) { | |
| 8597 | zig_panic("Unable to read %s: %s", buf_ptr(asm_file), err_str(err)); | |
| 8598 | } | |
| 8599 | buf_append_buf(&g->global_asm, &contents); | |
| 8600 | } | |
| 8601 | } | |
| 8602 | ||
| 8603 | 8583 | static void print_zig_cc_cmd(const char *zig_exe, ZigList<const char *> *args) { |
| 8604 | 8584 | fprintf(stderr, "%s", zig_exe); |
| 8605 | 8585 | for (size_t arg_i = 0; arg_i < args->length; arg_i += 1) { |
| ... | ... | @@ -8750,10 +8730,16 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { |
| 8750 | 8730 | |
| 8751 | 8731 | // add the files depended on to the cache system |
| 8752 | 8732 | if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) { |
| 8753 | fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err)); | |
| 8754 | exit(1); | |
| 8733 | // Don't treat the absence of the .d file as a fatal error, the | |
| 8734 | // compiler may not produce one eg. when compiling .s files | |
| 8735 | if (err != ErrorFileNotFound) { | |
| 8736 | fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err)); | |
| 8737 | exit(1); | |
| 8738 | } | |
| 8739 | } | |
| 8740 | if (err != ErrorFileNotFound) { | |
| 8741 | os_delete_file(out_dep_path); | |
| 8755 | 8742 | } |
| 8756 | os_delete_file(out_dep_path); | |
| 8757 | 8743 | |
| 8758 | 8744 | if ((err = cache_final(cache_hash, &digest))) { |
| 8759 | 8745 | fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err)); |
| ... | ... | @@ -9330,8 +9316,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 9330 | 9316 | cache_list_of_buf(ch, g->darwin_frameworks.items, g->darwin_frameworks.length); |
| 9331 | 9317 | cache_list_of_buf(ch, g->rpath_list.items, g->rpath_list.length); |
| 9332 | 9318 | cache_list_of_buf(ch, g->forbidden_libs.items, g->forbidden_libs.length); |
| 9333 | cache_list_of_file(ch, g->assembly_files.items, g->assembly_files.length); | |
| 9334 | cache_int(ch, g->emit_file_type); | |
| 9335 | 9319 | cache_int(ch, g->build_mode); |
| 9336 | 9320 | cache_int(ch, g->out_type); |
| 9337 | 9321 | cache_bool(ch, g->zig_target->is_native); |
| ... | ... | @@ -9392,7 +9376,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 9392 | 9376 | } |
| 9393 | 9377 | |
| 9394 | 9378 | static bool need_llvm_module(CodeGen *g) { |
| 9395 | return g->assembly_files.length != 0 || buf_len(&g->root_package->root_src_path) != 0; | |
| 9379 | return buf_len(&g->root_package->root_src_path) != 0; | |
| 9396 | 9380 | } |
| 9397 | 9381 | |
| 9398 | 9382 | static void resolve_out_paths(CodeGen *g) { |
| ... | ... | @@ -9499,7 +9483,6 @@ void codegen_build_and_link(CodeGen *g) { |
| 9499 | 9483 | |
| 9500 | 9484 | codegen_add_time_event(g, "Semantic Analysis"); |
| 9501 | 9485 | |
| 9502 | gen_global_asm(g); | |
| 9503 | 9486 | gen_root_source(g); |
| 9504 | 9487 | |
| 9505 | 9488 | } |
src/link.cpp+31-30| ... | ... | @@ -59,14 +59,6 @@ static const char *build_libc_object(CodeGen *parent_gen, const char *name, CFil |
| 59 | 59 | return buf_ptr(&child_gen->output_file_path); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | static const char *build_asm_object(CodeGen *parent_gen, const char *name, Buf *file) { | |
| 63 | CodeGen *child_gen = create_child_codegen(parent_gen, nullptr, OutTypeObj, nullptr); | |
| 64 | codegen_set_out_name(child_gen, buf_create_from_str(name)); | |
| 65 | codegen_add_assembly(child_gen, file); | |
| 66 | codegen_build_and_link(child_gen); | |
| 67 | return buf_ptr(&child_gen->output_file_path); | |
| 68 | } | |
| 69 | ||
| 70 | 62 | static const char *path_from_zig_lib(CodeGen *g, const char *dir, const char *subpath) { |
| 71 | 63 | Buf *dir1 = buf_alloc(); |
| 72 | 64 | os_path_join(g->zig_lib_dir, buf_create_from_str(dir), dir1); |
| ... | ... | @@ -140,6 +132,7 @@ static const char *build_libunwind(CodeGen *parent) { |
| 140 | 132 | c_file->args.append(path_from_libunwind(parent, "include")); |
| 141 | 133 | c_file->args.append("-fPIC"); |
| 142 | 134 | c_file->args.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS"); |
| 135 | c_file->args.append("-Wa,--noexecstack"); | |
| 143 | 136 | if (parent->zig_target->is_native) { |
| 144 | 137 | c_file->args.append("-D_LIBUNWIND_IS_NATIVE_ONLY"); |
| 145 | 138 | } |
| ... | ... | @@ -406,12 +399,13 @@ static const char *musl_arch_name(const ZigTarget *target) { |
| 406 | 399 | } |
| 407 | 400 | } |
| 408 | 401 | |
| 409 | static Buf *musl_start_asm_path(CodeGen *parent, const char *file) { | |
| 410 | return buf_sprintf("%s" OS_SEP "libc" OS_SEP "musl" OS_SEP "crt" OS_SEP "%s" OS_SEP "%s", | |
| 411 | buf_ptr(parent->zig_lib_dir), musl_arch_name(parent->zig_target), file); | |
| 402 | static const char *musl_start_asm_path(CodeGen *parent, const char *file) { | |
| 403 | Buf *result = buf_sprintf("%s" OS_SEP "libc" OS_SEP "musl" OS_SEP "crt" OS_SEP "%s" OS_SEP "%s", | |
| 404 | buf_ptr(parent->zig_lib_dir), musl_arch_name(parent->zig_target), file); | |
| 405 | return buf_ptr(result); | |
| 412 | 406 | } |
| 413 | 407 | |
| 414 | static void musl_add_cc_args(CodeGen *parent, CFile *c_file) { | |
| 408 | static void musl_add_cc_args(CodeGen *parent, CFile *c_file, bool want_O3) { | |
| 415 | 409 | c_file->args.append("-std=c99"); |
| 416 | 410 | c_file->args.append("-ffreestanding"); |
| 417 | 411 | // Musl adds these args to builds with gcc but clang does not support them. |
| ... | ... | @@ -448,7 +442,11 @@ static void musl_add_cc_args(CodeGen *parent, CFile *c_file) { |
| 448 | 442 | c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "generic-musl", |
| 449 | 443 | buf_ptr(parent->zig_lib_dir)))); |
| 450 | 444 | |
| 451 | c_file->args.append("-Os"); | |
| 445 | if (want_O3) | |
| 446 | c_file->args.append("-O3"); | |
| 447 | else | |
| 448 | c_file->args.append("-Os"); | |
| 449 | ||
| 452 | 450 | c_file->args.append("-fomit-frame-pointer"); |
| 453 | 451 | c_file->args.append("-fno-unwind-tables"); |
| 454 | 452 | c_file->args.append("-fno-asynchronous-unwind-tables"); |
| ... | ... | @@ -574,19 +572,14 @@ static const char *build_musl(CodeGen *parent) { |
| 574 | 572 | Buf *full_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "%s", |
| 575 | 573 | buf_ptr(parent->zig_lib_dir), buf_ptr(src_file)); |
| 576 | 574 | |
| 577 | if (src_kind == MuslSrcAsm) { | |
| 578 | codegen_add_assembly(child_gen, full_path); | |
| 579 | } else { | |
| 580 | CFile *c_file = allocate<CFile>(1); | |
| 581 | c_file->source_path = buf_ptr(full_path); | |
| 582 | musl_add_cc_args(parent, c_file); | |
| 583 | c_file->args.append("-Qunused-arguments"); | |
| 584 | c_file->args.append("-w"); // disable all warnings | |
| 585 | if (src_kind == MuslSrcO3) { | |
| 586 | c_file->args.append("-O3"); | |
| 587 | } | |
| 588 | c_source_files.append(c_file); | |
| 589 | } | |
| 575 | CFile *c_file = allocate<CFile>(1); | |
| 576 | c_file->source_path = buf_ptr(full_path); | |
| 577 | ||
| 578 | musl_add_cc_args(parent, c_file, src_kind == MuslSrcO3); | |
| 579 | c_file->args.append("-Qunused-arguments"); | |
| 580 | c_file->args.append("-w"); // disable all warnings | |
| 581 | ||
| 582 | c_source_files.append(c_file); | |
| 590 | 583 | } |
| 591 | 584 | |
| 592 | 585 | child_gen->c_source_files = c_source_files; |
| ... | ... | @@ -744,20 +737,28 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file) { |
| 744 | 737 | } |
| 745 | 738 | } else if (parent->libc == nullptr && target_is_musl(parent->zig_target)) { |
| 746 | 739 | if (strcmp(file, "crti.o") == 0) { |
| 747 | return build_asm_object(parent, "crti", musl_start_asm_path(parent, "crti.s")); | |
| 740 | CFile *c_file = allocate<CFile>(1); | |
| 741 | c_file->source_path = musl_start_asm_path(parent, "crti.s"); | |
| 742 | musl_add_cc_args(parent, c_file, false); | |
| 743 | c_file->args.append("-Qunused-arguments"); | |
| 744 | return build_libc_object(parent, "crti", c_file); | |
| 748 | 745 | } else if (strcmp(file, "crtn.o") == 0) { |
| 749 | return build_asm_object(parent, "crtn", musl_start_asm_path(parent, "crtn.s")); | |
| 746 | CFile *c_file = allocate<CFile>(1); | |
| 747 | c_file->source_path = musl_start_asm_path(parent, "crtn.s"); | |
| 748 | c_file->args.append("-Qunused-arguments"); | |
| 749 | musl_add_cc_args(parent, c_file, false); | |
| 750 | return build_libc_object(parent, "crtn", c_file); | |
| 750 | 751 | } else if (strcmp(file, "crt1.o") == 0) { |
| 751 | 752 | CFile *c_file = allocate<CFile>(1); |
| 752 | 753 | c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "crt1.c"); |
| 753 | musl_add_cc_args(parent, c_file); | |
| 754 | musl_add_cc_args(parent, c_file, false); | |
| 754 | 755 | c_file->args.append("-fno-stack-protector"); |
| 755 | 756 | c_file->args.append("-DCRT"); |
| 756 | 757 | return build_libc_object(parent, "crt1", c_file); |
| 757 | 758 | } else if (strcmp(file, "Scrt1.o") == 0) { |
| 758 | 759 | CFile *c_file = allocate<CFile>(1); |
| 759 | 760 | c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "Scrt1.c"); |
| 760 | musl_add_cc_args(parent, c_file); | |
| 761 | musl_add_cc_args(parent, c_file, false); | |
| 761 | 762 | c_file->args.append("-fPIC"); |
| 762 | 763 | c_file->args.append("-fno-stack-protector"); |
| 763 | 764 | c_file->args.append("-DCRT"); |
src/main.cpp+1-9| ... | ... | @@ -48,7 +48,6 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) { |
| 48 | 48 | " zen print zen of zig and exit\n" |
| 49 | 49 | "\n" |
| 50 | 50 | "Compile Options:\n" |
| 51 | " --assembly [source] add assembly file to build\n" | |
| 52 | 51 | " --c-source [options] [file] compile C source code\n" |
| 53 | 52 | " --cache-dir [path] override the local cache directory\n" |
| 54 | 53 | " --cache [auto|off|on] build in cache, print output path to stdout\n" |
| ... | ... | @@ -428,7 +427,6 @@ int main(int argc, char **argv) { |
| 428 | 427 | bool each_lib_rpath = false; |
| 429 | 428 | ZigList<const char *> objects = {0}; |
| 430 | 429 | ZigList<CFile *> c_source_files = {0}; |
| 431 | ZigList<const char *> asm_files = {0}; | |
| 432 | 430 | const char *test_filter = nullptr; |
| 433 | 431 | const char *test_name_prefix = nullptr; |
| 434 | 432 | size_t ver_major = 0; |
| ... | ... | @@ -774,8 +772,6 @@ int main(int argc, char **argv) { |
| 774 | 772 | break; |
| 775 | 773 | } |
| 776 | 774 | } |
| 777 | } else if (strcmp(arg, "--assembly") == 0) { | |
| 778 | asm_files.append(argv[i]); | |
| 779 | 775 | } else if (strcmp(arg, "--cache-dir") == 0) { |
| 780 | 776 | cache_dir = argv[i]; |
| 781 | 777 | } else if (strcmp(arg, "-target") == 0) { |
| ... | ... | @@ -971,14 +967,13 @@ int main(int argc, char **argv) { |
| 971 | 967 | case CmdTranslateCUserland: |
| 972 | 968 | case CmdTest: |
| 973 | 969 | { |
| 974 | if (cmd == CmdBuild && !in_file && objects.length == 0 && asm_files.length == 0 && | |
| 970 | if (cmd == CmdBuild && !in_file && objects.length == 0 && | |
| 975 | 971 | c_source_files.length == 0) |
| 976 | 972 | { |
| 977 | 973 | fprintf(stderr, |
| 978 | 974 | "Expected at least one of these things:\n" |
| 979 | 975 | " * Zig root source file argument\n" |
| 980 | 976 | " * --object argument\n" |
| 981 | " * --assembly argument\n" | |
| 982 | 977 | " * --c-source argument\n"); |
| 983 | 978 | return print_error_usage(arg0); |
| 984 | 979 | } else if ((cmd == CmdTranslateC || cmd == CmdTranslateCUserland || |
| ... | ... | @@ -1130,9 +1125,6 @@ int main(int argc, char **argv) { |
| 1130 | 1125 | for (size_t i = 0; i < objects.length; i += 1) { |
| 1131 | 1126 | codegen_add_object(g, buf_create_from_str(objects.at(i))); |
| 1132 | 1127 | } |
| 1133 | for (size_t i = 0; i < asm_files.length; i += 1) { | |
| 1134 | codegen_add_assembly(g, buf_create_from_str(asm_files.at(i))); | |
| 1135 | } | |
| 1136 | 1128 | } |
| 1137 | 1129 | |
| 1138 | 1130 |
std/build.zig+1-1| ... | ... | @@ -1376,7 +1376,7 @@ pub const LibExeObjStep = struct { |
| 1376 | 1376 | try zig_args.append(name); |
| 1377 | 1377 | }, |
| 1378 | 1378 | LinkObject.AssemblyFile => |asm_file| { |
| 1379 | try zig_args.append("--assembly"); | |
| 1379 | try zig_args.append("--c-source"); | |
| 1380 | 1380 | try zig_args.append(builder.pathFromRoot(asm_file)); |
| 1381 | 1381 | }, |
| 1382 | 1382 | LinkObject.CSourceFile => |c_source_file| { |