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,...@@ -154,6 +154,8 @@ owned_link_dir: ?std.fs.Dir,
154/// Don't use this for anything other than stage1 compatibility.154/// Don't use this for anything other than stage1 compatibility.
155color: Color = .auto,155color: Color = .auto,
156156
157libcxx_abi_version: libcxx.AbiVersion = libcxx.AbiVersion.default,
158
157/// This mutex guards all `Compilation` mutable state.159/// This mutex guards all `Compilation` mutable state.
158mutex: std.Thread.Mutex = .{},160mutex: std.Thread.Mutex = .{},
159161
...@@ -950,6 +952,7 @@ pub const InitOptions = struct {...@@ -950,6 +952,7 @@ pub const InitOptions = struct {
950 headerpad_max_install_names: bool = false,952 headerpad_max_install_names: bool = false,
951 /// (Darwin) remove dylibs that are unreachable by the entry point or exported symbols953 /// (Darwin) remove dylibs that are unreachable by the entry point or exported symbols
952 dead_strip_dylibs: bool = false,954 dead_strip_dylibs: bool = false,
955 libcxx_abi_version: libcxx.AbiVersion = libcxx.AbiVersion.default,
953};956};
954957
955fn addPackageTableToCacheHash(958fn addPackageTableToCacheHash(
...@@ -1843,6 +1846,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1843,6 +1846,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1843 .test_evented_io = options.test_evented_io,1846 .test_evented_io = options.test_evented_io,
1844 .debug_compiler_runtime_libs = options.debug_compiler_runtime_libs,1847 .debug_compiler_runtime_libs = options.debug_compiler_runtime_libs,
1845 .debug_compile_errors = options.debug_compile_errors,1848 .debug_compile_errors = options.debug_compile_errors,
1849 .libcxx_abi_version = options.libcxx_abi_version,
1846 };1850 };
1847 break :comp comp;1851 break :comp comp;
1848 };1852 };
...@@ -4026,6 +4030,13 @@ pub fn addCCArgs(...@@ -4026,6 +4030,13 @@ pub fn addCCArgs(
4026 if (comp.bin_file.options.single_threaded) {4030 if (comp.bin_file.options.single_threaded) {
4027 try argv.append("-D_LIBCPP_HAS_NO_THREADS");4031 try argv.append("-D_LIBCPP_HAS_NO_THREADS");
4028 }4032 }
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 }));
4029 }4040 }
40304041
4031 if (comp.bin_file.options.link_libunwind) {4042 if (comp.bin_file.options.link_libunwind) {
src/libcxx.zig+27
...@@ -7,6 +7,13 @@ const Compilation = @import("Compilation.zig");...@@ -7,6 +7,13 @@ const Compilation = @import("Compilation.zig");
7const build_options = @import("build_options");7const build_options = @import("build_options");
8const trace = @import("tracy.zig").trace;8const 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
10const libcxxabi_files = [_][]const u8{17const libcxxabi_files = [_][]const u8{
11 "src/abort_message.cpp",18 "src/abort_message.cpp",
12 "src/cxa_aux_runtime.cpp",19 "src/cxa_aux_runtime.cpp",
...@@ -120,6 +127,12 @@ pub fn buildLibCXX(comp: *Compilation) !void {...@@ -120,6 +127,12 @@ pub fn buildLibCXX(comp: *Compilation) !void {
120 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });127 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
121 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });128 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
122 const cxx_src_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "src" });129 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 });
123 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxx_files.len);136 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxx_files.len);
124137
125 for (libcxx_files) |cxx_src| {138 for (libcxx_files) |cxx_src| {
...@@ -152,6 +165,10 @@ pub fn buildLibCXX(comp: *Compilation) !void {...@@ -152,6 +165,10 @@ pub fn buildLibCXX(comp: *Compilation) !void {
152 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");165 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
153 try cflags.append("-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS");166 try cflags.append("-D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS");
154 try cflags.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS");167 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
155 try cflags.append("-fvisibility=hidden");172 try cflags.append("-fvisibility=hidden");
156 try cflags.append("-fvisibility-inlines-hidden");173 try cflags.append("-fvisibility-inlines-hidden");
157174
...@@ -277,6 +294,12 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {...@@ -277,6 +294,12 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
277 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });294 const cxxabi_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxxabi", "include" });
278 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });295 const cxx_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "include" });
279 const cxx_src_include_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libcxx", "src" });296 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 });
280 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxxabi_files.len);303 var c_source_files = try std.ArrayList(Compilation.CSourceFile).initCapacity(arena, libcxxabi_files.len);
281304
282 for (libcxxabi_files) |cxxabi_src| {305 for (libcxxabi_files) |cxxabi_src| {
...@@ -306,6 +329,10 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {...@@ -306,6 +329,10 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
306 try cflags.append("-D_LIBCXXABI_BUILDING_LIBRARY");329 try cflags.append("-D_LIBCXXABI_BUILDING_LIBRARY");
307 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");330 try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
308 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");331 try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
332
333 try cflags.append(abi_version_arg);
334 try cflags.append(abi_namespace_arg);
335
309 try cflags.append("-fvisibility=hidden");336 try cflags.append("-fvisibility=hidden");
310 try cflags.append("-fvisibility-inlines-hidden");337 try cflags.append("-fvisibility-inlines-hidden");
311338