Skip to content

Commit b80cad2

Browse files
Emil Tywoniakandrewrk
Emil Tywoniak
authored andcommitted
libcxx: fix C++ builds with glibc <2.16 without aligned_alloc
1 parent 9b714e0 commit b80cad2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libcxx.zig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
233233
try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
234234
}
235235

236+
if (target.isGnuLibC()) {
237+
// glibc 2.16 introduced aligned_alloc
238+
if (target.os.version_range.linux.glibc.order(.{ .major = 2, .minor = 16, .patch = 0 }) == .lt) {
239+
try cflags.append("-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION");
240+
}
241+
}
242+
236243
if (target.os.tag == .wasi) {
237244
// WASI doesn't support exceptions yet.
238245
try cflags.append("-fno-exceptions");
@@ -433,6 +440,13 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
433440
try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
434441
}
435442

443+
if (target.isGnuLibC()) {
444+
// glibc 2.16 introduced aligned_alloc
445+
if (target.os.version_range.linux.glibc.order(.{ .major = 2, .minor = 16, .patch = 0 }) == .lt) {
446+
try cflags.append("-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION");
447+
}
448+
}
449+
436450
if (target_util.supports_fpic(target)) {
437451
try cflags.append("-fPIC");
438452
}

0 commit comments

Comments
 (0)