diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-03-07 16:55:31 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-03-07 16:55:31 -0500 |
| commit | 1e634a384ccc0ae57e0343369f7adb0b1b4b9875 (patch) | |
| tree | e7f4d834e39028b141f6c02e16f6eafb20d8320d /src/compiler.cpp | |
| parent | 5469e3e3c1ae060ee04f554499c852603eef3a5f (diff) | |
| parent | 2bb6825baa906936ff28b82029a4644ef0f73755 (diff) | |
| download | zig-1e634a384ccc0ae57e0343369f7adb0b1b4b9875.tar.gz zig-1e634a384ccc0ae57e0343369f7adb0b1b4b9875.zip | |
Merge branch 'glibc'
See #514
Diffstat (limited to 'src/compiler.cpp')
| -rw-r--r-- | src/compiler.cpp | 36 |
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"); |
