| ... | @@ -164,32 +164,45 @@ static void add_rpath(LinkJob *lj, Buf *rpath) { | ... | @@ -164,32 +164,45 @@ static void add_rpath(LinkJob *lj, Buf *rpath) { |
| 164 | lj->rpath_table.put(rpath, true); | 164 | lj->rpath_table.put(rpath, true); |
| 165 | } | 165 | } |
| 166 | | 166 | |
| | 167 | static Buf *try_dynamic_linker_path(const char *ld_name) { |
| | 168 | const char *cc_exe = getenv("CC"); |
| | 169 | cc_exe = (cc_exe == nullptr) ? "cc" : cc_exe; |
| | 170 | ZigList<const char *> args = {}; |
| | 171 | args.append(buf_ptr(buf_sprintf("-print-file-name=%s", ld_name))); |
| | 172 | Termination term; |
| | 173 | Buf *out_stderr = buf_alloc(); |
| | 174 | Buf *out_stdout = buf_alloc(); |
| | 175 | int err; |
| | 176 | if ((err = os_exec_process(cc_exe, args, &term, out_stderr, out_stdout))) { |
| | 177 | return nullptr; |
| | 178 | } |
| | 179 | if (term.how != TerminationIdClean || term.code != 0) { |
| | 180 | return nullptr; |
| | 181 | } |
| | 182 | if (buf_ends_with_str(out_stdout, "\n")) { |
| | 183 | buf_resize(out_stdout, buf_len(out_stdout) - 1); |
| | 184 | } |
| | 185 | if (buf_len(out_stdout) == 0 || buf_eql_str(out_stdout, ld_name)) { |
| | 186 | return nullptr; |
| | 187 | } |
| | 188 | return out_stdout; |
| | 189 | } |
| | 190 | |
| 167 | static Buf *get_dynamic_linker_path(CodeGen *g) { | 191 | static Buf *get_dynamic_linker_path(CodeGen *g) { |
| 168 | if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) { | 192 | if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) { |
| 169 | const char *cc_exe = getenv("CC"); | 193 | static const char *ld_names[] = { |
| 170 | cc_exe = (cc_exe == nullptr) ? "cc" : cc_exe; | 194 | "ld-linux-x86-64.so.2", |
| 171 | ZigList<const char *> args = {}; | 195 | "ld-musl-x86_64.so.1", |
| 172 | args.append("-print-file-name=ld-linux-x86-64.so.2"); | 196 | }; |
| 173 | Termination term; | 197 | for (size_t i = 0; i < array_length(ld_names); i += 1) { |
| 174 | Buf *out_stderr = buf_alloc(); | 198 | const char *ld_name = ld_names[i]; |
| 175 | Buf *out_stdout = buf_alloc(); | 199 | Buf *result = try_dynamic_linker_path(ld_name); |
| 176 | int err; | 200 | if (result != nullptr) { |
| 177 | if ((err = os_exec_process(cc_exe, args, &term, out_stderr, out_stdout))) { | 201 | return result; |
| 178 | return target_dynamic_linker(&g->zig_target); | 202 | } |
| 179 | } | | |
| 180 | if (term.how != TerminationIdClean || term.code != 0) { | | |
| 181 | return target_dynamic_linker(&g->zig_target); | | |
| 182 | } | | |
| 183 | if (buf_ends_with_str(out_stdout, "\n")) { | | |
| 184 | buf_resize(out_stdout, buf_len(out_stdout) - 1); | | |
| 185 | } | | |
| 186 | if (buf_len(out_stdout) == 0 || buf_eql_str(out_stdout, "ld-linux-x86-64.so.2")) { | | |
| 187 | return target_dynamic_linker(&g->zig_target); | | |
| 188 | } | 203 | } |
| 189 | return out_stdout; | | |
| 190 | } else { | | |
| 191 | return target_dynamic_linker(&g->zig_target); | | |
| 192 | } | 204 | } |
| | 205 | return target_dynamic_linker(&g->zig_target); |
| 193 | } | 206 | } |
| 194 | | 207 | |
| 195 | static void construct_linker_job_elf(LinkJob *lj) { | 208 | static void construct_linker_job_elf(LinkJob *lj) { |