authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-09-12 15:56:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-09-12 15:56:31-07:00
logf79824f946995a050c261ee96a08e31ccf00a112
tree354cab5f5640827e5fc85e15796ff250769a47c1
parent6e3bbba9518b2efd789af94c89ae7712e011ed3b

libcxx: define _LIBCPP_ABI_VERSION and _LIBCPP_ABI_NAMESPACE

The changes from https://reviews.llvm.org/D119173 mean that __config no longer defaults the libc++ ABI to 1, relying on external configuration. This means Zig must provide the external configuration. This fixes static libraries built with zig with -lc++ to have the standard __1 namespace prefix, which had previously regressed in the llvm15 branch.

2 files changed, 38 insertions(+), 0 deletions(-)

src/Compilation.zig+11
......@@ -154,6 +154,8 @@ owned_link_dir: ?std.fs.Dir,
154154/// Don't use this for anything other than stage1 compatibility.
155155color: Color = .auto,
156156
157libcxx_abi_version: libcxx.AbiVersion = libcxx.AbiVersion.default,
158
157159/// This mutex guards all `Compilation` mutable state.
158160mutex: std.Thread.Mutex = .{},
159161
......@@ -950,6 +952,7 @@ pub const InitOptions = struct {
950952 headerpad_max_install_names: bool = false,
951953 /// (Darwin) remove dylibs that are unreachable by the entry point or exported symbols
952954 dead_strip_dylibs: bool = false,
955 libcxx_abi_version: libcxx.AbiVersion = libcxx.AbiVersion.default,
953956};
954957
955958fn addPackageTableToCacheHash(
......@@ -1843,6 +1846,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
18431846 .test_evented_io = options.test_evented_io,
18441847 .debug_compiler_runtime_libs = options.debug_compiler_runtime_libs,
18451848 .debug_compile_errors = options.debug_compile_errors,
1849 .libcxx_abi_version = options.libcxx_abi_version,
18461850 };
18471851 break :comp comp;
18481852 };
......@@ -4026,6 +4030,13 @@ pub fn addCCArgs(
40264030 if (comp.bin_file.options.single_threaded) {
40274031 try argv.append("-D_LIBCPP_HAS_NO_THREADS");
40284032 }
4033
4034 try argv.append(try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_VERSION={d}", .{
4035 @enumToInt(comp.libcxx_abi_version),
4036 }));
4037 try argv.append(try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_NAMESPACE=__{d}", .{
4038 @enumToInt(comp.libcxx_abi_version),
4039 }));
40294040 }
40304041
40314042 if (comp.bin_file.options.link_libunwind) {
src/libcxx.zig+27
......@@ -7,6 +7,13 @@ const Compilation = @import("Compilation.zig");
77const build_options = @import("build_options");
88const trace = @import("tracy.zig").trace;
99
10pub const AbiVersion = enum(u2) {
11 @"1" = 1,
12 @"2" = 2,
13
14 pub const default: AbiVersion = .@"1";
15};
16
1017const libcxxabi_files = [_][]const u8{
1118 "src/abort_message.cpp",
1219 "src/cxa_aux_runtime.cpp",
......@@ -120,6 +127,12 @@ pub fn buildLibCXX(comp: *Compilation) !void {
120127 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
121128 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
122129 const cxx_src_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "src" });
130 const abi_version_arg = try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_VERSION={d}", .{
131 @enumToInt(comp.libcxx_abi_version),
132 });
133 const abi_namespace_arg = try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_NAMESPACE=__{d}", .{
134 @enumToInt(comp.libcxx_abi_version),
135 });
123136 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxx_files.len);
124137
125138 for (libcxx_files) |cxx_src| {
......@@ -152,6 +165,10 @@ pub fn buildLibCXX(comp: *Compilation) !void {
152165 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
153166 try cflags.append("-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS");
154167 try cflags.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS");
168
169 try cflags.append(abi_version_arg);
170 try cflags.append(abi_namespace_arg);
171
155172 try cflags.append("-fvisibility=hidden");
156173 try cflags.append("-fvisibility-inlines-hidden");
157174
......@@ -277,6 +294,12 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
277294 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
278295 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
279296 const cxx_src_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "src" });
297 const abi_version_arg = try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_VERSION={d}", .{
298 @enumToInt(comp.libcxx_abi_version),
299 });
300 const abi_namespace_arg = try std.fmt.allocPrint(arena, "-D_LIBCPP_ABI_NAMESPACE=__{d}", .{
301 @enumToInt(comp.libcxx_abi_version),
302 });
280303 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxxabi_files.len);
281304
282305 for (libcxxabi_files) |cxxabi_src| {
......@@ -306,6 +329,10 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
306329 try cflags.append("-D_LIBCXXABI_BUILDING_LIBRARY");
307330 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
308331 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
332
333 try cflags.append(abi_version_arg);
334 try cflags.append(abi_namespace_arg);
335
309336 try cflags.append("-fvisibility=hidden");
310337 try cflags.append("-fvisibility-inlines-hidden");
311338