| ... | ... | @@ -2002,6 +2002,7 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 2002 | 2002 | lj->args.append(buf_ptr(compiler_rt_o_path)); |
| 2003 | 2003 | } |
| 2004 | 2004 | |
| 2005 | // libraries |
| 2005 | 2006 | for (size_t i = 0; i < g->link_libs_list.length; i += 1) { |
| 2006 | 2007 | LinkLib *link_lib = g->link_libs_list.at(i); |
| 2007 | 2008 | if (buf_eql_str(link_lib->name, "c")) { |
| ... | ... | @@ -2662,8 +2663,8 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 2662 | 2663 | static void construct_linker_job_macho(LinkJob *lj) { |
| 2663 | 2664 | CodeGen *g = lj->codegen; |
| 2664 | 2665 | |
| 2665 | | // LLD MACH-O has no error limit option. |
| 2666 | | //lj->args.append("-error-limit=0"); |
| 2666 | lj->args.append("-error-limit"); |
| 2667 | lj->args.append("0"); |
| 2667 | 2668 | lj->args.append("-demangle"); |
| 2668 | 2669 | |
| 2669 | 2670 | switch (g->linker_gc_sections) { |
| ... | ... | @@ -2736,6 +2737,7 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 2736 | 2737 | lj->args.append("-iphoneos_version_min"); |
| 2737 | 2738 | } |
| 2738 | 2739 | } |
| 2740 | |
| 2739 | 2741 | Buf *version_string = buf_sprintf("%d.%d.%d", |
| 2740 | 2742 | g->zig_target->glibc_or_darwin_version->major, |
| 2741 | 2743 | g->zig_target->glibc_or_darwin_version->minor, |
| ... | ... | @@ -2744,6 +2746,12 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 2744 | 2746 | |
| 2745 | 2747 | lj->args.append("-sdk_version"); |
| 2746 | 2748 | lj->args.append(buf_ptr(version_string)); |
| 2749 | } else if (stage2_is_zig0 && g->zig_target->os == OsMacOSX) { |
| 2750 | // running `zig0`; `-pie` requires versions >= 10.5; select 10.13 |
| 2751 | lj->args.append("-macosx_version_min"); |
| 2752 | lj->args.append("10.13"); |
| 2753 | lj->args.append("-sdk_version"); |
| 2754 | lj->args.append("10.13"); |
| 2747 | 2755 | } |
| 2748 | 2756 | |
| 2749 | 2757 | if (g->out_type == OutTypeExe) { |
| ... | ... | @@ -2773,45 +2781,74 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 2773 | 2781 | lj->args.append(lib_dir); |
| 2774 | 2782 | } |
| 2775 | 2783 | |
| 2784 | // .o files |
| 2776 | 2785 | for (size_t i = 0; i < g->link_objects.length; i += 1) { |
| 2777 | 2786 | lj->args.append((const char *)buf_ptr(g->link_objects.at(i))); |
| 2778 | 2787 | } |
| 2779 | 2788 | |
| 2780 | | // libc++ dep |
| 2781 | | if (g->libcpp_link_lib != nullptr && g->out_type != OutTypeObj) { |
| 2782 | | lj->args.append(build_libcxxabi(g, lj->build_dep_prog_node)); |
| 2783 | | lj->args.append(build_libcxx(g, lj->build_dep_prog_node)); |
| 2784 | | } |
| 2785 | | |
| 2786 | 2789 | // compiler_rt on darwin is missing some stuff, so we still build it and rely on LinkOnce |
| 2787 | 2790 | if (g->out_type == OutTypeExe || is_dyn_lib) { |
| 2788 | 2791 | Buf *compiler_rt_o_path = build_compiler_rt(g, OutTypeLib, lj->build_dep_prog_node); |
| 2789 | 2792 | lj->args.append(buf_ptr(compiler_rt_o_path)); |
| 2790 | 2793 | } |
| 2791 | 2794 | |
| 2792 | | if (g->zig_target->is_native_os) { |
| 2793 | | for (size_t lib_i = 0; lib_i < g->link_libs_list.length; lib_i += 1) { |
| 2794 | | LinkLib *link_lib = g->link_libs_list.at(lib_i); |
| 2795 | | if (target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) { |
| 2796 | | // handled by libSystem |
| 2797 | | continue; |
| 2798 | | } |
| 2799 | | if (strchr(buf_ptr(link_lib->name), '/') == nullptr) { |
| 2800 | | Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib->name)); |
| 2801 | | lj->args.append(buf_ptr(arg)); |
| 2802 | | } else { |
| 2803 | | lj->args.append(buf_ptr(link_lib->name)); |
| 2804 | | } |
| 2795 | // libraries |
| 2796 | for (size_t lib_i = 0; lib_i < g->link_libs_list.length; lib_i += 1) { |
| 2797 | LinkLib *link_lib = g->link_libs_list.at(lib_i); |
| 2798 | if (buf_eql_str(link_lib->name, "c")) { |
| 2799 | // libc is linked specially |
| 2800 | continue; |
| 2801 | } |
| 2802 | if (target_is_libcpp_lib_name(g->zig_target, buf_ptr(link_lib->name))) { |
| 2803 | // libc++ is linked specially |
| 2804 | continue; |
| 2805 | 2805 | } |
| 2806 | if (g->zig_target->is_native_os && target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) { |
| 2807 | // libSystem is linked specially |
| 2808 | continue; |
| 2809 | } |
| 2810 | |
| 2811 | Buf *arg; |
| 2812 | if (buf_starts_with_str(link_lib->name, "/") || buf_ends_with_str(link_lib->name, ".a") || |
| 2813 | buf_ends_with_str(link_lib->name, ".dylib")) |
| 2814 | { |
| 2815 | arg = link_lib->name; |
| 2816 | } else { |
| 2817 | arg = buf_sprintf("-l%s", buf_ptr(link_lib->name)); |
| 2818 | } |
| 2819 | lj->args.append(buf_ptr(arg)); |
| 2820 | } |
| 2821 | |
| 2822 | // libc++ dep |
| 2823 | if (g->libcpp_link_lib != nullptr && g->out_type != OutTypeObj) { |
| 2824 | lj->args.append(build_libcxxabi(g, lj->build_dep_prog_node)); |
| 2825 | lj->args.append(build_libcxx(g, lj->build_dep_prog_node)); |
| 2826 | } |
| 2827 | |
| 2828 | // libc dep |
| 2829 | if (g->zig_target->is_native_os || stage2_is_zig0) { |
| 2806 | 2830 | // on Darwin, libSystem has libc in it, but also you have to use it |
| 2807 | 2831 | // to make syscalls because the syscall numbers are not documented |
| 2808 | 2832 | // and change between versions. |
| 2809 | 2833 | // so we always link against libSystem |
| 2810 | 2834 | lj->args.append("-lSystem"); |
| 2811 | 2835 | } |
| 2836 | |
| 2837 | for (size_t i = 0; i < g->framework_dirs.length; i += 1) { |
| 2838 | const char *framework_dir = g->framework_dirs.at(i); |
| 2839 | lj->args.append("-F"); |
| 2840 | lj->args.append(framework_dir); |
| 2841 | } |
| 2842 | |
| 2843 | for (size_t i = 0; i < g->darwin_frameworks.length; i += 1) { |
| 2844 | lj->args.append("-framework"); |
| 2845 | lj->args.append(buf_ptr(g->darwin_frameworks.at(i))); |
| 2846 | } |
| 2847 | |
| 2812 | 2848 | switch (g->linker_allow_shlib_undefined) { |
| 2813 | 2849 | case OptionalBoolNull: |
| 2814 | | if (!g->zig_target->is_native_os) { |
| 2850 | if (!g->zig_target->is_native_os && !stage2_is_zig0) { |
| 2851 | // TODO https://github.com/ziglang/zig/issues/5059 |
| 2815 | 2852 | lj->args.append("-undefined"); |
| 2816 | 2853 | lj->args.append("dynamic_lookup"); |
| 2817 | 2854 | } |
| ... | ... | @@ -2831,18 +2868,6 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 2831 | 2868 | lj->args.append("-Bsymbolic"); |
| 2832 | 2869 | break; |
| 2833 | 2870 | } |
| 2834 | | |
| 2835 | | for (size_t i = 0; i < g->framework_dirs.length; i += 1) { |
| 2836 | | const char *framework_dir = g->framework_dirs.at(i); |
| 2837 | | lj->args.append("-F"); |
| 2838 | | lj->args.append(framework_dir); |
| 2839 | | } |
| 2840 | | |
| 2841 | | for (size_t i = 0; i < g->darwin_frameworks.length; i += 1) { |
| 2842 | | lj->args.append("-framework"); |
| 2843 | | lj->args.append(buf_ptr(g->darwin_frameworks.at(i))); |
| 2844 | | } |
| 2845 | | |
| 2846 | 2871 | } |
| 2847 | 2872 | |
| 2848 | 2873 | static void construct_linker_job(LinkJob *lj) { |
| ... | ... | @@ -2920,7 +2945,6 @@ void codegen_link(CodeGen *g) { |
| 2920 | 2945 | |
| 2921 | 2946 | construct_linker_job(&lj); |
| 2922 | 2947 | |
| 2923 | | |
| 2924 | 2948 | if (g->verbose_link) { |
| 2925 | 2949 | for (size_t i = 0; i < lj.args.length; i += 1) { |
| 2926 | 2950 | const char *space = (i != 0) ? " " : ""; |