authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-15 17:52:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-15 17:52:27-07:00
log4d48948b526337947ef59a83f7dbc81b70aa5723
tree9c5701f84d9ab7e9feee64443c143941bd46f9c0
parent694f424fc788f6c64908b3f6d076f4836df33b68

glibc: pass -D__GLIBC_MINOR__=XX

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

3 files changed, 11 insertions(+), 3 deletions(-)

lib/libc/glibc/include/features.h+1-1
...@@ -477,7 +477,7 @@...@@ -477,7 +477,7 @@
477/* Major and minor version number of the GNU C library package. Use477/* Major and minor version number of the GNU C library package. Use
478 these macros to test for features in specific releases. */478 these macros to test for features in specific releases. */
479#define __GLIBC__ 2479#define __GLIBC__ 2
480#define __GLIBC_MINOR__ 34480/* Zig patch: we pass `-D__GLIBC_MINOR__=XX` depending on the target. */
481481
482#define __GLIBC_PREREQ(maj, min) \482#define __GLIBC_PREREQ(maj, min) \
483 ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))483 ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))
lib/libc/include/generic-glibc/features.h+2-2
...@@ -477,7 +477,7 @@...@@ -477,7 +477,7 @@
477/* Major and minor version number of the GNU C library package. Use477/* Major and minor version number of the GNU C library package. Use
478 these macros to test for features in specific releases. */478 these macros to test for features in specific releases. */
479#define __GLIBC__ 2479#define __GLIBC__ 2
480#define __GLIBC_MINOR__ 34480/* Zig patch: we pass `-D__GLIBC_MINOR__=XX` depending on the target. */
481481
482#define __GLIBC_PREREQ(maj, min) \482#define __GLIBC_PREREQ(maj, min) \
483 ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))483 ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))
...@@ -512,4 +512,4 @@...@@ -512,4 +512,4 @@
512#include <gnu/stubs.h>512#include <gnu/stubs.h>
513513
514514
515#endif /* features.h */
\ No newline at end of file
515#endif /* features.h */
src/Compilation.zig+8
...@@ -3397,6 +3397,14 @@ pub fn addCCArgs(...@@ -3397,6 +3397,14 @@ pub fn addCCArgs(
3397 try argv.append(libunwind_include_path);3397 try argv.append(libunwind_include_path);
3398 }3398 }
33993399
3400 if (comp.bin_file.options.link_libc and target.isGnuLibC()) {
3401 const target_version = target.os.version_range.linux.glibc;
3402 const glibc_minor_define = try std.fmt.allocPrint(arena, "-D__GLIBC_MINOR__={d}", .{
3403 target_version.minor,
3404 });
3405 try argv.append(glibc_minor_define);
3406 }
3407
3400 const llvm_triple = try @import("codegen/llvm.zig").targetTriple(arena, target);3408 const llvm_triple = try @import("codegen/llvm.zig").targetTriple(arena, target);
3401 try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });3409 try argv.appendSlice(&[_][]const u8{ "-target", llvm_triple });
34023410