diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-07-08 13:51:48 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-08 13:51:48 -0400 |
| commit | 4953e84902df3467b6d7491532e48bf33b5e56b9 (patch) | |
| tree | aa7d7fcb91a0e6ca8725d3fbdd586e168f62a27f /src/target.cpp | |
| parent | d39dcd6d9db2faf18287b2ff734ffda0d4080e5a (diff) | |
| parent | 201033d83b80d65380aaade37b76eafa17258f16 (diff) | |
| download | zig-4953e84902df3467b6d7491532e48bf33b5e56b9.tar.gz zig-4953e84902df3467b6d7491532e48bf33b5e56b9.zip | |
Merge pull request #2847 from ziglang/glibc-abi-versioning
support glibc version as part of the target
Diffstat (limited to 'src/target.cpp')
| -rw-r--r-- | src/target.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/target.cpp b/src/target.cpp index f646b33e22..5cbf8c4de1 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -10,6 +10,8 @@ #include "target.hpp" #include "util.hpp" #include "os.hpp" +#include "compiler.hpp" +#include "glibc.hpp" #include <stdio.h> @@ -466,7 +468,33 @@ const char *target_abi_name(ZigLLVM_EnvironmentType abi) { return ZigLLVMGetEnvironmentTypeName(abi); } +Error target_parse_glibc_version(ZigGLibCVersion *glibc_ver, const char *text) { + glibc_ver->major = 2; + glibc_ver->minor = 0; + glibc_ver->patch = 0; + SplitIterator it = memSplit(str(text), str("GLIBC_.")); + { + Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it); + if (!opt_component.is_some) return ErrorUnknownABI; + glibc_ver->major = strtoul(buf_ptr(buf_create_from_slice(opt_component.value)), nullptr, 10); + } + { + Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it); + if (!opt_component.is_some) return ErrorNone; + glibc_ver->minor = strtoul(buf_ptr(buf_create_from_slice(opt_component.value)), nullptr, 10); + } + { + Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it); + if (!opt_component.is_some) return ErrorNone; + glibc_ver->patch = strtoul(buf_ptr(buf_create_from_slice(opt_component.value)), nullptr, 10); + } + return ErrorNone; +} + void get_native_target(ZigTarget *target) { + // first zero initialize + *target = {}; + ZigLLVM_OSType os_type; ZigLLVM_ObjectFormatType oformat; // ignored; based on arch/os ZigLLVMGetNativeTarget( @@ -481,6 +509,16 @@ void get_native_target(ZigTarget *target) { if (target->abi == ZigLLVM_UnknownEnvironment) { target->abi = target_default_abi(target->arch, target->os); } + if (target_is_glibc(target)) { + target->glibc_version = allocate<ZigGLibCVersion>(1); + *target->glibc_version = {2, 17, 0}; +#ifdef ZIG_OS_LINUX + Error err; + if ((err = glibc_detect_native_version(target->glibc_version))) { + // Fall back to the default version. + } +#endif + } } Error target_parse_archsub(ZigLLVM_ArchType *out_arch, ZigLLVM_SubArchType *out_sub, @@ -667,6 +705,10 @@ Error target_parse_abi(ZigLLVM_EnvironmentType *out_abi, const char *abi_ptr, si Error target_parse_triple(ZigTarget *target, const char *triple) { Error err; + + // first initialize all to zero + *target = {}; + SplitIterator it = memSplit(str(triple), str("-")); Optional<Slice<uint8_t>> opt_archsub = SplitIterator_next(&it); @@ -696,9 +738,6 @@ Error target_parse_triple(ZigTarget *target, const char *triple) { } else { target->abi = target_default_abi(target->arch, target->os); } - - target->vendor = ZigLLVM_UnknownVendor; - target->is_native = false; return ErrorNone; } |
