zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 4d48948b526337947ef59a83f7dbc81b70aa5723 (tree)
parent 694f424fc788f6c64908b3f6d076f4836df33b68
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed, 15 Dec 2021 17:52:27 -0700

glibc: pass -D__GLIBC_MINOR__=XX

instead of hard-coding it. This means that C code has accurate glibc
version information in the preprocessor.

Diffstat:
Mlib/libc/glibc/include/features.h | 2+-
Mlib/libc/include/generic-glibc/features.h | 5++---
Msrc/Compilation.zig | 8++++++++
3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/libc/glibc/include/features.h b/lib/libc/glibc/include/features.h @@ -477,7 +477,7 @@ /* Major and minor version number of the GNU C library package. Use these macros to test for features in specific releases. */ #define __GLIBC__ 2 -#define __GLIBC_MINOR__ 34 +/* Zig patch: we pass `-D__GLIBC_MINOR__=XX` depending on the target. */ #define __GLIBC_PREREQ(maj, min) \ ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min)) diff --git a/lib/libc/include/generic-glibc/features.h b/lib/libc/include/generic-glibc/features.h @@ -477,7 +477,7 @@ /* Major and minor version number of the GNU C library package. Use these macros to test for features in specific releases. */ #define __GLIBC__ 2 -#define __GLIBC_MINOR__ 34 +/* Zig patch: we pass `-D__GLIBC_MINOR__=XX` depending on the target. */ #define __GLIBC_PREREQ(maj, min) \ ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min)) @@ -512,4 +512,4 @@ #include <gnu/stubs.h> -#endif /* features.h */ -\ No newline at end of file +#endif /* features.h */ diff --git a/src/Compilation.zig b/src/Compilation.zig @@ -3397,6 +3397,14 @@ pub fn addCCArgs( try argv.append(libunwind_include_path); } + if (comp.bin_file.options.link_libc and target.isGnuLibC()) { + const target_version = target.os.version_range.linux.glibc; + const glibc_minor_define = try std.fmt.allocPrint(arena, "-D__GLIBC_MINOR__={d}", .{ + target_version.minor, + }); + try argv.append(glibc_minor_define); + } + const llvm_triple = try @import("codegen/llvm.zig").targetTriple(arena, target); try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });