Skip to content

Commit d000e53

Browse files
authored
Merge pull request #23923 from alexrp/compiler-rt-symbols
Use hidden visibility in compiler-rt and libzigc except when testing
2 parents b27c5fb + b0c10e2 commit d000e53

10 files changed

+141
-133
lines changed

build.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ pub fn build(b: *std.Build) !void {
437437
.skip_non_native = skip_non_native,
438438
.skip_libc = skip_libc,
439439
.use_llvm = use_llvm,
440-
.max_rss = 2 * 1024 * 1024 * 1024,
440+
// 2262585344 was observed on an x86_64-linux-gnu host.
441+
.max_rss = 2488843878,
441442
}));
442443

443444
test_modules_step.dependOn(tests.addModuleTests(b, .{

lib/c/common.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ else
99
/// Determines the symbol's visibility to other objects.
1010
/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
1111
/// export it to the host runtime.
12-
pub const visibility: std.builtin.SymbolVisibility = if (builtin.cpu.arch.isWasm() and linkage != .internal)
12+
pub const visibility: std.builtin.SymbolVisibility = if (linkage != .internal)
1313
.hidden
1414
else
1515
.default;

lib/compiler_rt/aarch64_outline_atomics.zig

Lines changed: 101 additions & 101 deletions
Large diffs are not rendered by default.

lib/compiler_rt/clear_cache.zig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ const std = @import("std");
22
const builtin = @import("builtin");
33
const arch = builtin.cpu.arch;
44
const os = builtin.os.tag;
5-
pub const panic = @import("common.zig").panic;
5+
const common = @import("common.zig");
6+
pub const panic = common.panic;
67

78
// Ported from llvm-project d32170dbd5b0d54436537b6b75beaf44324e0c28
89

@@ -174,10 +175,8 @@ fn clear_cache(start: usize, end: usize) callconv(.c) void {
174175
}
175176
}
176177

177-
const linkage = if (builtin.is_test) std.builtin.GlobalLinkage.internal else std.builtin.GlobalLinkage.weak;
178-
179178
fn exportIt() void {
180-
@export(&clear_cache, .{ .name = "__clear_cache", .linkage = linkage });
179+
@export(&clear_cache, .{ .name = "__clear_cache", .linkage = common.linkage, .visibility = common.visibility });
181180
}
182181

183182
// Darwin-only

lib/compiler_rt/common.zig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const builtin = @import("builtin");
33
const native_endian = builtin.cpu.arch.endian();
44
const ofmt_c = builtin.object_format == .c;
55

6+
/// For now, we prefer weak linkage because some of the routines we implement here may also be
7+
/// provided by system/dynamic libc. Eventually we should be more disciplined about this on a
8+
/// per-symbol, per-target basis: https://github.com/ziglang/zig/issues/11883
69
pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test)
710
.internal
811
else if (ofmt_c)
@@ -13,8 +16,10 @@ else
1316
/// Determines the symbol's visibility to other objects.
1417
/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
1518
/// export it to the host runtime.
16-
pub const visibility: std.builtin.SymbolVisibility =
17-
if (builtin.target.cpu.arch.isWasm() and linkage != .internal) .hidden else .default;
19+
pub const visibility: std.builtin.SymbolVisibility = if (linkage != .internal)
20+
.hidden
21+
else
22+
.default;
1823

1924
pub const PreferredLoadStoreElement = element: {
2025
if (std.simd.suggestVectorLength(u8)) |vec_size| {

lib/compiler_rt/os_version_check.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const std = @import("std");
22
const testing = std.testing;
33
const builtin = @import("builtin");
4-
const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .weak;
4+
const common = @import("common.zig");
55
const panic = @import("common.zig").panic;
66

77
const have_availability_version_check = builtin.os.tag.isDarwin() and
88
builtin.os.version_range.semver.min.order(.{ .major = 10, .minor = 15, .patch = 0 }).compare(.gte);
99

1010
comptime {
1111
if (have_availability_version_check) {
12-
@export(&__isPlatformVersionAtLeast, .{ .name = "__isPlatformVersionAtLeast", .linkage = linkage });
12+
@export(&__isPlatformVersionAtLeast, .{ .name = "__isPlatformVersionAtLeast", .linkage = common.linkage, .visibility = common.visibility });
1313
}
1414
}
1515

lib/compiler_rt/stack_probe.zig

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
3+
const common = @import("common.zig");
34
const os_tag = builtin.os.tag;
45
const arch = builtin.cpu.arch;
56
const abi = builtin.abi;
67
const is_test = builtin.is_test;
78

8-
const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .weak;
9-
const strong_linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .strong;
10-
pub const panic = @import("common.zig").panic;
9+
pub const panic = common.panic;
1110

1211
comptime {
1312
if (builtin.os.tag == .windows) {
1413
// Default stack-probe functions emitted by LLVM
1514
if (builtin.target.isMinGW()) {
16-
@export(&_chkstk, .{ .name = "_alloca", .linkage = linkage });
17-
@export(&___chkstk_ms, .{ .name = "___chkstk_ms", .linkage = linkage });
15+
@export(&_chkstk, .{ .name = "_alloca", .linkage = common.linkage, .visibility = common.visibility });
16+
@export(&___chkstk_ms, .{ .name = "___chkstk_ms", .linkage = common.linkage, .visibility = common.visibility });
1817

1918
if (arch == .thumb or arch == .aarch64) {
20-
@export(&__chkstk, .{ .name = "__chkstk", .linkage = linkage });
19+
@export(&__chkstk, .{ .name = "__chkstk", .linkage = common.linkage, .visibility = common.visibility });
2120
}
2221
} else if (!builtin.link_libc) {
2322
// This symbols are otherwise exported by MSVCRT.lib
24-
@export(&_chkstk, .{ .name = "_chkstk", .linkage = linkage });
25-
@export(&__chkstk, .{ .name = "__chkstk", .linkage = linkage });
23+
@export(&_chkstk, .{ .name = "_chkstk", .linkage = common.linkage, .visibility = common.visibility });
24+
@export(&__chkstk, .{ .name = "__chkstk", .linkage = common.linkage, .visibility = common.visibility });
2625
}
2726
}
2827

2928
switch (arch) {
3029
.x86,
3130
.x86_64,
3231
=> {
33-
@export(&zig_probe_stack, .{ .name = "__zig_probe_stack", .linkage = linkage });
32+
@export(&zig_probe_stack, .{ .name = "__zig_probe_stack", .linkage = common.linkage, .visibility = common.visibility });
3433
},
3534
else => {},
3635
}

lib/std/leb128.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const builtin = @import("builtin");
12
const std = @import("std");
23
const testing = std.testing;
34

@@ -432,6 +433,8 @@ fn test_write_leb128(value: anytype) !void {
432433
}
433434

434435
test "serialize unsigned LEB128" {
436+
if (builtin.cpu.arch == .x86 and builtin.abi == .musl and builtin.link_mode == .dynamic) return error.SkipZigTest;
437+
435438
const max_bits = 18;
436439

437440
comptime var t = 0;
@@ -446,6 +449,8 @@ test "serialize unsigned LEB128" {
446449
}
447450

448451
test "serialize signed LEB128" {
452+
if (builtin.cpu.arch == .x86 and builtin.abi == .musl and builtin.link_mode == .dynamic) return error.SkipZigTest;
453+
449454
// explicitly test i0 because starting `t` at 0
450455
// will break the while loop
451456
try test_write_leb128(@as(i0, 0));

test/tests.zig

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,16 @@ const test_targets = blk: {
296296
},
297297
.link_libc = true,
298298
},
299-
// https://github.com/ziglang/zig/issues/7935
300-
// .{
301-
// .target = .{
302-
// .cpu_arch = .x86,
303-
// .os_tag = .linux,
304-
// .abi = .musl,
305-
// },
306-
// .linkage = .dynamic,
307-
// .link_libc = true,
308-
// .extra_target = true,
309-
// },
299+
.{
300+
.target = .{
301+
.cpu_arch = .x86,
302+
.os_tag = .linux,
303+
.abi = .musl,
304+
},
305+
.linkage = .dynamic,
306+
.link_libc = true,
307+
.extra_target = true,
308+
},
310309
.{
311310
.target = .{
312311
.cpu_arch = .x86,

tools/gen_outline_atomics.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn main() !void {
2424
\\//! This file is generated by tools/gen_outline_atomics.zig.
2525
\\const builtin = @import("builtin");
2626
\\const std = @import("std");
27-
\\const linkage = @import("./common.zig").linkage;
27+
\\const common = @import("common.zig");
2828
\\const always_has_lse = std.Target.aarch64.featureSetHas(builtin.cpu.features, .lse);
2929
\\
3030
\\/// This default is overridden at runtime after inspecting CPU properties.
@@ -48,7 +48,7 @@ pub fn main() !void {
4848
@tagName(op), n.toBytes(), @tagName(order),
4949
});
5050
try writeFunction(arena, w, name, op, n, order);
51-
try footer.writer().print(" @export(&{s}, .{{ .name = \"{s}\", .linkage = linkage }});\n", .{
51+
try footer.writer().print(" @export(&{s}, .{{ .name = \"{s}\", .linkage = common.linkage, .visibility = common.visibility }});\n", .{
5252
name, name,
5353
});
5454
}

0 commit comments

Comments
 (0)