| author | |
| committer | |
| log | d4f375c46be2e509ee9161b0577d8a25d6620b3e |
| tree | c79f706ad52702e62b615e94e702ff625b957575 |
| parent | 4616af0ca459358ffa09ba27f9daa8527a38fd35 |
| signature |
and glibc_detect_native_version4 files changed, 0 insertions(+), 66 deletions(-)
src/compiler.cpp-25| ... | ... | @@ -4,31 +4,6 @@ |
| 4 | 4 | |
| 5 | 5 | #include <stdio.h> |
| 6 | 6 | |
| 7 | Buf *get_self_libc_path(void) { | |
| 8 | static Buf saved_libc_path = BUF_INIT; | |
| 9 | static bool searched_for_libc = false; | |
| 10 | ||
| 11 | for (;;) { | |
| 12 | if (saved_libc_path.list.length != 0) { | |
| 13 | return &saved_libc_path; | |
| 14 | } | |
| 15 | if (searched_for_libc) | |
| 16 | return nullptr; | |
| 17 | ZigList<Buf *> lib_paths = {}; | |
| 18 | Error err; | |
| 19 | if ((err = os_self_exe_shared_libs(lib_paths))) | |
| 20 | return nullptr; | |
| 21 | for (size_t i = 0; i < lib_paths.length; i += 1) { | |
| 22 | Buf *lib_path = lib_paths.at(i); | |
| 23 | if (buf_ends_with_str(lib_path, "libc.so.6")) { | |
| 24 | buf_init_from_buf(&saved_libc_path, lib_path); | |
| 25 | return &saved_libc_path; | |
| 26 | } | |
| 27 | } | |
| 28 | searched_for_libc = true; | |
| 29 | } | |
| 30 | } | |
| 31 | ||
| 32 | 7 | Error get_compiler_id(Buf **result) { |
| 33 | 8 | static Buf saved_compiler_id = BUF_INIT; |
| 34 | 9 |
src/compiler.hpp-1| ... | ... | @@ -12,7 +12,6 @@ |
| 12 | 12 | #include "error.hpp" |
| 13 | 13 | |
| 14 | 14 | Error get_compiler_id(Buf **result); |
| 15 | Buf *get_self_libc_path(void); | |
| 16 | 15 | |
| 17 | 16 | Buf *get_zig_lib_dir(void); |
| 18 | 17 | Buf *get_zig_special_dir(Buf *zig_lib_dir); |
src/glibc.cpp-37| ... | ... | @@ -362,43 +362,6 @@ bool eql_glibc_target(const ZigTarget *a, const ZigTarget *b) { |
| 362 | 362 | a->abi == b->abi; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | #ifdef ZIG_OS_LINUX | |
| 366 | #include <unistd.h> | |
| 367 | Error glibc_detect_native_version(ZigGLibCVersion *glibc_ver) { | |
| 368 | Buf *self_libc_path = get_self_libc_path(); | |
| 369 | if (self_libc_path == nullptr) { | |
| 370 | // TODO There is still more we could do to detect the native glibc version. For example, | |
| 371 | // we could look at the ELF file of `/usr/bin/env`, find `libc.so.6`, and then `readlink` | |
| 372 | // to find out the glibc version. This is relevant for the static zig builds distributed | |
| 373 | // on the download page, since the above detection based on zig's own dynamic linking | |
| 374 | // will not work. | |
| 375 | ||
| 376 | return ErrorUnknownABI; | |
| 377 | } | |
| 378 | Buf *link_name = buf_alloc(); | |
| 379 | buf_resize(link_name, 4096); | |
| 380 | ssize_t amt = readlink(buf_ptr(self_libc_path), buf_ptr(link_name), buf_len(link_name)); | |
| 381 | if (amt == -1) { | |
| 382 | return ErrorUnknownABI; | |
| 383 | } | |
| 384 | buf_resize(link_name, amt); | |
| 385 | if (!buf_starts_with_str(link_name, "libc-") || !buf_ends_with_str(link_name, ".so")) { | |
| 386 | return ErrorUnknownABI; | |
| 387 | } | |
| 388 | // example: "libc-2.3.4.so" | |
| 389 | // example: "libc-2.27.so" | |
| 390 | buf_resize(link_name, buf_len(link_name) - 3); // chop off ".so" | |
| 391 | glibc_ver->major = 2; | |
| 392 | glibc_ver->minor = 0; | |
| 393 | glibc_ver->patch = 0; | |
| 394 | return target_parse_glibc_version(glibc_ver, buf_ptr(link_name) + 5); | |
| 395 | } | |
| 396 | #else | |
| 397 | Error glibc_detect_native_version(ZigGLibCVersion *glibc_ver) { | |
| 398 | return ErrorUnknownABI; | |
| 399 | } | |
| 400 | #endif | |
| 401 | ||
| 402 | 365 | size_t glibc_lib_count(void) { |
| 403 | 366 | return array_length(glibc_libs); |
| 404 | 367 | } |
src/glibc.hpp-3| ... | ... | @@ -43,9 +43,6 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo |
| 43 | 43 | Error glibc_build_dummies_and_maps(CodeGen *codegen, const ZigGLibCAbi *glibc_abi, const ZigTarget *target, |
| 44 | 44 | Buf **out_dir, bool verbose, Stage2ProgressNode *progress_node); |
| 45 | 45 | |
| 46 | // returns ErrorUnknownABI when glibc is not the native libc | |
| 47 | Error glibc_detect_native_version(ZigGLibCVersion *glibc_ver); | |
| 48 | ||
| 49 | 46 | size_t glibc_lib_count(void); |
| 50 | 47 | const ZigGLibCLib *glibc_lib_enum(size_t index); |
| 51 | 48 | const ZigGLibCLib *glibc_lib_find(const char *name); |