| author | |
| committer | |
| log | 7438d0fc31f70b3a6d19e1da9a4e3f7918fc9d66 |
| tree | 45c97bea61dd454347202e7371fa1d42d4b60938 |
| parent | ef69e4efa07af12172e6dfd7aa62961f1a5491f9 |
| signature |
6 files changed, 25 insertions(+), 4 deletions(-)
src-self-hosted/stage2.zig+8| ... | @@ -909,6 +909,7 @@ const Stage2Target = extern struct { | ... | @@ -909,6 +909,7 @@ const Stage2Target = extern struct { |
| 909 | os_builtin_str: ?[*:0]const u8, | 909 | os_builtin_str: ?[*:0]const u8, |
| 910 | 910 | ||
| 911 | dynamic_linker: ?[*:0]const u8, | 911 | dynamic_linker: ?[*:0]const u8, |
| 912 | standard_dynamic_linker_path: ?[*:0]const u8, | ||
| 912 | 913 | ||
| 913 | fn fromTarget(self: *Stage2Target, cross_target: CrossTarget) !void { | 914 | fn fromTarget(self: *Stage2Target, cross_target: CrossTarget) !void { |
| 914 | const allocator = std.heap.c_allocator; | 915 | const allocator = std.heap.c_allocator; |
| ... | @@ -1119,6 +1120,12 @@ const Stage2Target = extern struct { | ... | @@ -1119,6 +1120,12 @@ const Stage2Target = extern struct { |
| 1119 | } | 1120 | } |
| 1120 | }; | 1121 | }; |
| 1121 | 1122 | ||
| 1123 | const std_dl = target.standardDynamicLinkerPath(); | ||
| 1124 | const std_dl_z = if (std_dl.get()) |dl| | ||
| 1125 | (try mem.dupeZ(std.heap.c_allocator, u8, dl)).ptr | ||
| 1126 | else | ||
| 1127 | null; | ||
| 1128 | |||
| 1122 | const cache_hash_slice = cache_hash.toOwnedSlice(); | 1129 | const cache_hash_slice = cache_hash.toOwnedSlice(); |
| 1123 | self.* = .{ | 1130 | self.* = .{ |
| 1124 | .arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch | 1131 | .arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch |
| ... | @@ -1134,6 +1141,7 @@ const Stage2Target = extern struct { | ... | @@ -1134,6 +1141,7 @@ const Stage2Target = extern struct { |
| 1134 | .is_native = cross_target.isNative(), | 1141 | .is_native = cross_target.isNative(), |
| 1135 | .glibc_or_darwin_version = glibc_or_darwin_version, | 1142 | .glibc_or_darwin_version = glibc_or_darwin_version, |
| 1136 | .dynamic_linker = dynamic_linker, | 1143 | .dynamic_linker = dynamic_linker, |
| 1144 | .standard_dynamic_linker_path = std_dl_z, | ||
| 1137 | }; | 1145 | }; |
| 1138 | } | 1146 | } |
| 1139 | }; | 1147 | }; |
src/all_types.hpp+1| ... | @@ -2267,6 +2267,7 @@ struct CodeGen { | ... | @@ -2267,6 +2267,7 @@ struct CodeGen { |
| 2267 | Buf *zig_lib_dir; | 2267 | Buf *zig_lib_dir; |
| 2268 | Buf *zig_std_dir; | 2268 | Buf *zig_std_dir; |
| 2269 | Buf *version_script_path; | 2269 | Buf *version_script_path; |
| 2270 | Buf *override_soname; | ||
| 2270 | 2271 | ||
| 2271 | const char **llvm_argv; | 2272 | const char **llvm_argv; |
| 2272 | size_t llvm_argv_len; | 2273 | size_t llvm_argv_len; |
src/codegen.cpp+1| ... | @@ -10510,6 +10510,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { | ... | @@ -10510,6 +10510,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 10510 | cache_str(ch, g->libc->kernel32_lib_dir); | 10510 | cache_str(ch, g->libc->kernel32_lib_dir); |
| 10511 | } | 10511 | } |
| 10512 | cache_buf_opt(ch, g->version_script_path); | 10512 | cache_buf_opt(ch, g->version_script_path); |
| 10513 | cache_buf_opt(ch, g->override_soname); | ||
| 10513 | 10514 | ||
| 10514 | // gen_c_objects appends objects to g->link_objects which we want to include in the hash | 10515 | // gen_c_objects appends objects to g->link_objects which we want to include in the hash |
| 10515 | gen_c_objects(g); | 10516 | gen_c_objects(g); |
src/glibc.cpp+10| ... | @@ -16,6 +16,7 @@ static const ZigGLibCLib glibc_libs[] = { | ... | @@ -16,6 +16,7 @@ static const ZigGLibCLib glibc_libs[] = { |
| 16 | {"pthread", 0}, | 16 | {"pthread", 0}, |
| 17 | {"dl", 2}, | 17 | {"dl", 2}, |
| 18 | {"rt", 1}, | 18 | {"rt", 1}, |
| 19 | {"ld", 2}, | ||
| 19 | }; | 20 | }; |
| 20 | 21 | ||
| 21 | Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbose) { | 22 | Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbose) { |
| ... | @@ -330,6 +331,8 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con | ... | @@ -330,6 +331,8 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con |
| 330 | return err; | 331 | return err; |
| 331 | } | 332 | } |
| 332 | 333 | ||
| 334 | bool is_ld = (strcmp(lib->name, "ld") == 0); | ||
| 335 | |||
| 333 | CodeGen *child_gen = create_child_codegen(g, zig_file_path, OutTypeLib, nullptr, lib->name, progress_node); | 336 | CodeGen *child_gen = create_child_codegen(g, zig_file_path, OutTypeLib, nullptr, lib->name, progress_node); |
| 334 | codegen_set_lib_version(child_gen, lib->sover, 0, 0); | 337 | codegen_set_lib_version(child_gen, lib->sover, 0, 0); |
| 335 | child_gen->is_dynamic = true; | 338 | child_gen->is_dynamic = true; |
| ... | @@ -337,6 +340,13 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con | ... | @@ -337,6 +340,13 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con |
| 337 | child_gen->version_script_path = map_file_path; | 340 | child_gen->version_script_path = map_file_path; |
| 338 | child_gen->enable_cache = false; | 341 | child_gen->enable_cache = false; |
| 339 | child_gen->output_dir = dummy_dir; | 342 | child_gen->output_dir = dummy_dir; |
| 343 | if (is_ld) { | ||
| 344 | assert(g->zig_target->standard_dynamic_linker_path != nullptr); | ||
| 345 | Buf *ld_basename = buf_alloc(); | ||
| 346 | os_path_split(buf_create_from_str(g->zig_target->standard_dynamic_linker_path), | ||
| 347 | nullptr, ld_basename); | ||
| 348 | child_gen->override_soname = ld_basename; | ||
| 349 | } | ||
| 340 | codegen_build_and_link(child_gen); | 350 | codegen_build_and_link(child_gen); |
| 341 | } | 351 | } |
| 342 | 352 |
src/link.cpp+4-4| ... | @@ -1651,7 +1651,6 @@ static void construct_linker_job_elf(LinkJob *lj) { | ... | @@ -1651,7 +1651,6 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1651 | 1651 | ||
| 1652 | bool is_lib = g->out_type == OutTypeLib; | 1652 | bool is_lib = g->out_type == OutTypeLib; |
| 1653 | bool is_dyn_lib = g->is_dynamic && is_lib; | 1653 | bool is_dyn_lib = g->is_dynamic && is_lib; |
| 1654 | Buf *soname = nullptr; | ||
| 1655 | if (!g->have_dynamic_link) { | 1654 | if (!g->have_dynamic_link) { |
| 1656 | if (g->zig_target->arch == ZigLLVM_arm || g->zig_target->arch == ZigLLVM_armeb || | 1655 | if (g->zig_target->arch == ZigLLVM_arm || g->zig_target->arch == ZigLLVM_armeb || |
| 1657 | g->zig_target->arch == ZigLLVM_thumb || g->zig_target->arch == ZigLLVM_thumbeb) | 1656 | g->zig_target->arch == ZigLLVM_thumb || g->zig_target->arch == ZigLLVM_thumbeb) |
| ... | @@ -1662,15 +1661,13 @@ static void construct_linker_job_elf(LinkJob *lj) { | ... | @@ -1662,15 +1661,13 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1662 | } | 1661 | } |
| 1663 | } else if (is_dyn_lib) { | 1662 | } else if (is_dyn_lib) { |
| 1664 | lj->args.append("-shared"); | 1663 | lj->args.append("-shared"); |
| 1665 | |||
| 1666 | assert(buf_len(&g->bin_file_output_path) != 0); | ||
| 1667 | soname = buf_sprintf("lib%s.so.%" ZIG_PRI_usize, buf_ptr(g->root_out_name), g->version_major); | ||
| 1668 | } | 1664 | } |
| 1669 | 1665 | ||
| 1670 | if (target_requires_pie(g->zig_target) && g->out_type == OutTypeExe) { | 1666 | if (target_requires_pie(g->zig_target) && g->out_type == OutTypeExe) { |
| 1671 | lj->args.append("-pie"); | 1667 | lj->args.append("-pie"); |
| 1672 | } | 1668 | } |
| 1673 | 1669 | ||
| 1670 | assert(buf_len(&g->bin_file_output_path) != 0); | ||
| 1674 | lj->args.append("-o"); | 1671 | lj->args.append("-o"); |
| 1675 | lj->args.append(buf_ptr(&g->bin_file_output_path)); | 1672 | lj->args.append(buf_ptr(&g->bin_file_output_path)); |
| 1676 | 1673 | ||
| ... | @@ -1740,6 +1737,9 @@ static void construct_linker_job_elf(LinkJob *lj) { | ... | @@ -1740,6 +1737,9 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1740 | } | 1737 | } |
| 1741 | 1738 | ||
| 1742 | if (is_dyn_lib) { | 1739 | if (is_dyn_lib) { |
| 1740 | Buf *soname = (g->override_soname == nullptr) ? | ||
| 1741 | buf_sprintf("lib%s.so.%" ZIG_PRI_usize, buf_ptr(g->root_out_name), g->version_major) : | ||
| 1742 | g->override_soname; | ||
| 1743 | lj->args.append("-soname"); | 1743 | lj->args.append("-soname"); |
| 1744 | lj->args.append(buf_ptr(soname)); | 1744 | lj->args.append(buf_ptr(soname)); |
| 1745 | 1745 |
src/stage2.h+1| ... | @@ -291,6 +291,7 @@ struct ZigTarget { | ... | @@ -291,6 +291,7 @@ struct ZigTarget { |
| 291 | size_t cache_hash_len; | 291 | size_t cache_hash_len; |
| 292 | const char *os_builtin_str; | 292 | const char *os_builtin_str; |
| 293 | const char *dynamic_linker; | 293 | const char *dynamic_linker; |
| 294 | const char *standard_dynamic_linker_path; | ||
| 294 | }; | 295 | }; |
| 295 | 296 | ||
| 296 | // ABI warning | 297 | // ABI warning |