self-host dynamic linker detection

This commit is contained in:
Andrew Kelley
2020-02-17 15:23:59 -05:00
parent c784c52819
commit 2f9c5c0644
17 changed files with 430 additions and 532 deletions

View File

@@ -4,20 +4,6 @@
#include <stdio.h>
static Buf saved_dynamic_linker_path = BUF_INIT;
static bool searched_for_dyn_linker = false;
static void detect_dynamic_linker(Buf *lib_path) {
#if defined(ZIG_OS_LINUX)
for (size_t i = 0; possible_ld_names[i] != NULL; i += 1) {
if (buf_ends_with_str(lib_path, possible_ld_names[i])) {
buf_init_from_buf(&saved_dynamic_linker_path, lib_path);
break;
}
}
#endif
}
Buf *get_self_libc_path(void) {
static Buf saved_libc_path = BUF_INIT;
static bool searched_for_libc = false;
@@ -43,25 +29,6 @@ Buf *get_self_libc_path(void) {
}
}
Buf *get_self_dynamic_linker_path(void) {
for (;;) {
if (saved_dynamic_linker_path.list.length != 0) {
return &saved_dynamic_linker_path;
}
if (searched_for_dyn_linker)
return nullptr;
ZigList<Buf *> lib_paths = {};
Error err;
if ((err = os_self_exe_shared_libs(lib_paths)))
return nullptr;
for (size_t i = 0; i < lib_paths.length; i += 1) {
Buf *lib_path = lib_paths.at(i);
detect_dynamic_linker(lib_path);
}
searched_for_dyn_linker = true;
}
}
Error get_compiler_id(Buf **result) {
static Buf saved_compiler_id = BUF_INIT;
@@ -98,7 +65,6 @@ Error get_compiler_id(Buf **result) {
return err;
for (size_t i = 0; i < lib_paths.length; i += 1) {
Buf *lib_path = lib_paths.at(i);
detect_dynamic_linker(lib_path);
if ((err = cache_add_file(ch, lib_path)))
return err;
}