Skip to content

Commit 8c5d429

Browse files
authored
Merge pull request #8876 from xxxbxxx/cxx-lto
build libc++ with lto and function-sections
2 parents 8275c77 + a6e65f3 commit 8c5d429

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/libcxx.zig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ pub fn buildLibCXX(comp: *Compilation) !void {
129129
try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
130130
try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
131131
try cflags.append("-D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS");
132+
try cflags.append("-fvisibility=hidden");
133+
try cflags.append("-fvisibility-inlines-hidden");
132134

133135
if (target.abi.isMusl()) {
134136
try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
@@ -144,7 +146,6 @@ pub fn buildLibCXX(comp: *Compilation) !void {
144146
try cflags.append("-fPIC");
145147
}
146148
try cflags.append("-nostdinc++");
147-
try cflags.append("-fvisibility-inlines-hidden");
148149
try cflags.append("-std=c++14");
149150
try cflags.append("-Wno-user-defined-literals");
150151

@@ -174,6 +175,8 @@ pub fn buildLibCXX(comp: *Compilation) !void {
174175
.want_tsan = comp.bin_file.options.tsan,
175176
.want_pic = comp.bin_file.options.pic,
176177
.want_pie = comp.bin_file.options.pie,
178+
.want_lto = comp.bin_file.options.lto,
179+
.function_sections = comp.bin_file.options.function_sections,
177180
.emit_h = null,
178181
.strip = comp.compilerRtStrip(),
179182
.is_native_os = comp.bin_file.options.is_native_os,
@@ -247,6 +250,8 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
247250
try cflags.append("-D_LIBCXXABI_BUILDING_LIBRARY");
248251
try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
249252
try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
253+
try cflags.append("-fvisibility=hidden");
254+
try cflags.append("-fvisibility-inlines-hidden");
250255

251256
if (target.abi.isMusl()) {
252257
try cflags.append("-D_LIBCPP_HAS_MUSL_LIBC");
@@ -292,6 +297,8 @@ pub fn buildLibCXXABI(comp: *Compilation) !void {
292297
.want_tsan = comp.bin_file.options.tsan,
293298
.want_pic = comp.bin_file.options.pic,
294299
.want_pie = comp.bin_file.options.pie,
300+
.want_lto = comp.bin_file.options.lto,
301+
.function_sections = comp.bin_file.options.function_sections,
295302
.emit_h = null,
296303
.strip = comp.compilerRtStrip(),
297304
.is_native_os = comp.bin_file.options.is_native_os,

src/libunwind.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ pub fn buildStaticLib(comp: *Compilation) !void {
6969
}
7070
try cflags.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS");
7171
try cflags.append("-Wa,--noexecstack");
72+
try cflags.append("-fvisibility=hidden");
73+
try cflags.append("-fvisibility-inlines-hidden");
7274

7375
// This is intentionally always defined because the macro definition means, should it only
7476
// build for the target specified by compiler defines. Since we pass -target the compiler
@@ -113,6 +115,8 @@ pub fn buildStaticLib(comp: *Compilation) !void {
113115
.want_tsan = false,
114116
.want_pic = comp.bin_file.options.pic,
115117
.want_pie = comp.bin_file.options.pie,
118+
.want_lto = comp.bin_file.options.lto,
119+
.function_sections = comp.bin_file.options.function_sections,
116120
.emit_h = null,
117121
.strip = comp.compilerRtStrip(),
118122
.is_native_os = comp.bin_file.options.is_native_os,

0 commit comments

Comments
 (0)