Skip to content

Commit

Permalink
glibc: pass -D__GLIBC_MINOR__=XX
Browse files Browse the repository at this point in the history
instead of hard-coding it. This means that C code has accurate glibc
version information in the preprocessor.
  • Loading branch information
andrewrk committed Dec 16, 2021
1 parent 694f424 commit 4d48948
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/libc/glibc/include/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions lib/libc/include/generic-glibc/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -512,4 +512,4 @@
#include <gnu/stubs.h>


#endif /* features.h */
#endif /* features.h */
8 changes: 8 additions & 0 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down

0 comments on commit 4d48948

Please sign in to comment.