| ... | ... | @@ -574,7 +574,7 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path) |
| 574 | 574 | |
| 575 | 575 | CodeGen *child_gen = create_child_codegen(parent_gen, full_path, child_out_type, |
| 576 | 576 | parent_gen->libc); |
| 577 | | codegen_set_is_static(child_gen, true); |
| 577 | child_gen->is_static = true; |
| 578 | 578 | codegen_set_out_name(child_gen, buf_create_from_str(aname)); |
| 579 | 579 | |
| 580 | 580 | // This is so that compiler_rt and builtin libraries know whether they |
| ... | ... | @@ -699,7 +699,7 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 699 | 699 | lj->args.append(getLDMOption(g->zig_target)); |
| 700 | 700 | |
| 701 | 701 | bool is_lib = g->out_type == OutTypeLib; |
| 702 | | bool shared = !g->is_static && is_lib; |
| 702 | bool is_dyn_lib = !g->is_static && is_lib; |
| 703 | 703 | Buf *soname = nullptr; |
| 704 | 704 | if (g->is_static) { |
| 705 | 705 | if (g->zig_target->arch == ZigLLVM_arm || g->zig_target->arch == ZigLLVM_armeb || |
| ... | ... | @@ -709,7 +709,7 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 709 | 709 | } else { |
| 710 | 710 | lj->args.append("-static"); |
| 711 | 711 | } |
| 712 | | } else if (shared) { |
| 712 | } else if (is_dyn_lib) { |
| 713 | 713 | lj->args.append("-shared"); |
| 714 | 714 | |
| 715 | 715 | if (buf_len(&g->output_file_path) == 0) { |
| ... | ... | @@ -780,7 +780,7 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 780 | 780 | |
| 781 | 781 | } |
| 782 | 782 | |
| 783 | | if (shared) { |
| 783 | if (is_dyn_lib) { |
| 784 | 784 | lj->args.append("-soname"); |
| 785 | 785 | lj->args.append(buf_ptr(soname)); |
| 786 | 786 | } |
| ... | ... | @@ -1231,36 +1231,34 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 1231 | 1231 | } |
| 1232 | 1232 | |
| 1233 | 1233 | bool is_lib = g->out_type == OutTypeLib; |
| 1234 | | bool shared = !g->is_static && is_lib; |
| 1234 | bool is_dyn_lib = !g->is_static && is_lib; |
| 1235 | 1235 | if (g->is_static) { |
| 1236 | 1236 | lj->args.append("-static"); |
| 1237 | 1237 | } else { |
| 1238 | 1238 | lj->args.append("-dynamic"); |
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | | if (is_lib) { |
| 1242 | | if (!g->is_static) { |
| 1243 | | lj->args.append("-dylib"); |
| 1241 | if (is_dyn_lib) { |
| 1242 | lj->args.append("-dylib"); |
| 1244 | 1243 | |
| 1245 | | Buf *compat_vers = buf_sprintf("%" ZIG_PRI_usize ".0.0", g->version_major); |
| 1246 | | lj->args.append("-compatibility_version"); |
| 1247 | | lj->args.append(buf_ptr(compat_vers)); |
| 1244 | Buf *compat_vers = buf_sprintf("%" ZIG_PRI_usize ".0.0", g->version_major); |
| 1245 | lj->args.append("-compatibility_version"); |
| 1246 | lj->args.append(buf_ptr(compat_vers)); |
| 1248 | 1247 | |
| 1249 | | Buf *cur_vers = buf_sprintf("%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".%" ZIG_PRI_usize, |
| 1250 | | g->version_major, g->version_minor, g->version_patch); |
| 1251 | | lj->args.append("-current_version"); |
| 1252 | | lj->args.append(buf_ptr(cur_vers)); |
| 1248 | Buf *cur_vers = buf_sprintf("%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".%" ZIG_PRI_usize, |
| 1249 | g->version_major, g->version_minor, g->version_patch); |
| 1250 | lj->args.append("-current_version"); |
| 1251 | lj->args.append(buf_ptr(cur_vers)); |
| 1253 | 1252 | |
| 1254 | | // TODO getting an error when running an executable when doing this rpath thing |
| 1255 | | //Buf *dylib_install_name = buf_sprintf("@rpath/lib%s.%" ZIG_PRI_usize ".dylib", |
| 1256 | | // buf_ptr(g->root_out_name), g->version_major); |
| 1257 | | //lj->args.append("-install_name"); |
| 1258 | | //lj->args.append(buf_ptr(dylib_install_name)); |
| 1253 | // TODO getting an error when running an executable when doing this rpath thing |
| 1254 | //Buf *dylib_install_name = buf_sprintf("@rpath/lib%s.%" ZIG_PRI_usize ".dylib", |
| 1255 | // buf_ptr(g->root_out_name), g->version_major); |
| 1256 | //lj->args.append("-install_name"); |
| 1257 | //lj->args.append(buf_ptr(dylib_install_name)); |
| 1259 | 1258 | |
| 1260 | | if (buf_len(&g->output_file_path) == 0) { |
| 1261 | | buf_appendf(&g->output_file_path, "lib%s.%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".dylib", |
| 1262 | | buf_ptr(g->root_out_name), g->version_major, g->version_minor, g->version_patch); |
| 1263 | | } |
| 1259 | if (buf_len(&g->output_file_path) == 0) { |
| 1260 | buf_appendf(&g->output_file_path, "lib%s.%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".dylib", |
| 1261 | buf_ptr(g->root_out_name), g->version_major, g->version_minor, g->version_patch); |
| 1264 | 1262 | } |
| 1265 | 1263 | } |
| 1266 | 1264 | |
| ... | ... | @@ -1302,38 +1300,14 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 1302 | 1300 | Buf *rpath = g->rpath_list.at(i); |
| 1303 | 1301 | add_rpath(lj, rpath); |
| 1304 | 1302 | } |
| 1305 | | add_rpath(lj, &g->output_file_path); |
| 1303 | if (is_dyn_lib) { |
| 1304 | add_rpath(lj, &g->output_file_path); |
| 1305 | } |
| 1306 | 1306 | |
| 1307 | | if (shared) { |
| 1307 | if (is_dyn_lib) { |
| 1308 | 1308 | if (g->system_linker_hack) { |
| 1309 | 1309 | lj->args.append("-headerpad_max_install_names"); |
| 1310 | 1310 | } |
| 1311 | | } else if (g->is_static) { |
| 1312 | | lj->args.append("-lcrt0.o"); |
| 1313 | | } else { |
| 1314 | | switch (platform.kind) { |
| 1315 | | case MacOS: |
| 1316 | | if (darwin_version_lt(&platform, 10, 5)) { |
| 1317 | | lj->args.append("-lcrt1.o"); |
| 1318 | | } else if (darwin_version_lt(&platform, 10, 6)) { |
| 1319 | | lj->args.append("-lcrt1.10.5.o"); |
| 1320 | | } else if (darwin_version_lt(&platform, 10, 8)) { |
| 1321 | | lj->args.append("-lcrt1.10.6.o"); |
| 1322 | | } |
| 1323 | | break; |
| 1324 | | case IPhoneOS: |
| 1325 | | if (g->zig_target->arch == ZigLLVM_aarch64) { |
| 1326 | | // iOS does not need any crt1 files for arm64 |
| 1327 | | } else if (darwin_version_lt(&platform, 3, 1)) { |
| 1328 | | lj->args.append("-lcrt1.o"); |
| 1329 | | } else if (darwin_version_lt(&platform, 6, 0)) { |
| 1330 | | lj->args.append("-lcrt1.3.1.o"); |
| 1331 | | } |
| 1332 | | break; |
| 1333 | | case IPhoneOSSimulator: |
| 1334 | | // no crt1.o needed |
| 1335 | | break; |
| 1336 | | } |
| 1337 | 1311 | } |
| 1338 | 1312 | |
| 1339 | 1313 | for (size_t i = 0; i < g->lib_dirs.length; i += 1) { |
| ... | ... | @@ -1347,7 +1321,7 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 1347 | 1321 | } |
| 1348 | 1322 | |
| 1349 | 1323 | // compiler_rt on darwin is missing some stuff, so we still build it and rely on LinkOnce |
| 1350 | | if (g->out_type == OutTypeExe || (g->out_type == OutTypeLib && !g->is_static)) { |
| 1324 | if (g->out_type == OutTypeExe || is_dyn_lib) { |
| 1351 | 1325 | Buf *compiler_rt_o_path = build_compiler_rt(g); |
| 1352 | 1326 | lj->args.append(buf_ptr(compiler_rt_o_path)); |
| 1353 | 1327 | } |
| ... | ... | @@ -1356,11 +1330,7 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 1356 | 1330 | for (size_t lib_i = 0; lib_i < g->link_libs_list.length; lib_i += 1) { |
| 1357 | 1331 | LinkLib *link_lib = g->link_libs_list.at(lib_i); |
| 1358 | 1332 | if (buf_eql_str(link_lib->name, "c")) { |
| 1359 | | // on Darwin, libSystem has libc in it, but also you have to use it |
| 1360 | | // to make syscalls because the syscall numbers are not documented |
| 1361 | | // and change between versions. |
| 1362 | | // so we always link against libSystem |
| 1363 | | lj->args.append("-lSystem"); |
| 1333 | continue; |
| 1364 | 1334 | } else { |
| 1365 | 1335 | if (strchr(buf_ptr(link_lib->name), '/') == nullptr) { |
| 1366 | 1336 | Buf *arg = buf_sprintf("-l%s", buf_ptr(link_lib->name)); |
| ... | ... | @@ -1370,6 +1340,11 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 1370 | 1340 | } |
| 1371 | 1341 | } |
| 1372 | 1342 | } |
| 1343 | // on Darwin, libSystem has libc in it, but also you have to use it |
| 1344 | // to make syscalls because the syscall numbers are not documented |
| 1345 | // and change between versions. |
| 1346 | // so we always link against libSystem |
| 1347 | lj->args.append("-lSystem"); |
| 1373 | 1348 | } else { |
| 1374 | 1349 | lj->args.append("-undefined"); |
| 1375 | 1350 | lj->args.append("dynamic_lookup"); |