aboutsummaryrefslogtreecommitdiff
path: root/src/compiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler.cpp')
-rw-r--r--src/compiler.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/compiler.cpp b/src/compiler.cpp
index 8c2f9cdf60..fa153aa2d8 100644
--- a/src/compiler.cpp
+++ b/src/compiler.cpp
@@ -1,4 +1,5 @@
#include "cache_hash.hpp"
+#include "os.hpp"
#include <stdio.h>
@@ -8,8 +9,10 @@ static Buf saved_stage1_path = BUF_INIT;
static Buf saved_lib_dir = BUF_INIT;
static Buf saved_special_dir = BUF_INIT;
static Buf saved_std_dir = BUF_INIT;
+static Buf saved_dynamic_linker_path = BUF_INIT;
+static bool searched_for_dyn_linker = false;
-Buf *get_stage1_cache_path() {
+Buf *get_stage1_cache_path(void) {
if (saved_stage1_path.list.length != 0) {
return &saved_stage1_path;
}
@@ -22,6 +25,35 @@ Buf *get_stage1_cache_path() {
return &saved_stage1_path;
}
+static void detect_dynamic_linker(Buf *lib_path) {
+#if defined(ZIG_OS_LINUX) && defined(ZIG_ARCH_X86_64)
+ if (buf_ends_with_str(lib_path, "ld-linux-x86-64.so.2")) {
+ buf_init_from_buf(&saved_dynamic_linker_path, lib_path);
+ } else if (buf_ends_with_str(lib_path, "ld-musl-x86-64.so.1")) {
+ buf_init_from_buf(&saved_dynamic_linker_path, lib_path);
+ }
+#endif
+}
+
+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) {
if (saved_compiler_id.list.length != 0) {
*result = &saved_compiler_id;
@@ -55,6 +87,7 @@ 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;
}
@@ -67,7 +100,6 @@ Error get_compiler_id(Buf **result) {
return ErrorNone;
}
-
static bool test_zig_install_prefix(Buf *test_path, Buf *out_zig_lib_dir) {
Buf lib_buf = BUF_INIT;
buf_init_from_str(&lib_buf, "lib");