From d4f375c46be2e509ee9161b0577d8a25d6620b3e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 25 Feb 2020 02:52:49 -0500 Subject: [PATCH] stage1: remove get_self_libc_path and glibc_detect_native_version --- src/compiler.cpp | 25 ------------------------- src/compiler.hpp | 1 - src/glibc.cpp | 37 ------------------------------------- src/glibc.hpp | 3 --- 4 files changed, 66 deletions(-) diff --git a/src/compiler.cpp b/src/compiler.cpp index 31bac4ee24..cddecc2025 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -4,31 +4,6 @@ #include -Buf *get_self_libc_path(void) { - static Buf saved_libc_path = BUF_INIT; - static bool searched_for_libc = false; - - for (;;) { - if (saved_libc_path.list.length != 0) { - return &saved_libc_path; - } - if (searched_for_libc) - return nullptr; - ZigList 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); - if (buf_ends_with_str(lib_path, "libc.so.6")) { - buf_init_from_buf(&saved_libc_path, lib_path); - return &saved_libc_path; - } - } - searched_for_libc = true; - } -} - Error get_compiler_id(Buf **result) { static Buf saved_compiler_id = BUF_INIT; diff --git a/src/compiler.hpp b/src/compiler.hpp index 4a1699b782..47841af5dc 100644 --- a/src/compiler.hpp +++ b/src/compiler.hpp @@ -12,7 +12,6 @@ #include "error.hpp" Error get_compiler_id(Buf **result); -Buf *get_self_libc_path(void); Buf *get_zig_lib_dir(void); Buf *get_zig_special_dir(Buf *zig_lib_dir); diff --git a/src/glibc.cpp b/src/glibc.cpp index 849aac6c77..91e2f9dfc1 100644 --- a/src/glibc.cpp +++ b/src/glibc.cpp @@ -362,43 +362,6 @@ bool eql_glibc_target(const ZigTarget *a, const ZigTarget *b) { a->abi == b->abi; } -#ifdef ZIG_OS_LINUX -#include -Error glibc_detect_native_version(ZigGLibCVersion *glibc_ver) { - Buf *self_libc_path = get_self_libc_path(); - if (self_libc_path == nullptr) { - // TODO There is still more we could do to detect the native glibc version. For example, - // we could look at the ELF file of `/usr/bin/env`, find `libc.so.6`, and then `readlink` - // to find out the glibc version. This is relevant for the static zig builds distributed - // on the download page, since the above detection based on zig's own dynamic linking - // will not work. - - return ErrorUnknownABI; - } - Buf *link_name = buf_alloc(); - buf_resize(link_name, 4096); - ssize_t amt = readlink(buf_ptr(self_libc_path), buf_ptr(link_name), buf_len(link_name)); - if (amt == -1) { - return ErrorUnknownABI; - } - buf_resize(link_name, amt); - if (!buf_starts_with_str(link_name, "libc-") || !buf_ends_with_str(link_name, ".so")) { - return ErrorUnknownABI; - } - // example: "libc-2.3.4.so" - // example: "libc-2.27.so" - buf_resize(link_name, buf_len(link_name) - 3); // chop off ".so" - glibc_ver->major = 2; - glibc_ver->minor = 0; - glibc_ver->patch = 0; - return target_parse_glibc_version(glibc_ver, buf_ptr(link_name) + 5); -} -#else -Error glibc_detect_native_version(ZigGLibCVersion *glibc_ver) { - return ErrorUnknownABI; -} -#endif - size_t glibc_lib_count(void) { return array_length(glibc_libs); } diff --git a/src/glibc.hpp b/src/glibc.hpp index 42c2099371..8e4c7888ad 100644 --- a/src/glibc.hpp +++ b/src/glibc.hpp @@ -43,9 +43,6 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo Error glibc_build_dummies_and_maps(CodeGen *codegen, const ZigGLibCAbi *glibc_abi, const ZigTarget *target, Buf **out_dir, bool verbose, Stage2ProgressNode *progress_node); -// returns ErrorUnknownABI when glibc is not the native libc -Error glibc_detect_native_version(ZigGLibCVersion *glibc_ver); - size_t glibc_lib_count(void); const ZigGLibCLib *glibc_lib_enum(size_t index); const ZigGLibCLib *glibc_lib_find(const char *name);