authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-25 02:52:49-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-28 14:51:53-05:00
logd4f375c46be2e509ee9161b0577d8a25d6620b3e
treec79f706ad52702e62b615e94e702ff625b957575
parent4616af0ca459358ffa09ba27f9daa8527a38fd35
signaturelock-open Commit is signed but in an unrecognized format.

stage1: remove get_self_libc_path

and glibc_detect_native_version

4 files changed, 0 insertions(+), 66 deletions(-)

src/compiler.cpp-25
...@@ -4,31 +4,6 @@...@@ -4,31 +4,6 @@
44
5#include <stdio.h>5#include <stdio.h>
66
7Buf *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
32Error get_compiler_id(Buf **result) {7Error get_compiler_id(Buf **result) {
33 static Buf saved_compiler_id = BUF_INIT;8 static Buf saved_compiler_id = BUF_INIT;
349
src/compiler.hpp-1
...@@ -12,7 +12,6 @@...@@ -12,7 +12,6 @@
12#include "error.hpp"12#include "error.hpp"
1313
14Error get_compiler_id(Buf **result);14Error get_compiler_id(Buf **result);
15Buf *get_self_libc_path(void);
1615
17Buf *get_zig_lib_dir(void);16Buf *get_zig_lib_dir(void);
18Buf *get_zig_special_dir(Buf *zig_lib_dir);17Buf *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,43 +362,6 @@ bool eql_glibc_target(const ZigTarget *a, const ZigTarget *b) {
362 a->abi == b->abi;362 a->abi == b->abi;
363}363}
364364
365#ifdef ZIG_OS_LINUX
366#include <unistd.h>
367Error 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
397Error glibc_detect_native_version(ZigGLibCVersion *glibc_ver) {
398 return ErrorUnknownABI;
399}
400#endif
401
402size_t glibc_lib_count(void) {365size_t glibc_lib_count(void) {
403 return array_length(glibc_libs);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,9 +43,6 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
43Error glibc_build_dummies_and_maps(CodeGen *codegen, const ZigGLibCAbi *glibc_abi, const ZigTarget *target,43Error glibc_build_dummies_and_maps(CodeGen *codegen, const ZigGLibCAbi *glibc_abi, const ZigTarget *target,
44 Buf **out_dir, bool verbose, Stage2ProgressNode *progress_node);44 Buf **out_dir, bool verbose, Stage2ProgressNode *progress_node);
4545
46// returns ErrorUnknownABI when glibc is not the native libc
47Error glibc_detect_native_version(ZigGLibCVersion *glibc_ver);
48
49size_t glibc_lib_count(void);46size_t glibc_lib_count(void);
50const ZigGLibCLib *glibc_lib_enum(size_t index);47const ZigGLibCLib *glibc_lib_enum(size_t index);
51const ZigGLibCLib *glibc_lib_find(const char *name);48const ZigGLibCLib *glibc_lib_find(const char *name);