Skip to content

Commit 31cc955

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/opt-index-of-diff' into opt-index-of-diff
2 parents 8906bad + b649daa commit 31cc955

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1280
-965
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ jobs:
2020
uses: actions/checkout@v4
2121
- name: Build and Test
2222
run: sh ci/x86_64-linux-debug.sh
23+
x86_64-linux-debug-llvm:
24+
timeout-minutes: 540
25+
runs-on: [self-hosted, Linux, x86_64]
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
- name: Build and Test
30+
run: sh ci/x86_64-linux-debug-llvm.sh
2331
x86_64-linux-release:
2432
timeout-minutes: 540
2533
runs-on: [self-hosted, Linux, x86_64]

CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ set(ZIG_STAGE2_SOURCES
519519
src/Air/Legalize.zig
520520
src/Air/Liveness.zig
521521
src/Air/Liveness/Verify.zig
522+
src/Air/print.zig
522523
src/Air/types_resolved.zig
523524
src/Builtin.zig
524525
src/Compilation.zig
@@ -675,7 +676,6 @@ set(ZIG_STAGE2_SOURCES
675676
src/libs/mingw.zig
676677
src/libs/musl.zig
677678
src/mutable_value.zig
678-
src/print_air.zig
679679
src/print_env.zig
680680
src/print_targets.zig
681681
src/print_value.zig
@@ -797,13 +797,12 @@ elseif(ZIG_HOST_TARGET_ARCH STREQUAL "amd64")
797797
set(ZIG_HOST_TARGET_ARCH "x86_64")
798798
elseif(ZIG_HOST_TARGET_ARCH STREQUAL "arm64")
799799
set(ZIG_HOST_TARGET_ARCH "aarch64")
800-
elseif(ZIG_HOST_TARGET_ARCH STREQUAL "armv7l")
800+
elseif(ZIG_HOST_TARGET_ARCH MATCHES "^arm(el)?$" OR ZIG_HOST_TARGET_ARCH MATCHES "^armv[7-8]l$")
801801
set(ZIG_HOST_TARGET_ARCH "arm")
802-
elseif(ZIG_HOST_TARGET_ARCH STREQUAL "armv7b")
802+
elseif(ZIG_HOST_TARGET_ARCH STREQUAL "armeb" OR ZIG_HOST_TARGET_ARCH MATCHES "^armv[7-8]b$")
803803
set(ZIG_HOST_TARGET_ARCH "armeb")
804804
endif()
805-
string(REGEX REPLACE "^((arm|thumb)(hf?)?)el$" "\\1" ZIG_HOST_TARGET_ARCH "${ZIG_HOST_TARGET_ARCH}")
806-
if(ZIG_HOST_TARGET_ARCH MATCHES "^arm(hf?)?(eb)?$")
805+
if(ZIG_HOST_TARGET_ARCH MATCHES "^arm(eb)?$")
807806
check_symbol_exists(__thumb__ "" ZIG_HOST_TARGET_DEFAULTS_TO_THUMB)
808807
if(ZIG_HOST_TARGET_DEFAULTS_TO_THUMB)
809808
string(REGEX REPLACE "^arm" "thumb" ZIG_HOST_TARGET_ARCH "${ZIG_HOST_TARGET_ARCH}")

build.zig

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ pub fn build(b: *std.Build) !void {
9292
const skip_single_threaded = b.option(bool, "skip-single-threaded", "Main test suite skips tests that are single-threaded") orelse false;
9393
const skip_translate_c = b.option(bool, "skip-translate-c", "Main test suite skips translate-c tests") orelse false;
9494
const skip_run_translated_c = b.option(bool, "skip-run-translated-c", "Main test suite skips run-translated-c tests") orelse false;
95+
const skip_freebsd = b.option(bool, "skip-freebsd", "Main test suite skips targets with freebsd OS") orelse false;
96+
const skip_netbsd = b.option(bool, "skip-netbsd", "Main test suite skips targets with netbsd OS") orelse false;
97+
const skip_windows = b.option(bool, "skip-windows", "Main test suite skips targets with windows OS") orelse false;
98+
const skip_macos = b.option(bool, "skip-macos", "Main test suite skips targets with macos OS") orelse false;
99+
const skip_linux = b.option(bool, "skip-linux", "Main test suite skips targets with linux OS") orelse false;
100+
const skip_llvm = b.option(bool, "skip-llvm", "Main test suite skips targets that use LLVM backend") orelse false;
95101

96102
const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
97103

@@ -435,10 +441,15 @@ pub fn build(b: *std.Build) !void {
435441
.include_paths = &.{},
436442
.skip_single_threaded = skip_single_threaded,
437443
.skip_non_native = skip_non_native,
444+
.skip_freebsd = skip_freebsd,
445+
.skip_netbsd = skip_netbsd,
446+
.skip_windows = skip_windows,
447+
.skip_macos = skip_macos,
448+
.skip_linux = skip_linux,
449+
.skip_llvm = skip_llvm,
438450
.skip_libc = skip_libc,
439-
.use_llvm = use_llvm,
440-
// 2520100864 was observed on an x86_64-linux-gnu host.
441-
.max_rss = 2772110950,
451+
// 2923515904 was observed on an x86_64-linux-gnu host.
452+
.max_rss = 3100000000,
442453
}));
443454

444455
test_modules_step.dependOn(tests.addModuleTests(b, .{
@@ -452,8 +463,13 @@ pub fn build(b: *std.Build) !void {
452463
.include_paths = &.{"test/c_import"},
453464
.skip_single_threaded = true,
454465
.skip_non_native = skip_non_native,
466+
.skip_freebsd = skip_freebsd,
467+
.skip_netbsd = skip_netbsd,
468+
.skip_windows = skip_windows,
469+
.skip_macos = skip_macos,
470+
.skip_linux = skip_linux,
471+
.skip_llvm = skip_llvm,
455472
.skip_libc = skip_libc,
456-
.use_llvm = use_llvm,
457473
}));
458474

459475
test_modules_step.dependOn(tests.addModuleTests(b, .{
@@ -467,8 +483,13 @@ pub fn build(b: *std.Build) !void {
467483
.include_paths = &.{},
468484
.skip_single_threaded = true,
469485
.skip_non_native = skip_non_native,
486+
.skip_freebsd = skip_freebsd,
487+
.skip_netbsd = skip_netbsd,
488+
.skip_windows = skip_windows,
489+
.skip_macos = skip_macos,
490+
.skip_linux = skip_linux,
491+
.skip_llvm = skip_llvm,
470492
.skip_libc = true,
471-
.use_llvm = use_llvm,
472493
.no_builtin = true,
473494
}));
474495

@@ -483,8 +504,13 @@ pub fn build(b: *std.Build) !void {
483504
.include_paths = &.{},
484505
.skip_single_threaded = true,
485506
.skip_non_native = skip_non_native,
507+
.skip_freebsd = skip_freebsd,
508+
.skip_netbsd = skip_netbsd,
509+
.skip_windows = skip_windows,
510+
.skip_macos = skip_macos,
511+
.skip_linux = skip_linux,
512+
.skip_llvm = skip_llvm,
486513
.skip_libc = true,
487-
.use_llvm = use_llvm,
488514
.no_builtin = true,
489515
}));
490516

@@ -499,8 +525,13 @@ pub fn build(b: *std.Build) !void {
499525
.include_paths = &.{},
500526
.skip_single_threaded = skip_single_threaded,
501527
.skip_non_native = skip_non_native,
528+
.skip_freebsd = skip_freebsd,
529+
.skip_netbsd = skip_netbsd,
530+
.skip_windows = skip_windows,
531+
.skip_macos = skip_macos,
532+
.skip_linux = skip_linux,
533+
.skip_llvm = skip_llvm,
502534
.skip_libc = skip_libc,
503-
.use_llvm = use_llvm,
504535
// I observed a value of 5605064704 on the M2 CI.
505536
.max_rss = 6165571174,
506537
}));
@@ -536,6 +567,12 @@ pub fn build(b: *std.Build) !void {
536567
test_step.dependOn(tests.addCAbiTests(b, .{
537568
.test_target_filters = test_target_filters,
538569
.skip_non_native = skip_non_native,
570+
.skip_freebsd = skip_freebsd,
571+
.skip_netbsd = skip_netbsd,
572+
.skip_windows = skip_windows,
573+
.skip_macos = skip_macos,
574+
.skip_linux = skip_linux,
575+
.skip_llvm = skip_llvm,
539576
.skip_release = skip_release,
540577
}));
541578
test_step.dependOn(tests.addLinkTests(b, enable_macos_sdk, enable_ios_sdk, enable_symlinks_windows));
@@ -549,7 +586,6 @@ pub fn build(b: *std.Build) !void {
549586
.lldb = b.option([]const u8, "lldb", "path to lldb binary"),
550587
.optimize_modes = optimization_modes,
551588
.skip_single_threaded = skip_single_threaded,
552-
.skip_non_native = skip_non_native,
553589
.skip_libc = skip_libc,
554590
})) |test_debugger_step| test_step.dependOn(test_debugger_step);
555591
if (tests.addLlvmIrTests(b, .{

ci/x86_64-linux-debug-llvm.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/sh
2+
3+
# Requires cmake ninja-build
4+
5+
set -x
6+
set -e
7+
8+
ARCH="$(uname -m)"
9+
TARGET="$ARCH-linux-musl"
10+
MCPU="baseline"
11+
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.15.0-dev.233+7c85dc460"
12+
PREFIX="$HOME/deps/$CACHE_BASENAME"
13+
ZIG="$PREFIX/bin/zig"
14+
15+
export PATH="$HOME/deps/wasmtime-v29.0.0-$ARCH-linux:$HOME/deps/qemu-linux-x86_64-9.2.0-rc1/bin:$HOME/local/bin:$PATH"
16+
17+
# Make the `zig version` number consistent.
18+
# This will affect the cmake command below.
19+
git fetch --unshallow || true
20+
git fetch --tags
21+
22+
# Override the cache directories because they won't actually help other CI runs
23+
# which will be testing alternate versions of zig, and ultimately would just
24+
# fill up space on the hard drive for no reason.
25+
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
26+
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
27+
28+
mkdir build-debug-llvm
29+
cd build-debug-llvm
30+
31+
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
32+
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
33+
34+
cmake .. \
35+
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
36+
-DCMAKE_PREFIX_PATH="$PREFIX" \
37+
-DCMAKE_BUILD_TYPE=Debug \
38+
-DZIG_TARGET_TRIPLE="$TARGET" \
39+
-DZIG_TARGET_MCPU="$MCPU" \
40+
-DZIG_STATIC=ON \
41+
-DZIG_NO_LIB=ON \
42+
-DZIG_EXTRA_BUILD_ARGS="-Duse-llvm=true" \
43+
-GNinja
44+
45+
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
46+
# so that installation and testing do not get affected by them.
47+
unset CC
48+
unset CXX
49+
50+
ninja install
51+
52+
# simultaneously test building self-hosted without LLVM and with 32-bit arm
53+
stage3-debug/bin/zig build \
54+
-Dtarget=arm-linux-musleabihf \
55+
-Dno-lib
56+
57+
stage3-debug/bin/zig build test docs \
58+
--maxrss 21000000000 \
59+
-Dlldb=$HOME/deps/lldb-zig/Debug-e0a42bb34/bin/lldb \
60+
-fqemu \
61+
-fwasmtime \
62+
-Dstatic-llvm \
63+
-Dskip-freebsd \
64+
-Dskip-netbsd \
65+
-Dskip-windows \
66+
-Dskip-macos \
67+
-Dtarget=native-native-musl \
68+
--search-prefix "$PREFIX" \
69+
--zig-lib-dir "$PWD/../lib" \
70+
-Denable-superhtml

ci/x86_64-linux-debug.sh

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ git fetch --tags
2525
export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache"
2626
export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache"
2727

28-
# Test building from source without LLVM.
29-
cc -o bootstrap bootstrap.c
30-
./bootstrap
31-
./zig2 build -Dno-lib
32-
./zig-out/bin/zig test test/behavior.zig
33-
3428
mkdir build-debug
3529
cd build-debug
3630

@@ -65,39 +59,12 @@ stage3-debug/bin/zig build test docs \
6559
-fqemu \
6660
-fwasmtime \
6761
-Dstatic-llvm \
62+
-Dskip-freebsd \
63+
-Dskip-netbsd \
64+
-Dskip-windows \
65+
-Dskip-macos \
66+
-Dskip-llvm \
6867
-Dtarget=native-native-musl \
6968
--search-prefix "$PREFIX" \
7069
--zig-lib-dir "$PWD/../lib" \
7170
-Denable-superhtml
72-
73-
# Ensure that updating the wasm binary from this commit will result in a viable build.
74-
stage3-debug/bin/zig build update-zig1
75-
76-
mkdir ../build-new
77-
cd ../build-new
78-
79-
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
80-
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
81-
82-
cmake .. \
83-
-DCMAKE_PREFIX_PATH="$PREFIX" \
84-
-DCMAKE_BUILD_TYPE=Debug \
85-
-DZIG_TARGET_TRIPLE="$TARGET" \
86-
-DZIG_TARGET_MCPU="$MCPU" \
87-
-DZIG_STATIC=ON \
88-
-DZIG_NO_LIB=ON \
89-
-GNinja
90-
91-
unset CC
92-
unset CXX
93-
94-
ninja install
95-
96-
stage3/bin/zig test ../test/behavior.zig
97-
stage3/bin/zig build -p stage4 \
98-
-Dstatic-llvm \
99-
-Dtarget=native-native-musl \
100-
-Dno-lib \
101-
--search-prefix "$PREFIX" \
102-
--zig-lib-dir "$PWD/../lib"
103-
stage4/bin/zig test ../test/behavior.zig

doc/langref.html.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@
777777
value. Using this value would be a bug. The value will be unused, or overwritten before being used."
778778
</p>
779779
<p>
780-
In {#link|Debug#} mode, Zig writes {#syntax#}0xaa{#endsyntax#} bytes to undefined memory. This is to catch
780+
In {#link|Debug#} and {#link|ReleaseSafe#} mode, Zig writes {#syntax#}0xaa{#endsyntax#} bytes to undefined memory. This is to catch
781781
bugs early, and to help detect use of undefined memory in a debugger. However, this behavior is only an
782782
implementation feature, not a language semantic, so it is not guaranteed to be observable to code.
783783
</p>
@@ -2295,7 +2295,7 @@ or
22952295
{#code|test_aligned_struct_fields.zig#}
22962296

22972297
<p>
2298-
Equating packed structs results in a comparison of the backing integer,
2298+
Equating packed structs results in a comparison of the backing integer,
22992299
and only works for the {#syntax#}=={#endsyntax#} and {#syntax#}!={#endsyntax#} {#link|Operators#}.
23002300
</p>
23012301
{#code|test_packed_struct_equality.zig#}

doc/langref/test_global_assembly.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ test "global assembly" {
1919

2020
// test
2121
// target=x86_64-linux
22+
// llvm=true

lib/std/Target.zig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,12 +2581,16 @@ pub fn standardDynamicLinkerPath(target: Target) DynamicLinker {
25812581
}
25822582

25832583
pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {
2584+
return ptrBitWidth_arch_abi(cpu.arch, abi);
2585+
}
2586+
2587+
pub fn ptrBitWidth_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) u16 {
25842588
switch (abi) {
25852589
.gnux32, .muslx32, .gnuabin32, .muslabin32, .ilp32 => return 32,
25862590
.gnuabi64, .muslabi64 => return 64,
25872591
else => {},
25882592
}
2589-
return switch (cpu.arch) {
2593+
return switch (cpu_arch) {
25902594
.avr,
25912595
.msp430,
25922596
=> 16,

lib/std/builtin.zig

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub const StackTrace = struct {
6161

6262
/// This data structure is used by the Zig language code generation and
6363
/// therefore must be kept in sync with the compiler implementation.
64-
pub const GlobalLinkage = enum {
64+
pub const GlobalLinkage = enum(u2) {
6565
internal,
6666
strong,
6767
weak,
@@ -70,7 +70,7 @@ pub const GlobalLinkage = enum {
7070

7171
/// This data structure is used by the Zig language code generation and
7272
/// therefore must be kept in sync with the compiler implementation.
73-
pub const SymbolVisibility = enum {
73+
pub const SymbolVisibility = enum(u2) {
7474
default,
7575
hidden,
7676
protected,
@@ -1030,8 +1030,19 @@ pub const ExternOptions = struct {
10301030
name: []const u8,
10311031
library_name: ?[]const u8 = null,
10321032
linkage: GlobalLinkage = .strong,
1033+
visibility: SymbolVisibility = .default,
1034+
/// Setting this to `true` makes the `@extern` a runtime value.
10331035
is_thread_local: bool = false,
10341036
is_dll_import: bool = false,
1037+
relocation: Relocation = .any,
1038+
1039+
pub const Relocation = enum(u1) {
1040+
/// Any type of relocation is allowed.
1041+
any,
1042+
/// A program-counter-relative relocation is required.
1043+
/// Using this value makes the `@extern` a runtime value.
1044+
pcrel,
1045+
};
10351046
};
10361047

10371048
/// This data structure is used by the Zig language code generation and

lib/std/dynamic_library.zig

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ const RDebug = extern struct {
8383
r_ldbase: usize,
8484
};
8585

86-
/// TODO make it possible to reference this same external symbol 2x so we don't need this
87-
/// helper function.
88-
pub fn get_DYNAMIC() ?[*]elf.Dyn {
89-
return @extern([*]elf.Dyn, .{ .name = "_DYNAMIC", .linkage = .weak });
86+
/// TODO fix comparisons of extern symbol pointers so we don't need this helper function.
87+
pub fn get_DYNAMIC() ?[*]const elf.Dyn {
88+
return @extern([*]const elf.Dyn, .{
89+
.name = "_DYNAMIC",
90+
.linkage = .weak,
91+
.visibility = .hidden,
92+
});
9093
}
9194

92-
pub fn linkmap_iterator(phdrs: []elf.Phdr) error{InvalidExe}!LinkMap.Iterator {
95+
pub fn linkmap_iterator(phdrs: []const elf.Phdr) error{InvalidExe}!LinkMap.Iterator {
9396
_ = phdrs;
9497
const _DYNAMIC = get_DYNAMIC() orelse {
9598
// No PT_DYNAMIC means this is either a statically-linked program or a

0 commit comments

Comments
 (0)