| ... | @@ -109,20 +109,20 @@ fn testDeadStrip(b: *Build, opts: Options) *Step { | ... | @@ -109,20 +109,20 @@ fn testDeadStrip(b: *Build, opts: Options) *Step { |
| 109 | const test_step = addTestStep(b, "dead-strip", opts); | 109 | const test_step = addTestStep(b, "dead-strip", opts); |
| 110 | | 110 | |
| 111 | const obj = addObject(b, opts, .{ .name = "a", .cpp_source_bytes = | 111 | const obj = addObject(b, opts, .{ .name = "a", .cpp_source_bytes = |
| 112 | \\#include <stdio.h> | 112 | \\#include <stdio.h> |
| 113 | \\int two() { return 2; } | 113 | \\int two() { return 2; } |
| 114 | \\int live_var1 = 1; | 114 | \\int live_var1 = 1; |
| 115 | \\int live_var2 = two(); | 115 | \\int live_var2 = two(); |
| 116 | \\int dead_var1 = 3; | 116 | \\int dead_var1 = 3; |
| 117 | \\int dead_var2 = 4; | 117 | \\int dead_var2 = 4; |
| 118 | \\void live_fn1() {} | 118 | \\void live_fn1() {} |
| 119 | \\void live_fn2() { live_fn1(); } | 119 | \\void live_fn2() { live_fn1(); } |
| 120 | \\void dead_fn1() {} | 120 | \\void dead_fn1() {} |
| 121 | \\void dead_fn2() { dead_fn1(); } | 121 | \\void dead_fn2() { dead_fn1(); } |
| 122 | \\int main() { | 122 | \\int main() { |
| 123 | \\ printf("%d %d\n", live_var1, live_var2); | 123 | \\ printf("%d %d\n", live_var1, live_var2); |
| 124 | \\ live_fn2(); | 124 | \\ live_fn2(); |
| 125 | \\} | 125 | \\} |
| 126 | }); | 126 | }); |
| 127 | | 127 | |
| 128 | { | 128 | { |
| ... | @@ -190,21 +190,21 @@ fn testDuplicateDefinitions(b: *Build, opts: Options) *Step { | ... | @@ -190,21 +190,21 @@ fn testDuplicateDefinitions(b: *Build, opts: Options) *Step { |
| 190 | const test_step = addTestStep(b, "duplicate-definitions", opts); | 190 | const test_step = addTestStep(b, "duplicate-definitions", opts); |
| 191 | | 191 | |
| 192 | const obj = addObject(b, opts, .{ .name = "a", .zig_source_bytes = | 192 | const obj = addObject(b, opts, .{ .name = "a", .zig_source_bytes = |
| 193 | \\var x: usize = 1; | 193 | \\var x: usize = 1; |
| 194 | \\export fn strong() void { x += 1; } | 194 | \\export fn strong() void { x += 1; } |
| 195 | \\export fn weak() void { x += 1; } | 195 | \\export fn weak() void { x += 1; } |
| 196 | }); | 196 | }); |
| 197 | | 197 | |
| 198 | const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = | 198 | const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = |
| 199 | \\var x: usize = 1; | 199 | \\var x: usize = 1; |
| 200 | \\export fn strong() void { x += 1; } | 200 | \\export fn strong() void { x += 1; } |
| 201 | \\comptime { @export(&weakImpl, .{ .name = "weak", .linkage = .weak }); } | 201 | \\comptime { @export(&weakImpl, .{ .name = "weak", .linkage = .weak }); } |
| 202 | \\fn weakImpl() callconv(.C) void { x += 1; } | 202 | \\fn weakImpl() callconv(.C) void { x += 1; } |
| 203 | \\extern fn weak() void; | 203 | \\extern fn weak() void; |
| 204 | \\pub fn main() void { | 204 | \\pub fn main() void { |
| 205 | \\ weak(); | 205 | \\ weak(); |
| 206 | \\ strong(); | 206 | \\ strong(); |
| 207 | \\} | 207 | \\} |
| 208 | }); | 208 | }); |
| 209 | exe.addObject(obj); | 209 | exe.addObject(obj); |
| 210 | | 210 | |
| ... | @@ -221,16 +221,16 @@ fn testDeadStripDylibs(b: *Build, opts: Options) *Step { | ... | @@ -221,16 +221,16 @@ fn testDeadStripDylibs(b: *Build, opts: Options) *Step { |
| 221 | const test_step = addTestStep(b, "dead-strip-dylibs", opts); | 221 | const test_step = addTestStep(b, "dead-strip-dylibs", opts); |
| 222 | | 222 | |
| 223 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = | 223 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = |
| 224 | \\#include <objc/runtime.h> | 224 | \\#include <objc/runtime.h> |
| 225 | \\int main() { | 225 | \\int main() { |
| 226 | \\ if (objc_getClass("NSObject") == 0) { | 226 | \\ if (objc_getClass("NSObject") == 0) { |
| 227 | \\ return -1; | 227 | \\ return -1; |
| 228 | \\ } | 228 | \\ } |
| 229 | \\ if (objc_getClass("NSApplication") == 0) { | 229 | \\ if (objc_getClass("NSApplication") == 0) { |
| 230 | \\ return -2; | 230 | \\ return -2; |
| 231 | \\ } | 231 | \\ } |
| 232 | \\ return 0; | 232 | \\ return 0; |
| 233 | \\} | 233 | \\} |
| 234 | }); | 234 | }); |
| 235 | | 235 | |
| 236 | { | 236 | { |
| ... | @@ -270,11 +270,11 @@ fn testDylib(b: *Build, opts: Options) *Step { | ... | @@ -270,11 +270,11 @@ fn testDylib(b: *Build, opts: Options) *Step { |
| 270 | const test_step = addTestStep(b, "dylib", opts); | 270 | const test_step = addTestStep(b, "dylib", opts); |
| 271 | | 271 | |
| 272 | const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = | 272 | const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = |
| 273 | \\#include<stdio.h> | 273 | \\#include<stdio.h> |
| 274 | \\char world[] = "world"; | 274 | \\char world[] = "world"; |
| 275 | \\char* hello() { | 275 | \\char* hello() { |
| 276 | \\ return "Hello"; | 276 | \\ return "Hello"; |
| 277 | \\} | 277 | \\} |
| 278 | }); | 278 | }); |
| 279 | | 279 | |
| 280 | const check = dylib.checkObject(); | 280 | const check = dylib.checkObject(); |
| ... | @@ -284,13 +284,13 @@ fn testDylib(b: *Build, opts: Options) *Step { | ... | @@ -284,13 +284,13 @@ fn testDylib(b: *Build, opts: Options) *Step { |
| 284 | test_step.dependOn(&check.step); | 284 | test_step.dependOn(&check.step); |
| 285 | | 285 | |
| 286 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 286 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 287 | \\#include<stdio.h> | 287 | \\#include<stdio.h> |
| 288 | \\char* hello(); | 288 | \\char* hello(); |
| 289 | \\extern char world[]; | 289 | \\extern char world[]; |
| 290 | \\int main() { | 290 | \\int main() { |
| 291 | \\ printf("%s %s", hello(), world); | 291 | \\ printf("%s %s", hello(), world); |
| 292 | \\ return 0; | 292 | \\ return 0; |
| 293 | \\} | 293 | \\} |
| 294 | }); | 294 | }); |
| 295 | exe.root_module.linkSystemLibrary("a", .{}); | 295 | exe.root_module.linkSystemLibrary("a", .{}); |
| 296 | exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory()); | 296 | exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory()); |
| ... | @@ -345,10 +345,10 @@ fn testEmptyObject(b: *Build, opts: Options) *Step { | ... | @@ -345,10 +345,10 @@ fn testEmptyObject(b: *Build, opts: Options) *Step { |
| 345 | const empty = addObject(b, opts, .{ .name = "empty", .c_source_bytes = "" }); | 345 | const empty = addObject(b, opts, .{ .name = "empty", .c_source_bytes = "" }); |
| 346 | | 346 | |
| 347 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 347 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 348 | \\#include <stdio.h> | 348 | \\#include <stdio.h> |
| 349 | \\int main() { | 349 | \\int main() { |
| 350 | \\ printf("Hello world!"); | 350 | \\ printf("Hello world!"); |
| 351 | \\} | 351 | \\} |
| 352 | }); | 352 | }); |
| 353 | exe.addObject(empty); | 353 | exe.addObject(empty); |
| 354 | | 354 | |
| ... | @@ -375,11 +375,11 @@ fn testEntryPoint(b: *Build, opts: Options) *Step { | ... | @@ -375,11 +375,11 @@ fn testEntryPoint(b: *Build, opts: Options) *Step { |
| 375 | const test_step = addTestStep(b, "entry-point", opts); | 375 | const test_step = addTestStep(b, "entry-point", opts); |
| 376 | | 376 | |
| 377 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 377 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 378 | \\#include<stdio.h> | 378 | \\#include<stdio.h> |
| 379 | \\int non_main() { | 379 | \\int non_main() { |
| 380 | \\ printf("%d", 42); | 380 | \\ printf("%d", 42); |
| 381 | \\ return 0; | 381 | \\ return 0; |
| 382 | \\} | 382 | \\} |
| 383 | }); | 383 | }); |
| 384 | exe.entry = .{ .symbol_name = "_non_main" }; | 384 | exe.entry = .{ .symbol_name = "_non_main" }; |
| 385 | | 385 | |
| ... | @@ -597,10 +597,10 @@ fn testHeaderWeakFlags(b: *Build, opts: Options) *Step { | ... | @@ -597,10 +597,10 @@ fn testHeaderWeakFlags(b: *Build, opts: Options) *Step { |
| 597 | const test_step = addTestStep(b, "header-weak-flags", opts); | 597 | const test_step = addTestStep(b, "header-weak-flags", opts); |
| 598 | | 598 | |
| 599 | const obj1 = addObject(b, opts, .{ .name = "a", .asm_source_bytes = | 599 | const obj1 = addObject(b, opts, .{ .name = "a", .asm_source_bytes = |
| 600 | \\.globl _x | 600 | \\.globl _x |
| 601 | \\.weak_definition _x | 601 | \\.weak_definition _x |
| 602 | \\_x: | 602 | \\_x: |
| 603 | \\ ret | 603 | \\ ret |
| 604 | }); | 604 | }); |
| 605 | | 605 | |
| 606 | const lib = addSharedLibrary(b, opts, .{ .name = "a" }); | 606 | const lib = addSharedLibrary(b, opts, .{ .name = "a" }); |
| ... | @@ -659,11 +659,11 @@ fn testHeaderWeakFlags(b: *Build, opts: Options) *Step { | ... | @@ -659,11 +659,11 @@ fn testHeaderWeakFlags(b: *Build, opts: Options) *Step { |
| 659 | | 659 | |
| 660 | { | 660 | { |
| 661 | const exe = addExecutable(b, opts, .{ .name = "main3", .asm_source_bytes = | 661 | const exe = addExecutable(b, opts, .{ .name = "main3", .asm_source_bytes = |
| 662 | \\.globl _main, _x | 662 | \\.globl _main, _x |
| 663 | \\_x: | 663 | \\_x: |
| 664 | \\ | 664 | \\ |
| 665 | \\_main: | 665 | \\_main: |
| 666 | \\ ret | 666 | \\ ret |
| 667 | }); | 667 | }); |
| 668 | exe.linkLibrary(lib); | 668 | exe.linkLibrary(lib); |
| 669 | | 669 | |
| ... | @@ -684,11 +684,11 @@ fn testHelloC(b: *Build, opts: Options) *Step { | ... | @@ -684,11 +684,11 @@ fn testHelloC(b: *Build, opts: Options) *Step { |
| 684 | const test_step = addTestStep(b, "hello-c", opts); | 684 | const test_step = addTestStep(b, "hello-c", opts); |
| 685 | | 685 | |
| 686 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 686 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 687 | \\#include <stdio.h> | 687 | \\#include <stdio.h> |
| 688 | \\int main() { | 688 | \\int main() { |
| 689 | \\ printf("Hello world!\n"); | 689 | \\ printf("Hello world!\n"); |
| 690 | \\ return 0; | 690 | \\ return 0; |
| 691 | \\} | 691 | \\} |
| 692 | }); | 692 | }); |
| 693 | | 693 | |
| 694 | const run = addRunArtifact(exe); | 694 | const run = addRunArtifact(exe); |
| ... | @@ -708,10 +708,10 @@ fn testHelloZig(b: *Build, opts: Options) *Step { | ... | @@ -708,10 +708,10 @@ fn testHelloZig(b: *Build, opts: Options) *Step { |
| 708 | const test_step = addTestStep(b, "hello-zig", opts); | 708 | const test_step = addTestStep(b, "hello-zig", opts); |
| 709 | | 709 | |
| 710 | const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = | 710 | const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = |
| 711 | \\const std = @import("std"); | 711 | \\const std = @import("std"); |
| 712 | \\pub fn main() void { | 712 | \\pub fn main() void { |
| 713 | \\ std.io.getStdOut().writer().print("Hello world!\n", .{}) catch unreachable; | 713 | \\ std.io.getStdOut().writer().print("Hello world!\n", .{}) catch unreachable; |
| 714 | \\} | 714 | \\} |
| 715 | }); | 715 | }); |
| 716 | | 716 | |
| 717 | const run = addRunArtifact(exe); | 717 | const run = addRunArtifact(exe); |
| ... | @@ -729,10 +729,10 @@ fn testLargeBss(b: *Build, opts: Options) *Step { | ... | @@ -729,10 +729,10 @@ fn testLargeBss(b: *Build, opts: Options) *Step { |
| 729 | // maybe S_GB_ZEROFILL section is an answer to this but it doesn't seem supported by dyld | 729 | // maybe S_GB_ZEROFILL section is an answer to this but it doesn't seem supported by dyld |
| 730 | // anymore. When I get some free time I will re-investigate this. | 730 | // anymore. When I get some free time I will re-investigate this. |
| 731 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 731 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 732 | \\char arr[0x1000000]; | 732 | \\char arr[0x1000000]; |
| 733 | \\int main() { | 733 | \\int main() { |
| 734 | \\ return arr[2000]; | 734 | \\ return arr[2000]; |
| 735 | \\} | 735 | \\} |
| 736 | }); | 736 | }); |
| 737 | | 737 | |
| 738 | const run = addRunArtifact(exe); | 738 | const run = addRunArtifact(exe); |
| ... | @@ -746,11 +746,11 @@ fn testLayout(b: *Build, opts: Options) *Step { | ... | @@ -746,11 +746,11 @@ fn testLayout(b: *Build, opts: Options) *Step { |
| 746 | const test_step = addTestStep(b, "layout", opts); | 746 | const test_step = addTestStep(b, "layout", opts); |
| 747 | | 747 | |
| 748 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 748 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 749 | \\#include <stdio.h> | 749 | \\#include <stdio.h> |
| 750 | \\int main() { | 750 | \\int main() { |
| 751 | \\ printf("Hello world!"); | 751 | \\ printf("Hello world!"); |
| 752 | \\ return 0; | 752 | \\ return 0; |
| 753 | \\} | 753 | \\} |
| 754 | }); | 754 | }); |
| 755 | | 755 | |
| 756 | const check = exe.checkObject(); | 756 | const check = exe.checkObject(); |
| ... | @@ -936,15 +936,15 @@ fn testLinksection(b: *Build, opts: Options) *Step { | ... | @@ -936,15 +936,15 @@ fn testLinksection(b: *Build, opts: Options) *Step { |
| 936 | const test_step = addTestStep(b, "linksection", opts); | 936 | const test_step = addTestStep(b, "linksection", opts); |
| 937 | | 937 | |
| 938 | const obj = addObject(b, opts, .{ .name = "main", .zig_source_bytes = | 938 | const obj = addObject(b, opts, .{ .name = "main", .zig_source_bytes = |
| 939 | \\export var test_global: u32 linksection("__DATA,__TestGlobal") = undefined; | 939 | \\export var test_global: u32 linksection("__DATA,__TestGlobal") = undefined; |
| 940 | \\export fn testFn() linksection("__TEXT,__TestFn") callconv(.C) void { | 940 | \\export fn testFn() linksection("__TEXT,__TestFn") callconv(.C) void { |
| 941 | \\ TestGenericFn("A").f(); | 941 | \\ TestGenericFn("A").f(); |
| 942 | \\} | 942 | \\} |
| 943 | \\fn TestGenericFn(comptime suffix: []const u8) type { | 943 | \\fn TestGenericFn(comptime suffix: []const u8) type { |
| 944 | \\ return struct { | 944 | \\ return struct { |
| 945 | \\ fn f() linksection("__TEXT,__TestGenFn" ++ suffix) void {} | 945 | \\ fn f() linksection("__TEXT,__TestGenFn" ++ suffix) void {} |
| 946 | \\ }; | 946 | \\ }; |
| 947 | \\} | 947 | \\} |
| 948 | }); | 948 | }); |
| 949 | | 949 | |
| 950 | const check = obj.checkObject(); | 950 | const check = obj.checkObject(); |
| ... | @@ -967,71 +967,71 @@ fn testMergeLiteralsX64(b: *Build, opts: Options) *Step { | ... | @@ -967,71 +967,71 @@ fn testMergeLiteralsX64(b: *Build, opts: Options) *Step { |
| 967 | const test_step = addTestStep(b, "merge-literals-x64", opts); | 967 | const test_step = addTestStep(b, "merge-literals-x64", opts); |
| 968 | | 968 | |
| 969 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = | 969 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = |
| 970 | \\.globl _q1 | 970 | \\.globl _q1 |
| 971 | \\.globl _s1 | 971 | \\.globl _s1 |
| 972 | \\ | 972 | \\ |
| 973 | \\.align 4 | 973 | \\.align 4 |
| 974 | \\_q1: | 974 | \\_q1: |
| 975 | \\ lea L._q1(%rip), %rax | 975 | \\ lea L._q1(%rip), %rax |
| 976 | \\ mov (%rax), %xmm0 | 976 | \\ mov (%rax), %xmm0 |
| 977 | \\ ret | 977 | \\ ret |
| 978 | \\ | 978 | \\ |
| 979 | \\.section __TEXT,__cstring,cstring_literals | 979 | \\.section __TEXT,__cstring,cstring_literals |
| 980 | \\l._s1: | 980 | \\l._s1: |
| 981 | \\ .asciz "hello" | 981 | \\ .asciz "hello" |
| 982 | \\ | 982 | \\ |
| 983 | \\.section __TEXT,__literal8,8byte_literals | 983 | \\.section __TEXT,__literal8,8byte_literals |
| 984 | \\.align 8 | 984 | \\.align 8 |
| 985 | \\L._q1: | 985 | \\L._q1: |
| 986 | \\ .double 1.2345 | 986 | \\ .double 1.2345 |
| 987 | \\ | 987 | \\ |
| 988 | \\.section __DATA,__data | 988 | \\.section __DATA,__data |
| 989 | \\.align 8 | 989 | \\.align 8 |
| 990 | \\_s1: | 990 | \\_s1: |
| 991 | \\ .quad l._s1 | 991 | \\ .quad l._s1 |
| 992 | }); | 992 | }); |
| 993 | | 993 | |
| 994 | const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = | 994 | const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = |
| 995 | \\.globl _q2 | 995 | \\.globl _q2 |
| 996 | \\.globl _s2 | 996 | \\.globl _s2 |
| 997 | \\.globl _s3 | 997 | \\.globl _s3 |
| 998 | \\ | 998 | \\ |
| 999 | \\.align 4 | 999 | \\.align 4 |
| 1000 | \\_q2: | 1000 | \\_q2: |
| 1001 | \\ lea L._q2(%rip), %rax | 1001 | \\ lea L._q2(%rip), %rax |
| 1002 | \\ mov (%rax), %xmm0 | 1002 | \\ mov (%rax), %xmm0 |
| 1003 | \\ ret | 1003 | \\ ret |
| 1004 | \\ | 1004 | \\ |
| 1005 | \\.section __TEXT,__cstring,cstring_literals | 1005 | \\.section __TEXT,__cstring,cstring_literals |
| 1006 | \\l._s2: | 1006 | \\l._s2: |
| 1007 | \\ .asciz "hello" | 1007 | \\ .asciz "hello" |
| 1008 | \\l._s3: | 1008 | \\l._s3: |
| 1009 | \\ .asciz "world" | 1009 | \\ .asciz "world" |
| 1010 | \\ | 1010 | \\ |
| 1011 | \\.section __TEXT,__literal8,8byte_literals | 1011 | \\.section __TEXT,__literal8,8byte_literals |
| 1012 | \\.align 8 | 1012 | \\.align 8 |
| 1013 | \\L._q2: | 1013 | \\L._q2: |
| 1014 | \\ .double 1.2345 | 1014 | \\ .double 1.2345 |
| 1015 | \\ | 1015 | \\ |
| 1016 | \\.section __DATA,__data | 1016 | \\.section __DATA,__data |
| 1017 | \\.align 8 | 1017 | \\.align 8 |
| 1018 | \\_s2: | 1018 | \\_s2: |
| 1019 | \\ .quad l._s2 | 1019 | \\ .quad l._s2 |
| 1020 | \\_s3: | 1020 | \\_s3: |
| 1021 | \\ .quad l._s3 | 1021 | \\ .quad l._s3 |
| 1022 | }); | 1022 | }); |
| 1023 | | 1023 | |
| 1024 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = | 1024 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = |
| 1025 | \\#include <stdio.h> | 1025 | \\#include <stdio.h> |
| 1026 | \\extern double q1(); | 1026 | \\extern double q1(); |
| 1027 | \\extern double q2(); | 1027 | \\extern double q2(); |
| 1028 | \\extern const char* s1; | 1028 | \\extern const char* s1; |
| 1029 | \\extern const char* s2; | 1029 | \\extern const char* s2; |
| 1030 | \\extern const char* s3; | 1030 | \\extern const char* s3; |
| 1031 | \\int main() { | 1031 | \\int main() { |
| 1032 | \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); | 1032 | \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); |
| 1033 | \\ return 0; | 1033 | \\ return 0; |
| 1034 | \\} | 1034 | \\} |
| 1035 | }); | 1035 | }); |
| 1036 | | 1036 | |
| 1037 | const runWithChecks = struct { | 1037 | const runWithChecks = struct { |
| ... | @@ -1083,71 +1083,71 @@ fn testMergeLiteralsArm64(b: *Build, opts: Options) *Step { | ... | @@ -1083,71 +1083,71 @@ fn testMergeLiteralsArm64(b: *Build, opts: Options) *Step { |
| 1083 | const test_step = addTestStep(b, "merge-literals-arm64", opts); | 1083 | const test_step = addTestStep(b, "merge-literals-arm64", opts); |
| 1084 | | 1084 | |
| 1085 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = | 1085 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = |
| 1086 | \\.globl _q1 | 1086 | \\.globl _q1 |
| 1087 | \\.globl _s1 | 1087 | \\.globl _s1 |
| 1088 | \\ | 1088 | \\ |
| 1089 | \\.align 4 | 1089 | \\.align 4 |
| 1090 | \\_q1: | 1090 | \\_q1: |
| 1091 | \\ adrp x8, L._q1@PAGE | 1091 | \\ adrp x8, L._q1@PAGE |
| 1092 | \\ ldr d0, [x8, L._q1@PAGEOFF] | 1092 | \\ ldr d0, [x8, L._q1@PAGEOFF] |
| 1093 | \\ ret | 1093 | \\ ret |
| 1094 | \\ | 1094 | \\ |
| 1095 | \\.section __TEXT,__cstring,cstring_literals | 1095 | \\.section __TEXT,__cstring,cstring_literals |
| 1096 | \\l._s1: | 1096 | \\l._s1: |
| 1097 | \\ .asciz "hello" | 1097 | \\ .asciz "hello" |
| 1098 | \\ | 1098 | \\ |
| 1099 | \\.section __TEXT,__literal8,8byte_literals | 1099 | \\.section __TEXT,__literal8,8byte_literals |
| 1100 | \\.align 8 | 1100 | \\.align 8 |
| 1101 | \\L._q1: | 1101 | \\L._q1: |
| 1102 | \\ .double 1.2345 | 1102 | \\ .double 1.2345 |
| 1103 | \\ | 1103 | \\ |
| 1104 | \\.section __DATA,__data | 1104 | \\.section __DATA,__data |
| 1105 | \\.align 8 | 1105 | \\.align 8 |
| 1106 | \\_s1: | 1106 | \\_s1: |
| 1107 | \\ .quad l._s1 | 1107 | \\ .quad l._s1 |
| 1108 | }); | 1108 | }); |
| 1109 | | 1109 | |
| 1110 | const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = | 1110 | const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = |
| 1111 | \\.globl _q2 | 1111 | \\.globl _q2 |
| 1112 | \\.globl _s2 | 1112 | \\.globl _s2 |
| 1113 | \\.globl _s3 | 1113 | \\.globl _s3 |
| 1114 | \\ | 1114 | \\ |
| 1115 | \\.align 4 | 1115 | \\.align 4 |
| 1116 | \\_q2: | 1116 | \\_q2: |
| 1117 | \\ adrp x8, L._q2@PAGE | 1117 | \\ adrp x8, L._q2@PAGE |
| 1118 | \\ ldr d0, [x8, L._q2@PAGEOFF] | 1118 | \\ ldr d0, [x8, L._q2@PAGEOFF] |
| 1119 | \\ ret | 1119 | \\ ret |
| 1120 | \\ | 1120 | \\ |
| 1121 | \\.section __TEXT,__cstring,cstring_literals | 1121 | \\.section __TEXT,__cstring,cstring_literals |
| 1122 | \\l._s2: | 1122 | \\l._s2: |
| 1123 | \\ .asciz "hello" | 1123 | \\ .asciz "hello" |
| 1124 | \\l._s3: | 1124 | \\l._s3: |
| 1125 | \\ .asciz "world" | 1125 | \\ .asciz "world" |
| 1126 | \\ | 1126 | \\ |
| 1127 | \\.section __TEXT,__literal8,8byte_literals | 1127 | \\.section __TEXT,__literal8,8byte_literals |
| 1128 | \\.align 8 | 1128 | \\.align 8 |
| 1129 | \\L._q2: | 1129 | \\L._q2: |
| 1130 | \\ .double 1.2345 | 1130 | \\ .double 1.2345 |
| 1131 | \\ | 1131 | \\ |
| 1132 | \\.section __DATA,__data | 1132 | \\.section __DATA,__data |
| 1133 | \\.align 8 | 1133 | \\.align 8 |
| 1134 | \\_s2: | 1134 | \\_s2: |
| 1135 | \\ .quad l._s2 | 1135 | \\ .quad l._s2 |
| 1136 | \\_s3: | 1136 | \\_s3: |
| 1137 | \\ .quad l._s3 | 1137 | \\ .quad l._s3 |
| 1138 | }); | 1138 | }); |
| 1139 | | 1139 | |
| 1140 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = | 1140 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = |
| 1141 | \\#include <stdio.h> | 1141 | \\#include <stdio.h> |
| 1142 | \\extern double q1(); | 1142 | \\extern double q1(); |
| 1143 | \\extern double q2(); | 1143 | \\extern double q2(); |
| 1144 | \\extern const char* s1; | 1144 | \\extern const char* s1; |
| 1145 | \\extern const char* s2; | 1145 | \\extern const char* s2; |
| 1146 | \\extern const char* s3; | 1146 | \\extern const char* s3; |
| 1147 | \\int main() { | 1147 | \\int main() { |
| 1148 | \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); | 1148 | \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); |
| 1149 | \\ return 0; | 1149 | \\ return 0; |
| 1150 | \\} | 1150 | \\} |
| 1151 | }); | 1151 | }); |
| 1152 | | 1152 | |
| 1153 | const runWithChecks = struct { | 1153 | const runWithChecks = struct { |
| ... | @@ -1203,59 +1203,59 @@ fn testMergeLiteralsArm642(b: *Build, opts: Options) *Step { | ... | @@ -1203,59 +1203,59 @@ fn testMergeLiteralsArm642(b: *Build, opts: Options) *Step { |
| 1203 | const test_step = addTestStep(b, "merge-literals-arm64-2", opts); | 1203 | const test_step = addTestStep(b, "merge-literals-arm64-2", opts); |
| 1204 | | 1204 | |
| 1205 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = | 1205 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = |
| 1206 | \\.globl _q1 | 1206 | \\.globl _q1 |
| 1207 | \\.globl _s1 | 1207 | \\.globl _s1 |
| 1208 | \\ | 1208 | \\ |
| 1209 | \\.align 4 | 1209 | \\.align 4 |
| 1210 | \\_q1: | 1210 | \\_q1: |
| 1211 | \\ adrp x0, L._q1@PAGE | 1211 | \\ adrp x0, L._q1@PAGE |
| 1212 | \\ ldr x0, [x0, L._q1@PAGEOFF] | 1212 | \\ ldr x0, [x0, L._q1@PAGEOFF] |
| 1213 | \\ ret | 1213 | \\ ret |
| 1214 | \\ | 1214 | \\ |
| 1215 | \\.section __TEXT,__cstring,cstring_literals | 1215 | \\.section __TEXT,__cstring,cstring_literals |
| 1216 | \\_s1: | 1216 | \\_s1: |
| 1217 | \\ .asciz "hello" | 1217 | \\ .asciz "hello" |
| 1218 | \\ | 1218 | \\ |
| 1219 | \\.section __TEXT,__literal8,8byte_literals | 1219 | \\.section __TEXT,__literal8,8byte_literals |
| 1220 | \\.align 8 | 1220 | \\.align 8 |
| 1221 | \\L._q1: | 1221 | \\L._q1: |
| 1222 | \\ .double 1.2345 | 1222 | \\ .double 1.2345 |
| 1223 | }); | 1223 | }); |
| 1224 | | 1224 | |
| 1225 | const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = | 1225 | const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = |
| 1226 | \\.globl _q2 | 1226 | \\.globl _q2 |
| 1227 | \\.globl _s2 | 1227 | \\.globl _s2 |
| 1228 | \\.globl _s3 | 1228 | \\.globl _s3 |
| 1229 | \\ | 1229 | \\ |
| 1230 | \\.align 4 | 1230 | \\.align 4 |
| 1231 | \\_q2: | 1231 | \\_q2: |
| 1232 | \\ adrp x0, L._q2@PAGE | 1232 | \\ adrp x0, L._q2@PAGE |
| 1233 | \\ ldr x0, [x0, L._q2@PAGEOFF] | 1233 | \\ ldr x0, [x0, L._q2@PAGEOFF] |
| 1234 | \\ ret | 1234 | \\ ret |
| 1235 | \\ | 1235 | \\ |
| 1236 | \\.section __TEXT,__cstring,cstring_literals | 1236 | \\.section __TEXT,__cstring,cstring_literals |
| 1237 | \\_s2: | 1237 | \\_s2: |
| 1238 | \\ .asciz "hello" | 1238 | \\ .asciz "hello" |
| 1239 | \\_s3: | 1239 | \\_s3: |
| 1240 | \\ .asciz "world" | 1240 | \\ .asciz "world" |
| 1241 | \\ | 1241 | \\ |
| 1242 | \\.section __TEXT,__literal8,8byte_literals | 1242 | \\.section __TEXT,__literal8,8byte_literals |
| 1243 | \\.align 8 | 1243 | \\.align 8 |
| 1244 | \\L._q2: | 1244 | \\L._q2: |
| 1245 | \\ .double 1.2345 | 1245 | \\ .double 1.2345 |
| 1246 | }); | 1246 | }); |
| 1247 | | 1247 | |
| 1248 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = | 1248 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = |
| 1249 | \\#include <stdio.h> | 1249 | \\#include <stdio.h> |
| 1250 | \\extern double q1(); | 1250 | \\extern double q1(); |
| 1251 | \\extern double q2(); | 1251 | \\extern double q2(); |
| 1252 | \\extern const char* s1; | 1252 | \\extern const char* s1; |
| 1253 | \\extern const char* s2; | 1253 | \\extern const char* s2; |
| 1254 | \\extern const char* s3; | 1254 | \\extern const char* s3; |
| 1255 | \\int main() { | 1255 | \\int main() { |
| 1256 | \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); | 1256 | \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); |
| 1257 | \\ return 0; | 1257 | \\ return 0; |
| 1258 | \\} | 1258 | \\} |
| 1259 | }); | 1259 | }); |
| 1260 | | 1260 | |
| 1261 | const exe = addExecutable(b, opts, .{ .name = "main1" }); | 1261 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| ... | @@ -1277,43 +1277,43 @@ fn testMergeLiteralsAlignment(b: *Build, opts: Options) *Step { | ... | @@ -1277,43 +1277,43 @@ fn testMergeLiteralsAlignment(b: *Build, opts: Options) *Step { |
| 1277 | const test_step = addTestStep(b, "merge-literals-alignment", opts); | 1277 | const test_step = addTestStep(b, "merge-literals-alignment", opts); |
| 1278 | | 1278 | |
| 1279 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = | 1279 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = |
| 1280 | \\.globl _s1 | 1280 | \\.globl _s1 |
| 1281 | \\.globl _s2 | 1281 | \\.globl _s2 |
| 1282 | \\ | 1282 | \\ |
| 1283 | \\.section __TEXT,__cstring,cstring_literals | 1283 | \\.section __TEXT,__cstring,cstring_literals |
| 1284 | \\.align 3 | 1284 | \\.align 3 |
| 1285 | \\_s1: | 1285 | \\_s1: |
| 1286 | \\ .asciz "str1" | 1286 | \\ .asciz "str1" |
| 1287 | \\_s2: | 1287 | \\_s2: |
| 1288 | \\ .asciz "str2" | 1288 | \\ .asciz "str2" |
| 1289 | }); | 1289 | }); |
| 1290 | | 1290 | |
| 1291 | const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = | 1291 | const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = |
| 1292 | \\.globl _s3 | 1292 | \\.globl _s3 |
| 1293 | \\.globl _s4 | 1293 | \\.globl _s4 |
| 1294 | \\ | 1294 | \\ |
| 1295 | \\.section __TEXT,__cstring,cstring_literals | 1295 | \\.section __TEXT,__cstring,cstring_literals |
| 1296 | \\.align 2 | 1296 | \\.align 2 |
| 1297 | \\_s3: | 1297 | \\_s3: |
| 1298 | \\ .asciz "str1" | 1298 | \\ .asciz "str1" |
| 1299 | \\_s4: | 1299 | \\_s4: |
| 1300 | \\ .asciz "str2" | 1300 | \\ .asciz "str2" |
| 1301 | }); | 1301 | }); |
| 1302 | | 1302 | |
| 1303 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = | 1303 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = |
| 1304 | \\#include <assert.h> | 1304 | \\#include <assert.h> |
| 1305 | \\#include <stdint.h> | 1305 | \\#include <stdint.h> |
| 1306 | \\#include <stdio.h> | 1306 | \\#include <stdio.h> |
| 1307 | \\extern const char* s1; | 1307 | \\extern const char* s1; |
| 1308 | \\extern const char* s2; | 1308 | \\extern const char* s2; |
| 1309 | \\extern const char* s3; | 1309 | \\extern const char* s3; |
| 1310 | \\extern const char* s4; | 1310 | \\extern const char* s4; |
| 1311 | \\int main() { | 1311 | \\int main() { |
| 1312 | \\ assert((uintptr_t)(&s1) % 8 == 0 && s1 == s3); | 1312 | \\ assert((uintptr_t)(&s1) % 8 == 0 && s1 == s3); |
| 1313 | \\ assert((uintptr_t)(&s2) % 8 == 0 && s2 == s4); | 1313 | \\ assert((uintptr_t)(&s2) % 8 == 0 && s2 == s4); |
| 1314 | \\ printf("%s%s%s%s", &s1, &s2, &s3, &s4); | 1314 | \\ printf("%s%s%s%s", &s1, &s2, &s3, &s4); |
| 1315 | \\ return 0; | 1315 | \\ return 0; |
| 1316 | \\} | 1316 | \\} |
| 1317 | , .c_source_flags = &.{"-Wno-format"} }); | 1317 | , .c_source_flags = &.{"-Wno-format"} }); |
| 1318 | | 1318 | |
| 1319 | const runWithChecks = struct { | 1319 | const runWithChecks = struct { |
| ... | @@ -1356,39 +1356,39 @@ fn testMergeLiteralsObjc(b: *Build, opts: Options) *Step { | ... | @@ -1356,39 +1356,39 @@ fn testMergeLiteralsObjc(b: *Build, opts: Options) *Step { |
| 1356 | const test_step = addTestStep(b, "merge-literals-objc", opts); | 1356 | const test_step = addTestStep(b, "merge-literals-objc", opts); |
| 1357 | | 1357 | |
| 1358 | const main_o = addObject(b, opts, .{ .name = "main", .objc_source_bytes = | 1358 | const main_o = addObject(b, opts, .{ .name = "main", .objc_source_bytes = |
| 1359 | \\#import <Foundation/Foundation.h>; | 1359 | \\#import <Foundation/Foundation.h>; |
| 1360 | \\ | 1360 | \\ |
| 1361 | \\extern void foo(); | 1361 | \\extern void foo(); |
| 1362 | \\ | 1362 | \\ |
| 1363 | \\int main() { | 1363 | \\int main() { |
| 1364 | \\ NSString *thing = @"aaa"; | 1364 | \\ NSString *thing = @"aaa"; |
| 1365 | \\ | 1365 | \\ |
| 1366 | \\ SEL sel = @selector(lowercaseString); | 1366 | \\ SEL sel = @selector(lowercaseString); |
| 1367 | \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO"); | 1367 | \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO"); |
| 1368 | \\ NSLog (@"Responds to lowercaseString: %@", lower); | 1368 | \\ NSLog (@"Responds to lowercaseString: %@", lower); |
| 1369 | \\ if ([thing respondsToSelector:sel]) //(lower == @"YES") | 1369 | \\ if ([thing respondsToSelector:sel]) //(lower == @"YES") |
| 1370 | \\ NSLog(@"lowercaseString is: %@", [thing lowercaseString]); | 1370 | \\ NSLog(@"lowercaseString is: %@", [thing lowercaseString]); |
| 1371 | \\ | 1371 | \\ |
| 1372 | \\ foo(); | 1372 | \\ foo(); |
| 1373 | \\} | 1373 | \\} |
| 1374 | }); | 1374 | }); |
| 1375 | | 1375 | |
| 1376 | const a_o = addObject(b, opts, .{ .name = "a", .objc_source_bytes = | 1376 | const a_o = addObject(b, opts, .{ .name = "a", .objc_source_bytes = |
| 1377 | \\#import <Foundation/Foundation.h>; | 1377 | \\#import <Foundation/Foundation.h>; |
| 1378 | \\ | 1378 | \\ |
| 1379 | \\void foo() { | 1379 | \\void foo() { |
| 1380 | \\ NSString *thing = @"aaa"; | 1380 | \\ NSString *thing = @"aaa"; |
| 1381 | \\ SEL sel = @selector(lowercaseString); | 1381 | \\ SEL sel = @selector(lowercaseString); |
| 1382 | \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO"); | 1382 | \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO"); |
| 1383 | \\ NSLog (@"Responds to lowercaseString in foo(): %@", lower); | 1383 | \\ NSLog (@"Responds to lowercaseString in foo(): %@", lower); |
| 1384 | \\ if ([thing respondsToSelector:sel]) //(lower == @"YES") | 1384 | \\ if ([thing respondsToSelector:sel]) //(lower == @"YES") |
| 1385 | \\ NSLog(@"lowercaseString in foo() is: %@", [thing lowercaseString]); | 1385 | \\ NSLog(@"lowercaseString in foo() is: %@", [thing lowercaseString]); |
| 1386 | \\ SEL sel2 = @selector(uppercaseString); | 1386 | \\ SEL sel2 = @selector(uppercaseString); |
| 1387 | \\ NSString *upper = (([thing respondsToSelector:sel2]) ? @"YES" : @"NO"); | 1387 | \\ NSString *upper = (([thing respondsToSelector:sel2]) ? @"YES" : @"NO"); |
| 1388 | \\ NSLog (@"Responds to uppercaseString in foo(): %@", upper); | 1388 | \\ NSLog (@"Responds to uppercaseString in foo(): %@", upper); |
| 1389 | \\ if ([thing respondsToSelector:sel2]) //(upper == @"YES") | 1389 | \\ if ([thing respondsToSelector:sel2]) //(upper == @"YES") |
| 1390 | \\ NSLog(@"uppercaseString in foo() is: %@", [thing uppercaseString]); | 1390 | \\ NSLog(@"uppercaseString in foo() is: %@", [thing uppercaseString]); |
| 1391 | \\} | 1391 | \\} |
| 1392 | }); | 1392 | }); |
| 1393 | | 1393 | |
| 1394 | const runWithChecks = struct { | 1394 | const runWithChecks = struct { |
| ... | @@ -1459,12 +1459,12 @@ fn testNoDeadStrip(b: *Build, opts: Options) *Step { | ... | @@ -1459,12 +1459,12 @@ fn testNoDeadStrip(b: *Build, opts: Options) *Step { |
| 1459 | const test_step = addTestStep(b, "no-dead-strip", opts); | 1459 | const test_step = addTestStep(b, "no-dead-strip", opts); |
| 1460 | | 1460 | |
| 1461 | const exe = addExecutable(b, opts, .{ .name = "name", .c_source_bytes = | 1461 | const exe = addExecutable(b, opts, .{ .name = "name", .c_source_bytes = |
| 1462 | \\__attribute__((used)) int bogus1 = 0; | 1462 | \\__attribute__((used)) int bogus1 = 0; |
| 1463 | \\int bogus2 = 0; | 1463 | \\int bogus2 = 0; |
| 1464 | \\int foo = 42; | 1464 | \\int foo = 42; |
| 1465 | \\int main() { | 1465 | \\int main() { |
| 1466 | \\ return foo - 42; | 1466 | \\ return foo - 42; |
| 1467 | \\} | 1467 | \\} |
| 1468 | }); | 1468 | }); |
| 1469 | exe.link_gc_sections = true; | 1469 | exe.link_gc_sections = true; |
| 1470 | | 1470 | |
| ... | @@ -1543,11 +1543,11 @@ fn testObjc(b: *Build, opts: Options) *Step { | ... | @@ -1543,11 +1543,11 @@ fn testObjc(b: *Build, opts: Options) *Step { |
| 1543 | const test_step = addTestStep(b, "objc", opts); | 1543 | const test_step = addTestStep(b, "objc", opts); |
| 1544 | | 1544 | |
| 1545 | const lib = addStaticLibrary(b, opts, .{ .name = "a", .objc_source_bytes = | 1545 | const lib = addStaticLibrary(b, opts, .{ .name = "a", .objc_source_bytes = |
| 1546 | \\#import <Foundation/Foundation.h> | 1546 | \\#import <Foundation/Foundation.h> |
| 1547 | \\@interface Foo : NSObject | 1547 | \\@interface Foo : NSObject |
| 1548 | \\@end | 1548 | \\@end |
| 1549 | \\@implementation Foo | 1549 | \\@implementation Foo |
| 1550 | \\@end | 1550 | \\@end |
| 1551 | }); | 1551 | }); |
| 1552 | | 1552 | |
| 1553 | { | 1553 | { |
| ... | @@ -1600,32 +1600,32 @@ fn testObjcpp(b: *Build, opts: Options) *Step { | ... | @@ -1600,32 +1600,32 @@ fn testObjcpp(b: *Build, opts: Options) *Step { |
| 1600 | }; | 1600 | }; |
| 1601 | | 1601 | |
| 1602 | const foo_o = addObject(b, opts, .{ .name = "foo", .objcpp_source_bytes = | 1602 | const foo_o = addObject(b, opts, .{ .name = "foo", .objcpp_source_bytes = |
| 1603 | \\#import "Foo.h" | 1603 | \\#import "Foo.h" |
| 1604 | \\@implementation Foo | 1604 | \\@implementation Foo |
| 1605 | \\- (NSString *)name | 1605 | \\- (NSString *)name |
| 1606 | \\{ | 1606 | \\{ |
| 1607 | \\ NSString *str = [[NSString alloc] initWithFormat:@"Zig"]; | 1607 | \\ NSString *str = [[NSString alloc] initWithFormat:@"Zig"]; |
| 1608 | \\ return str; | 1608 | \\ return str; |
| 1609 | \\} | 1609 | \\} |
| 1610 | \\@end | 1610 | \\@end |
| 1611 | }); | 1611 | }); |
| 1612 | foo_o.root_module.addIncludePath(foo_h.dirname()); | 1612 | foo_o.root_module.addIncludePath(foo_h.dirname()); |
| 1613 | foo_o.linkLibCpp(); | 1613 | foo_o.linkLibCpp(); |
| 1614 | | 1614 | |
| 1615 | const exe = addExecutable(b, opts, .{ .name = "main", .objcpp_source_bytes = | 1615 | const exe = addExecutable(b, opts, .{ .name = "main", .objcpp_source_bytes = |
| 1616 | \\#import "Foo.h" | 1616 | \\#import "Foo.h" |
| 1617 | \\#import <assert.h> | 1617 | \\#import <assert.h> |
| 1618 | \\#include <iostream> | 1618 | \\#include <iostream> |
| 1619 | \\int main(int argc, char *argv[]) | 1619 | \\int main(int argc, char *argv[]) |
| 1620 | \\{ | 1620 | \\{ |
| 1621 | \\ @autoreleasepool { | 1621 | \\ @autoreleasepool { |
| 1622 | \\ Foo *foo = [[Foo alloc] init]; | 1622 | \\ Foo *foo = [[Foo alloc] init]; |
| 1623 | \\ NSString *result = [foo name]; | 1623 | \\ NSString *result = [foo name]; |
| 1624 | \\ std::cout << "Hello from C++ and " << [result UTF8String]; | 1624 | \\ std::cout << "Hello from C++ and " << [result UTF8String]; |
| 1625 | \\ assert([result isEqualToString:@"Zig"]); | 1625 | \\ assert([result isEqualToString:@"Zig"]); |
| 1626 | \\ return 0; | 1626 | \\ return 0; |
| 1627 | \\ } | 1627 | \\ } |
| 1628 | \\} | 1628 | \\} |
| 1629 | }); | 1629 | }); |
| 1630 | exe.root_module.addIncludePath(foo_h.dirname()); | 1630 | exe.root_module.addIncludePath(foo_h.dirname()); |
| 1631 | exe.addObject(foo_o); | 1631 | exe.addObject(foo_o); |
| ... | @@ -1677,21 +1677,21 @@ fn testReexportsZig(b: *Build, opts: Options) *Step { | ... | @@ -1677,21 +1677,21 @@ fn testReexportsZig(b: *Build, opts: Options) *Step { |
| 1677 | const test_step = addTestStep(b, "reexports-zig", opts); | 1677 | const test_step = addTestStep(b, "reexports-zig", opts); |
| 1678 | | 1678 | |
| 1679 | const lib = addStaticLibrary(b, opts, .{ .name = "a", .zig_source_bytes = | 1679 | const lib = addStaticLibrary(b, opts, .{ .name = "a", .zig_source_bytes = |
| 1680 | \\const x: i32 = 42; | 1680 | \\const x: i32 = 42; |
| 1681 | \\export fn foo() i32 { | 1681 | \\export fn foo() i32 { |
| 1682 | \\ return x; | 1682 | \\ return x; |
| 1683 | \\} | 1683 | \\} |
| 1684 | \\comptime { | 1684 | \\comptime { |
| 1685 | \\ @export(&foo, .{ .name = "bar", .linkage = .strong }); | 1685 | \\ @export(&foo, .{ .name = "bar", .linkage = .strong }); |
| 1686 | \\} | 1686 | \\} |
| 1687 | }); | 1687 | }); |
| 1688 | | 1688 | |
| 1689 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 1689 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 1690 | \\extern int foo(); | 1690 | \\extern int foo(); |
| 1691 | \\extern int bar(); | 1691 | \\extern int bar(); |
| 1692 | \\int main() { | 1692 | \\int main() { |
| 1693 | \\ return bar() - foo(); | 1693 | \\ return bar() - foo(); |
| 1694 | \\} | 1694 | \\} |
| 1695 | }); | 1695 | }); |
| 1696 | exe.linkLibrary(lib); | 1696 | exe.linkLibrary(lib); |
| 1697 | | 1697 | |
| ... | @@ -1706,32 +1706,32 @@ fn testRelocatable(b: *Build, opts: Options) *Step { | ... | @@ -1706,32 +1706,32 @@ fn testRelocatable(b: *Build, opts: Options) *Step { |
| 1706 | const test_step = addTestStep(b, "relocatable", opts); | 1706 | const test_step = addTestStep(b, "relocatable", opts); |
| 1707 | | 1707 | |
| 1708 | const a_o = addObject(b, opts, .{ .name = "a", .cpp_source_bytes = | 1708 | const a_o = addObject(b, opts, .{ .name = "a", .cpp_source_bytes = |
| 1709 | \\#include <stdexcept> | 1709 | \\#include <stdexcept> |
| 1710 | \\int try_me() { | 1710 | \\int try_me() { |
| 1711 | \\ throw std::runtime_error("Oh no!"); | 1711 | \\ throw std::runtime_error("Oh no!"); |
| 1712 | \\} | 1712 | \\} |
| 1713 | }); | 1713 | }); |
| 1714 | a_o.linkLibCpp(); | 1714 | a_o.linkLibCpp(); |
| 1715 | | 1715 | |
| 1716 | const b_o = addObject(b, opts, .{ .name = "b", .cpp_source_bytes = | 1716 | const b_o = addObject(b, opts, .{ .name = "b", .cpp_source_bytes = |
| 1717 | \\extern int try_me(); | 1717 | \\extern int try_me(); |
| 1718 | \\int try_again() { | 1718 | \\int try_again() { |
| 1719 | \\ return try_me(); | 1719 | \\ return try_me(); |
| 1720 | \\} | 1720 | \\} |
| 1721 | }); | 1721 | }); |
| 1722 | | 1722 | |
| 1723 | const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes = | 1723 | const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes = |
| 1724 | \\#include <iostream> | 1724 | \\#include <iostream> |
| 1725 | \\#include <stdexcept> | 1725 | \\#include <stdexcept> |
| 1726 | \\extern int try_again(); | 1726 | \\extern int try_again(); |
| 1727 | \\int main() { | 1727 | \\int main() { |
| 1728 | \\ try { | 1728 | \\ try { |
| 1729 | \\ try_again(); | 1729 | \\ try_again(); |
| 1730 | \\ } catch (const std::exception &e) { | 1730 | \\ } catch (const std::exception &e) { |
| 1731 | \\ std::cout << "exception=" << e.what(); | 1731 | \\ std::cout << "exception=" << e.what(); |
| 1732 | \\ } | 1732 | \\ } |
| 1733 | \\ return 0; | 1733 | \\ return 0; |
| 1734 | \\} | 1734 | \\} |
| 1735 | }); | 1735 | }); |
| 1736 | main_o.linkLibCpp(); | 1736 | main_o.linkLibCpp(); |
| 1737 | | 1737 | |
| ... | @@ -1774,34 +1774,34 @@ fn testRelocatableZig(b: *Build, opts: Options) *Step { | ... | @@ -1774,34 +1774,34 @@ fn testRelocatableZig(b: *Build, opts: Options) *Step { |
| 1774 | const test_step = addTestStep(b, "relocatable-zig", opts); | 1774 | const test_step = addTestStep(b, "relocatable-zig", opts); |
| 1775 | | 1775 | |
| 1776 | const a_o = addObject(b, opts, .{ .name = "a", .zig_source_bytes = | 1776 | const a_o = addObject(b, opts, .{ .name = "a", .zig_source_bytes = |
| 1777 | \\const std = @import("std"); | 1777 | \\const std = @import("std"); |
| 1778 | \\export var foo: i32 = 0; | 1778 | \\export var foo: i32 = 0; |
| 1779 | \\export fn incrFoo() void { | 1779 | \\export fn incrFoo() void { |
| 1780 | \\ foo += 1; | 1780 | \\ foo += 1; |
| 1781 | \\ std.debug.print("incrFoo={d}\n", .{foo}); | 1781 | \\ std.debug.print("incrFoo={d}\n", .{foo}); |
| 1782 | \\} | 1782 | \\} |
| 1783 | }); | 1783 | }); |
| 1784 | | 1784 | |
| 1785 | const b_o = addObject(b, opts, .{ .name = "b", .zig_source_bytes = | 1785 | const b_o = addObject(b, opts, .{ .name = "b", .zig_source_bytes = |
| 1786 | \\const std = @import("std"); | 1786 | \\const std = @import("std"); |
| 1787 | \\extern var foo: i32; | 1787 | \\extern var foo: i32; |
| 1788 | \\export fn decrFoo() void { | 1788 | \\export fn decrFoo() void { |
| 1789 | \\ foo -= 1; | 1789 | \\ foo -= 1; |
| 1790 | \\ std.debug.print("decrFoo={d}\n", .{foo}); | 1790 | \\ std.debug.print("decrFoo={d}\n", .{foo}); |
| 1791 | \\} | 1791 | \\} |
| 1792 | }); | 1792 | }); |
| 1793 | | 1793 | |
| 1794 | const main_o = addObject(b, opts, .{ .name = "main", .zig_source_bytes = | 1794 | const main_o = addObject(b, opts, .{ .name = "main", .zig_source_bytes = |
| 1795 | \\const std = @import("std"); | 1795 | \\const std = @import("std"); |
| 1796 | \\extern var foo: i32; | 1796 | \\extern var foo: i32; |
| 1797 | \\extern fn incrFoo() void; | 1797 | \\extern fn incrFoo() void; |
| 1798 | \\extern fn decrFoo() void; | 1798 | \\extern fn decrFoo() void; |
| 1799 | \\pub fn main() void { | 1799 | \\pub fn main() void { |
| 1800 | \\ const init = foo; | 1800 | \\ const init = foo; |
| 1801 | \\ incrFoo(); | 1801 | \\ incrFoo(); |
| 1802 | \\ decrFoo(); | 1802 | \\ decrFoo(); |
| 1803 | \\ if (init == foo) @panic("Oh no!"); | 1803 | \\ if (init == foo) @panic("Oh no!"); |
| 1804 | \\} | 1804 | \\} |
| 1805 | }); | 1805 | }); |
| 1806 | | 1806 | |
| 1807 | const c_o = addObject(b, opts, .{ .name = "c" }); | 1807 | const c_o = addObject(b, opts, .{ .name = "c" }); |
| ... | @@ -1825,11 +1825,11 @@ fn testSearchStrategy(b: *Build, opts: Options) *Step { | ... | @@ -1825,11 +1825,11 @@ fn testSearchStrategy(b: *Build, opts: Options) *Step { |
| 1825 | const test_step = addTestStep(b, "search-strategy", opts); | 1825 | const test_step = addTestStep(b, "search-strategy", opts); |
| 1826 | | 1826 | |
| 1827 | const obj = addObject(b, opts, .{ .name = "a", .c_source_bytes = | 1827 | const obj = addObject(b, opts, .{ .name = "a", .c_source_bytes = |
| 1828 | \\#include<stdio.h> | 1828 | \\#include<stdio.h> |
| 1829 | \\char world[] = "world"; | 1829 | \\char world[] = "world"; |
| 1830 | \\char* hello() { | 1830 | \\char* hello() { |
| 1831 | \\ return "Hello"; | 1831 | \\ return "Hello"; |
| 1832 | \\} | 1832 | \\} |
| 1833 | }); | 1833 | }); |
| 1834 | | 1834 | |
| 1835 | const liba = addStaticLibrary(b, opts, .{ .name = "a" }); | 1835 | const liba = addStaticLibrary(b, opts, .{ .name = "a" }); |
| ... | @@ -1839,13 +1839,13 @@ fn testSearchStrategy(b: *Build, opts: Options) *Step { | ... | @@ -1839,13 +1839,13 @@ fn testSearchStrategy(b: *Build, opts: Options) *Step { |
| 1839 | dylib.addObject(obj); | 1839 | dylib.addObject(obj); |
| 1840 | | 1840 | |
| 1841 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = | 1841 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = |
| 1842 | \\#include<stdio.h> | 1842 | \\#include<stdio.h> |
| 1843 | \\char* hello(); | 1843 | \\char* hello(); |
| 1844 | \\extern char world[]; | 1844 | \\extern char world[]; |
| 1845 | \\int main() { | 1845 | \\int main() { |
| 1846 | \\ printf("%s %s", hello(), world); | 1846 | \\ printf("%s %s", hello(), world); |
| 1847 | \\ return 0; | 1847 | \\ return 0; |
| 1848 | \\} | 1848 | \\} |
| 1849 | }); | 1849 | }); |
| 1850 | | 1850 | |
| 1851 | { | 1851 | { |
| ... | @@ -1973,23 +1973,23 @@ fn testSectionBoundarySymbols2(b: *Build, opts: Options) *Step { | ... | @@ -1973,23 +1973,23 @@ fn testSectionBoundarySymbols2(b: *Build, opts: Options) *Step { |
| 1973 | const test_step = addTestStep(b, "section-boundary-symbols-2", opts); | 1973 | const test_step = addTestStep(b, "section-boundary-symbols-2", opts); |
| 1974 | | 1974 | |
| 1975 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 1975 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 1976 | \\#include <stdio.h> | 1976 | \\#include <stdio.h> |
| 1977 | \\struct pair { int a; int b; }; | 1977 | \\struct pair { int a; int b; }; |
| 1978 | \\struct pair first __attribute__((section("__DATA,__pairs"))) = { 1, 2 }; | 1978 | \\struct pair first __attribute__((section("__DATA,__pairs"))) = { 1, 2 }; |
| 1979 | \\struct pair second __attribute__((section("__DATA,__pairs"))) = { 3, 4 }; | 1979 | \\struct pair second __attribute__((section("__DATA,__pairs"))) = { 3, 4 }; |
| 1980 | \\extern struct pair pairs_start __asm("section$start$__DATA$__pairs"); | 1980 | \\extern struct pair pairs_start __asm("section$start$__DATA$__pairs"); |
| 1981 | \\extern struct pair pairs_end __asm("section$end$__DATA$__pairs"); | 1981 | \\extern struct pair pairs_end __asm("section$end$__DATA$__pairs"); |
| 1982 | \\int main() { | 1982 | \\int main() { |
| 1983 | \\ printf("%d,%d\n", first.a, first.b); | 1983 | \\ printf("%d,%d\n", first.a, first.b); |
| 1984 | \\ printf("%d,%d\n", second.a, second.b); | 1984 | \\ printf("%d,%d\n", second.a, second.b); |
| 1985 | \\ struct pair* p; | 1985 | \\ struct pair* p; |
| 1986 | \\ for (p = &pairs_start; p < &pairs_end; p++) { | 1986 | \\ for (p = &pairs_start; p < &pairs_end; p++) { |
| 1987 | \\ p->a = 0; | 1987 | \\ p->a = 0; |
| 1988 | \\ } | 1988 | \\ } |
| 1989 | \\ printf("%d,%d\n", first.a, first.b); | 1989 | \\ printf("%d,%d\n", first.a, first.b); |
| 1990 | \\ printf("%d,%d\n", second.a, second.b); | 1990 | \\ printf("%d,%d\n", second.a, second.b); |
| 1991 | \\ return 0; | 1991 | \\ return 0; |
| 1992 | \\} | 1992 | \\} |
| 1993 | }); | 1993 | }); |
| 1994 | | 1994 | |
| 1995 | const run = b.addRunArtifact(exe); | 1995 | const run = b.addRunArtifact(exe); |
| ... | @@ -2010,24 +2010,24 @@ fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step { | ... | @@ -2010,24 +2010,24 @@ fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step { |
| 2010 | const test_step = addTestStep(b, "segment-boundary-symbols", opts); | 2010 | const test_step = addTestStep(b, "segment-boundary-symbols", opts); |
| 2011 | | 2011 | |
| 2012 | const obj1 = addObject(b, opts, .{ .name = "a", .cpp_source_bytes = | 2012 | const obj1 = addObject(b, opts, .{ .name = "a", .cpp_source_bytes = |
| 2013 | \\constexpr const char* MESSAGE __attribute__((used, section("__DATA_CONST_1,__message_ptr"))) = "codebase"; | 2013 | \\constexpr const char* MESSAGE __attribute__((used, section("__DATA_CONST_1,__message_ptr"))) = "codebase"; |
| 2014 | }); | 2014 | }); |
| 2015 | | 2015 | |
| 2016 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = | 2016 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = |
| 2017 | \\#include <stdio.h> | 2017 | \\#include <stdio.h> |
| 2018 | \\const char* interop(); | 2018 | \\const char* interop(); |
| 2019 | \\int main() { | 2019 | \\int main() { |
| 2020 | \\ printf("All your %s are belong to us.\n", interop()); | 2020 | \\ printf("All your %s are belong to us.\n", interop()); |
| 2021 | \\ return 0; | 2021 | \\ return 0; |
| 2022 | \\} | 2022 | \\} |
| 2023 | }); | 2023 | }); |
| 2024 | | 2024 | |
| 2025 | { | 2025 | { |
| 2026 | const obj2 = addObject(b, opts, .{ .name = "b", .cpp_source_bytes = | 2026 | const obj2 = addObject(b, opts, .{ .name = "b", .cpp_source_bytes = |
| 2027 | \\extern const char* message_pointer __asm("segment$start$__DATA_CONST_1"); | 2027 | \\extern const char* message_pointer __asm("segment$start$__DATA_CONST_1"); |
| 2028 | \\extern "C" const char* interop() { | 2028 | \\extern "C" const char* interop() { |
| 2029 | \\ return message_pointer; | 2029 | \\ return message_pointer; |
| 2030 | \\} | 2030 | \\} |
| 2031 | }); | 2031 | }); |
| 2032 | | 2032 | |
| 2033 | const exe = addExecutable(b, opts, .{ .name = "main" }); | 2033 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| ... | @@ -2047,10 +2047,10 @@ fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step { | ... | @@ -2047,10 +2047,10 @@ fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step { |
| 2047 | | 2047 | |
| 2048 | { | 2048 | { |
| 2049 | const obj2 = addObject(b, opts, .{ .name = "c", .cpp_source_bytes = | 2049 | const obj2 = addObject(b, opts, .{ .name = "c", .cpp_source_bytes = |
| 2050 | \\extern const char* message_pointer __asm("segment$start$__DATA_1"); | 2050 | \\extern const char* message_pointer __asm("segment$start$__DATA_1"); |
| 2051 | \\extern "C" const char* interop() { | 2051 | \\extern "C" const char* interop() { |
| 2052 | \\ return message_pointer; | 2052 | \\ return message_pointer; |
| 2053 | \\} | 2053 | \\} |
| 2054 | }); | 2054 | }); |
| 2055 | | 2055 | |
| 2056 | const exe = addExecutable(b, opts, .{ .name = "main2" }); | 2056 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| ... | @@ -2078,27 +2078,27 @@ fn testSymbolStabs(b: *Build, opts: Options) *Step { | ... | @@ -2078,27 +2078,27 @@ fn testSymbolStabs(b: *Build, opts: Options) *Step { |
| 2078 | const test_step = addTestStep(b, "symbol-stabs", opts); | 2078 | const test_step = addTestStep(b, "symbol-stabs", opts); |
| 2079 | | 2079 | |
| 2080 | const a_o = addObject(b, opts, .{ .name = "a", .c_source_bytes = | 2080 | const a_o = addObject(b, opts, .{ .name = "a", .c_source_bytes = |
| 2081 | \\int foo = 42; | 2081 | \\int foo = 42; |
| 2082 | \\int getFoo() { | 2082 | \\int getFoo() { |
| 2083 | \\ return foo; | 2083 | \\ return foo; |
| 2084 | \\} | 2084 | \\} |
| 2085 | }); | 2085 | }); |
| 2086 | | 2086 | |
| 2087 | const b_o = addObject(b, opts, .{ .name = "b", .c_source_bytes = | 2087 | const b_o = addObject(b, opts, .{ .name = "b", .c_source_bytes = |
| 2088 | \\int bar = 24; | 2088 | \\int bar = 24; |
| 2089 | \\int getBar() { | 2089 | \\int getBar() { |
| 2090 | \\ return bar; | 2090 | \\ return bar; |
| 2091 | \\} | 2091 | \\} |
| 2092 | }); | 2092 | }); |
| 2093 | | 2093 | |
| 2094 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = | 2094 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = |
| 2095 | \\#include <stdio.h> | 2095 | \\#include <stdio.h> |
| 2096 | \\extern int getFoo(); | 2096 | \\extern int getFoo(); |
| 2097 | \\extern int getBar(); | 2097 | \\extern int getBar(); |
| 2098 | \\int main() { | 2098 | \\int main() { |
| 2099 | \\ printf("foo=%d,bar=%d", getFoo(), getBar()); | 2099 | \\ printf("foo=%d,bar=%d", getFoo(), getBar()); |
| 2100 | \\ return 0; | 2100 | \\ return 0; |
| 2101 | \\} | 2101 | \\} |
| 2102 | }); | 2102 | }); |
| 2103 | | 2103 | |
| 2104 | const exe = addExecutable(b, opts, .{ .name = "main" }); | 2104 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| ... | @@ -2162,11 +2162,11 @@ fn testTbdv3(b: *Build, opts: Options) *Step { | ... | @@ -2162,11 +2162,11 @@ fn testTbdv3(b: *Build, opts: Options) *Step { |
| 2162 | }; | 2162 | }; |
| 2163 | | 2163 | |
| 2164 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 2164 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 2165 | \\#include <stdio.h> | 2165 | \\#include <stdio.h> |
| 2166 | \\int getFoo(); | 2166 | \\int getFoo(); |
| 2167 | \\int main() { | 2167 | \\int main() { |
| 2168 | \\ return getFoo() - 42; | 2168 | \\ return getFoo() - 42; |
| 2169 | \\} | 2169 | \\} |
| 2170 | }); | 2170 | }); |
| 2171 | exe.root_module.linkSystemLibrary("a", .{}); | 2171 | exe.root_module.linkSystemLibrary("a", .{}); |
| 2172 | exe.root_module.addLibraryPath(tbd.dirname()); | 2172 | exe.root_module.addLibraryPath(tbd.dirname()); |
| ... | @@ -2209,18 +2209,18 @@ fn testThunks(b: *Build, opts: Options) *Step { | ... | @@ -2209,18 +2209,18 @@ fn testThunks(b: *Build, opts: Options) *Step { |
| 2209 | const test_step = addTestStep(b, "thunks", opts); | 2209 | const test_step = addTestStep(b, "thunks", opts); |
| 2210 | | 2210 | |
| 2211 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 2211 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 2212 | \\#include <stdio.h> | 2212 | \\#include <stdio.h> |
| 2213 | \\void bar() { | 2213 | \\void bar() { |
| 2214 | \\ printf("bar"); | 2214 | \\ printf("bar"); |
| 2215 | \\} | 2215 | \\} |
| 2216 | \\void foo() { | 2216 | \\void foo() { |
| 2217 | \\ fprintf(stdout, "foo"); | 2217 | \\ fprintf(stdout, "foo"); |
| 2218 | \\} | 2218 | \\} |
| 2219 | \\int main() { | 2219 | \\int main() { |
| 2220 | \\ foo(); | 2220 | \\ foo(); |
| 2221 | \\ bar(); | 2221 | \\ bar(); |
| 2222 | \\ return 0; | 2222 | \\ return 0; |
| 2223 | \\} | 2223 | \\} |
| 2224 | }); | 2224 | }); |
| 2225 | | 2225 | |
| 2226 | const check = exe.checkObject(); | 2226 | const check = exe.checkObject(); |
| ... | @@ -2241,24 +2241,24 @@ fn testTls(b: *Build, opts: Options) *Step { | ... | @@ -2241,24 +2241,24 @@ fn testTls(b: *Build, opts: Options) *Step { |
| 2241 | const test_step = addTestStep(b, "tls", opts); | 2241 | const test_step = addTestStep(b, "tls", opts); |
| 2242 | | 2242 | |
| 2243 | const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = | 2243 | const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = |
| 2244 | \\_Thread_local int a; | 2244 | \\_Thread_local int a; |
| 2245 | \\int getA() { | 2245 | \\int getA() { |
| 2246 | \\ return a; | 2246 | \\ return a; |
| 2247 | \\} | 2247 | \\} |
| 2248 | }); | 2248 | }); |
| 2249 | | 2249 | |
| 2250 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 2250 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 2251 | \\#include<stdio.h> | 2251 | \\#include<stdio.h> |
| 2252 | \\extern _Thread_local int a; | 2252 | \\extern _Thread_local int a; |
| 2253 | \\extern int getA(); | 2253 | \\extern int getA(); |
| 2254 | \\int getA2() { | 2254 | \\int getA2() { |
| 2255 | \\ return a; | 2255 | \\ return a; |
| 2256 | \\} | 2256 | \\} |
| 2257 | \\int main() { | 2257 | \\int main() { |
| 2258 | \\ a = 2; | 2258 | \\ a = 2; |
| 2259 | \\ printf("%d %d %d", a, getA(), getA2()); | 2259 | \\ printf("%d %d %d", a, getA(), getA2()); |
| 2260 | \\ return 0; | 2260 | \\ return 0; |
| 2261 | \\} | 2261 | \\} |
| 2262 | }); | 2262 | }); |
| 2263 | exe.root_module.linkSystemLibrary("a", .{}); | 2263 | exe.root_module.linkSystemLibrary("a", .{}); |
| 2264 | exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory()); | 2264 | exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory()); |
| ... | @@ -2292,33 +2292,33 @@ fn testTlsPointers(b: *Build, opts: Options) *Step { | ... | @@ -2292,33 +2292,33 @@ fn testTlsPointers(b: *Build, opts: Options) *Step { |
| 2292 | }; | 2292 | }; |
| 2293 | | 2293 | |
| 2294 | const bar_o = addObject(b, opts, .{ .name = "bar", .cpp_source_bytes = | 2294 | const bar_o = addObject(b, opts, .{ .name = "bar", .cpp_source_bytes = |
| 2295 | \\#include "foo.h" | 2295 | \\#include "foo.h" |
| 2296 | \\int bar() { | 2296 | \\int bar() { |
| 2297 | \\ int v1 = Foo<int>::getVar(); | 2297 | \\ int v1 = Foo<int>::getVar(); |
| 2298 | \\ return v1; | 2298 | \\ return v1; |
| 2299 | \\} | 2299 | \\} |
| 2300 | }); | 2300 | }); |
| 2301 | bar_o.root_module.addIncludePath(foo_h.dirname()); | 2301 | bar_o.root_module.addIncludePath(foo_h.dirname()); |
| 2302 | bar_o.linkLibCpp(); | 2302 | bar_o.linkLibCpp(); |
| 2303 | | 2303 | |
| 2304 | const baz_o = addObject(b, opts, .{ .name = "baz", .cpp_source_bytes = | 2304 | const baz_o = addObject(b, opts, .{ .name = "baz", .cpp_source_bytes = |
| 2305 | \\#include "foo.h" | 2305 | \\#include "foo.h" |
| 2306 | \\int baz() { | 2306 | \\int baz() { |
| 2307 | \\ int v1 = Foo<unsigned>::getVar(); | 2307 | \\ int v1 = Foo<unsigned>::getVar(); |
| 2308 | \\ return v1; | 2308 | \\ return v1; |
| 2309 | \\} | 2309 | \\} |
| 2310 | }); | 2310 | }); |
| 2311 | baz_o.root_module.addIncludePath(foo_h.dirname()); | 2311 | baz_o.root_module.addIncludePath(foo_h.dirname()); |
| 2312 | baz_o.linkLibCpp(); | 2312 | baz_o.linkLibCpp(); |
| 2313 | | 2313 | |
| 2314 | const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes = | 2314 | const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes = |
| 2315 | \\extern int bar(); | 2315 | \\extern int bar(); |
| 2316 | \\extern int baz(); | 2316 | \\extern int baz(); |
| 2317 | \\int main() { | 2317 | \\int main() { |
| 2318 | \\ int v1 = bar(); | 2318 | \\ int v1 = bar(); |
| 2319 | \\ int v2 = baz(); | 2319 | \\ int v2 = baz(); |
| 2320 | \\ return v1 != v2; | 2320 | \\ return v1 != v2; |
| 2321 | \\} | 2321 | \\} |
| 2322 | }); | 2322 | }); |
| 2323 | main_o.root_module.addIncludePath(foo_h.dirname()); | 2323 | main_o.root_module.addIncludePath(foo_h.dirname()); |
| 2324 | main_o.linkLibCpp(); | 2324 | main_o.linkLibCpp(); |
| ... | @@ -2340,14 +2340,14 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step { | ... | @@ -2340,14 +2340,14 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step { |
| 2340 | const test_step = addTestStep(b, "tls-large-tbss", opts); | 2340 | const test_step = addTestStep(b, "tls-large-tbss", opts); |
| 2341 | | 2341 | |
| 2342 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 2342 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 2343 | \\#include <stdio.h> | 2343 | \\#include <stdio.h> |
| 2344 | \\_Thread_local int x[0x8000]; | 2344 | \\_Thread_local int x[0x8000]; |
| 2345 | \\_Thread_local int y[0x8000]; | 2345 | \\_Thread_local int y[0x8000]; |
| 2346 | \\int main() { | 2346 | \\int main() { |
| 2347 | \\ x[0] = 3; | 2347 | \\ x[0] = 3; |
| 2348 | \\ x[0x7fff] = 5; | 2348 | \\ x[0x7fff] = 5; |
| 2349 | \\ printf("%d %d %d %d %d %d\n", x[0], x[1], x[0x7fff], y[0], y[1], y[0x7fff]); | 2349 | \\ printf("%d %d %d %d %d %d\n", x[0], x[1], x[0x7fff], y[0], y[1], y[0x7fff]); |
| 2350 | \\} | 2350 | \\} |
| 2351 | }); | 2351 | }); |
| 2352 | | 2352 | |
| 2353 | const run = addRunArtifact(exe); | 2353 | const run = addRunArtifact(exe); |
| ... | @@ -2361,15 +2361,15 @@ fn testTlsZig(b: *Build, opts: Options) *Step { | ... | @@ -2361,15 +2361,15 @@ fn testTlsZig(b: *Build, opts: Options) *Step { |
| 2361 | const test_step = addTestStep(b, "tls-zig", opts); | 2361 | const test_step = addTestStep(b, "tls-zig", opts); |
| 2362 | | 2362 | |
| 2363 | const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = | 2363 | const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = |
| 2364 | \\const std = @import("std"); | 2364 | \\const std = @import("std"); |
| 2365 | \\threadlocal var x: i32 = 0; | 2365 | \\threadlocal var x: i32 = 0; |
| 2366 | \\threadlocal var y: i32 = -1; | 2366 | \\threadlocal var y: i32 = -1; |
| 2367 | \\pub fn main() void { | 2367 | \\pub fn main() void { |
| 2368 | \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable; | 2368 | \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable; |
| 2369 | \\ x -= 1; | 2369 | \\ x -= 1; |
| 2370 | \\ y += 1; | 2370 | \\ y += 1; |
| 2371 | \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable; | 2371 | \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable; |
| 2372 | \\} | 2372 | \\} |
| 2373 | }); | 2373 | }); |
| 2374 | | 2374 | |
| 2375 | const run = addRunArtifact(exe); | 2375 | const run = addRunArtifact(exe); |
| ... | @@ -2387,15 +2387,15 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step { | ... | @@ -2387,15 +2387,15 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step { |
| 2387 | const test_step = addTestStep(b, "two-level-namespace", opts); | 2387 | const test_step = addTestStep(b, "two-level-namespace", opts); |
| 2388 | | 2388 | |
| 2389 | const liba = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = | 2389 | const liba = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = |
| 2390 | \\#include <stdio.h> | 2390 | \\#include <stdio.h> |
| 2391 | \\int foo = 1; | 2391 | \\int foo = 1; |
| 2392 | \\int* ptr_to_foo = &foo; | 2392 | \\int* ptr_to_foo = &foo; |
| 2393 | \\int getFoo() { | 2393 | \\int getFoo() { |
| 2394 | \\ return foo; | 2394 | \\ return foo; |
| 2395 | \\} | 2395 | \\} |
| 2396 | \\void printInA() { | 2396 | \\void printInA() { |
| 2397 | \\ printf("liba: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); | 2397 | \\ printf("liba: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); |
| 2398 | \\} | 2398 | \\} |
| 2399 | }); | 2399 | }); |
| 2400 | | 2400 | |
| 2401 | { | 2401 | { |
| ... | @@ -2408,15 +2408,15 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step { | ... | @@ -2408,15 +2408,15 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step { |
| 2408 | } | 2408 | } |
| 2409 | | 2409 | |
| 2410 | const libb = addSharedLibrary(b, opts, .{ .name = "b", .c_source_bytes = | 2410 | const libb = addSharedLibrary(b, opts, .{ .name = "b", .c_source_bytes = |
| 2411 | \\#include <stdio.h> | 2411 | \\#include <stdio.h> |
| 2412 | \\int foo = 2; | 2412 | \\int foo = 2; |
| 2413 | \\int* ptr_to_foo = &foo; | 2413 | \\int* ptr_to_foo = &foo; |
| 2414 | \\int getFoo() { | 2414 | \\int getFoo() { |
| 2415 | \\ return foo; | 2415 | \\ return foo; |
| 2416 | \\} | 2416 | \\} |
| 2417 | \\void printInB() { | 2417 | \\void printInB() { |
| 2418 | \\ printf("libb: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); | 2418 | \\ printf("libb: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); |
| 2419 | \\} | 2419 | \\} |
| 2420 | }); | 2420 | }); |
| 2421 | | 2421 | |
| 2422 | { | 2422 | { |
| ... | @@ -2429,17 +2429,17 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step { | ... | @@ -2429,17 +2429,17 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step { |
| 2429 | } | 2429 | } |
| 2430 | | 2430 | |
| 2431 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = | 2431 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = |
| 2432 | \\#include <stdio.h> | 2432 | \\#include <stdio.h> |
| 2433 | \\int getFoo(); | 2433 | \\int getFoo(); |
| 2434 | \\extern int* ptr_to_foo; | 2434 | \\extern int* ptr_to_foo; |
| 2435 | \\void printInA(); | 2435 | \\void printInA(); |
| 2436 | \\void printInB(); | 2436 | \\void printInB(); |
| 2437 | \\int main() { | 2437 | \\int main() { |
| 2438 | \\ printf("main: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); | 2438 | \\ printf("main: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); |
| 2439 | \\ printInA(); | 2439 | \\ printInA(); |
| 2440 | \\ printInB(); | 2440 | \\ printInB(); |
| 2441 | \\ return 0; | 2441 | \\ return 0; |
| 2442 | \\} | 2442 | \\} |
| 2443 | }); | 2443 | }); |
| 2444 | | 2444 | |
| 2445 | { | 2445 | { |
| ... | @@ -2629,17 +2629,17 @@ fn testUnresolvedError(b: *Build, opts: Options) *Step { | ... | @@ -2629,17 +2629,17 @@ fn testUnresolvedError(b: *Build, opts: Options) *Step { |
| 2629 | const test_step = addTestStep(b, "unresolved-error", opts); | 2629 | const test_step = addTestStep(b, "unresolved-error", opts); |
| 2630 | | 2630 | |
| 2631 | const obj = addObject(b, opts, .{ .name = "a", .zig_source_bytes = | 2631 | const obj = addObject(b, opts, .{ .name = "a", .zig_source_bytes = |
| 2632 | \\extern fn foo() i32; | 2632 | \\extern fn foo() i32; |
| 2633 | \\export fn bar() i32 { return foo() + 1; } | 2633 | \\export fn bar() i32 { return foo() + 1; } |
| 2634 | }); | 2634 | }); |
| 2635 | | 2635 | |
| 2636 | const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = | 2636 | const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = |
| 2637 | \\const std = @import("std"); | 2637 | \\const std = @import("std"); |
| 2638 | \\extern fn foo() i32; | 2638 | \\extern fn foo() i32; |
| 2639 | \\extern fn bar() i32; | 2639 | \\extern fn bar() i32; |
| 2640 | \\pub fn main() void { | 2640 | \\pub fn main() void { |
| 2641 | \\ std.debug.print("foo() + bar() = {d}", .{foo() + bar()}); | 2641 | \\ std.debug.print("foo() + bar() = {d}", .{foo() + bar()}); |
| 2642 | \\} | 2642 | \\} |
| 2643 | }); | 2643 | }); |
| 2644 | exe.addObject(obj); | 2644 | exe.addObject(obj); |
| 2645 | | 2645 | |
| ... | @@ -2665,17 +2665,17 @@ fn testUnresolvedError2(b: *Build, opts: Options) *Step { | ... | @@ -2665,17 +2665,17 @@ fn testUnresolvedError2(b: *Build, opts: Options) *Step { |
| 2665 | const test_step = addTestStep(b, "unresolved-error-2", opts); | 2665 | const test_step = addTestStep(b, "unresolved-error-2", opts); |
| 2666 | | 2666 | |
| 2667 | const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = | 2667 | const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = |
| 2668 | \\pub fn main() !void { | 2668 | \\pub fn main() !void { |
| 2669 | \\ const msg_send_fn = @extern( | 2669 | \\ const msg_send_fn = @extern( |
| 2670 | \\ *const fn () callconv(.C) usize, | 2670 | \\ *const fn () callconv(.C) usize, |
| 2671 | \\ .{ .name = "objc_msgSend$initWithContentRect:styleMask:backing:defer:screen:" }, | 2671 | \\ .{ .name = "objc_msgSend$initWithContentRect:styleMask:backing:defer:screen:" }, |
| 2672 | \\ ); | 2672 | \\ ); |
| 2673 | \\ _ = @call( | 2673 | \\ _ = @call( |
| 2674 | \\ .auto, | 2674 | \\ .auto, |
| 2675 | \\ msg_send_fn, | 2675 | \\ msg_send_fn, |
| 2676 | \\ .{}, | 2676 | \\ .{}, |
| 2677 | \\ ); | 2677 | \\ ); |
| 2678 | \\} | 2678 | \\} |
| 2679 | }); | 2679 | }); |
| 2680 | | 2680 | |
| 2681 | expectLinkErrors(exe, test_step, .{ .exact = &.{ | 2681 | expectLinkErrors(exe, test_step, .{ .exact = &.{ |
| ... | @@ -2737,82 +2737,82 @@ fn testUnwindInfo(b: *Build, opts: Options) *Step { | ... | @@ -2737,82 +2737,82 @@ fn testUnwindInfo(b: *Build, opts: Options) *Step { |
| 2737 | }; | 2737 | }; |
| 2738 | | 2738 | |
| 2739 | const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes = | 2739 | const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes = |
| 2740 | \\#include "all.h" | 2740 | \\#include "all.h" |
| 2741 | \\#include <cstdio> | 2741 | \\#include <cstdio> |
| 2742 | \\ | 2742 | \\ |
| 2743 | \\void fn_c() { | 2743 | \\void fn_c() { |
| 2744 | \\ SimpleStringOwner c{ "cccccccccc" }; | 2744 | \\ SimpleStringOwner c{ "cccccccccc" }; |
| 2745 | \\} | 2745 | \\} |
| 2746 | \\ | 2746 | \\ |
| 2747 | \\void fn_b() { | 2747 | \\void fn_b() { |
| 2748 | \\ SimpleStringOwner b{ "b" }; | 2748 | \\ SimpleStringOwner b{ "b" }; |
| 2749 | \\ fn_c(); | 2749 | \\ fn_c(); |
| 2750 | \\} | 2750 | \\} |
| 2751 | \\ | 2751 | \\ |
| 2752 | \\int main() { | 2752 | \\int main() { |
| 2753 | \\ try { | 2753 | \\ try { |
| 2754 | \\ SimpleStringOwner a{ "a" }; | 2754 | \\ SimpleStringOwner a{ "a" }; |
| 2755 | \\ fn_b(); | 2755 | \\ fn_b(); |
| 2756 | \\ SimpleStringOwner d{ "d" }; | 2756 | \\ SimpleStringOwner d{ "d" }; |
| 2757 | \\ } catch (const Error& e) { | 2757 | \\ } catch (const Error& e) { |
| 2758 | \\ printf("Error: %s\n", e.what()); | 2758 | \\ printf("Error: %s\n", e.what()); |
| 2759 | \\ } catch(const std::exception& e) { | 2759 | \\ } catch(const std::exception& e) { |
| 2760 | \\ printf("Exception: %s\n", e.what()); | 2760 | \\ printf("Exception: %s\n", e.what()); |
| 2761 | \\ } | 2761 | \\ } |
| 2762 | \\ return 0; | 2762 | \\ return 0; |
| 2763 | \\} | 2763 | \\} |
| 2764 | }); | 2764 | }); |
| 2765 | main_o.root_module.addIncludePath(all_h.dirname()); | 2765 | main_o.root_module.addIncludePath(all_h.dirname()); |
| 2766 | main_o.linkLibCpp(); | 2766 | main_o.linkLibCpp(); |
| 2767 | | 2767 | |
| 2768 | const simple_string_o = addObject(b, opts, .{ .name = "simple_string", .cpp_source_bytes = | 2768 | const simple_string_o = addObject(b, opts, .{ .name = "simple_string", .cpp_source_bytes = |
| 2769 | \\#include "all.h" | 2769 | \\#include "all.h" |
| 2770 | \\#include <cstdio> | 2770 | \\#include <cstdio> |
| 2771 | \\#include <cstring> | 2771 | \\#include <cstring> |
| 2772 | \\ | 2772 | \\ |
| 2773 | \\SimpleString::SimpleString(size_t max_size) | 2773 | \\SimpleString::SimpleString(size_t max_size) |
| 2774 | \\: max_size{ max_size }, length{} { | 2774 | \\: max_size{ max_size }, length{} { |
| 2775 | \\ if (max_size == 0) { | 2775 | \\ if (max_size == 0) { |
| 2776 | \\ throw Error{ "Max size must be at least 1." }; | 2776 | \\ throw Error{ "Max size must be at least 1." }; |
| 2777 | \\ } | 2777 | \\ } |
| 2778 | \\ buffer = new char[max_size]; | 2778 | \\ buffer = new char[max_size]; |
| 2779 | \\ buffer[0] = 0; | 2779 | \\ buffer[0] = 0; |
| 2780 | \\} | 2780 | \\} |
| 2781 | \\ | 2781 | \\ |
| 2782 | \\SimpleString::~SimpleString() { | 2782 | \\SimpleString::~SimpleString() { |
| 2783 | \\ delete[] buffer; | 2783 | \\ delete[] buffer; |
| 2784 | \\} | 2784 | \\} |
| 2785 | \\ | 2785 | \\ |
| 2786 | \\void SimpleString::print(const char* tag) const { | 2786 | \\void SimpleString::print(const char* tag) const { |
| 2787 | \\ printf("%s: %s", tag, buffer); | 2787 | \\ printf("%s: %s", tag, buffer); |
| 2788 | \\} | 2788 | \\} |
| 2789 | \\ | 2789 | \\ |
| 2790 | \\bool SimpleString::append_line(const char* x) { | 2790 | \\bool SimpleString::append_line(const char* x) { |
| 2791 | \\ const auto x_len = strlen(x); | 2791 | \\ const auto x_len = strlen(x); |
| 2792 | \\ if (x_len + length + 2 > max_size) return false; | 2792 | \\ if (x_len + length + 2 > max_size) return false; |
| 2793 | \\ std::strncpy(buffer + length, x, max_size - length); | 2793 | \\ std::strncpy(buffer + length, x, max_size - length); |
| 2794 | \\ length += x_len; | 2794 | \\ length += x_len; |
| 2795 | \\ buffer[length++] = '\n'; | 2795 | \\ buffer[length++] = '\n'; |
| 2796 | \\ buffer[length] = 0; | 2796 | \\ buffer[length] = 0; |
| 2797 | \\ return true; | 2797 | \\ return true; |
| 2798 | \\} | 2798 | \\} |
| 2799 | }); | 2799 | }); |
| 2800 | simple_string_o.root_module.addIncludePath(all_h.dirname()); | 2800 | simple_string_o.root_module.addIncludePath(all_h.dirname()); |
| 2801 | simple_string_o.linkLibCpp(); | 2801 | simple_string_o.linkLibCpp(); |
| 2802 | | 2802 | |
| 2803 | const simple_string_owner_o = addObject(b, opts, .{ .name = "simple_string_owner", .cpp_source_bytes = | 2803 | const simple_string_owner_o = addObject(b, opts, .{ .name = "simple_string_owner", .cpp_source_bytes = |
| 2804 | \\#include "all.h" | 2804 | \\#include "all.h" |
| 2805 | \\ | 2805 | \\ |
| 2806 | \\SimpleStringOwner::SimpleStringOwner(const char* x) : string{ 10 } { | 2806 | \\SimpleStringOwner::SimpleStringOwner(const char* x) : string{ 10 } { |
| 2807 | \\ if (!string.append_line(x)) { | 2807 | \\ if (!string.append_line(x)) { |
| 2808 | \\ throw Error{ "Not enough memory!" }; | 2808 | \\ throw Error{ "Not enough memory!" }; |
| 2809 | \\ } | 2809 | \\ } |
| 2810 | \\ string.print("Constructed"); | 2810 | \\ string.print("Constructed"); |
| 2811 | \\} | 2811 | \\} |
| 2812 | \\ | 2812 | \\ |
| 2813 | \\SimpleStringOwner::~SimpleStringOwner() { | 2813 | \\SimpleStringOwner::~SimpleStringOwner() { |
| 2814 | \\ string.print("About to destroy"); | 2814 | \\ string.print("About to destroy"); |
| 2815 | \\} | 2815 | \\} |
| 2816 | }); | 2816 | }); |
| 2817 | simple_string_owner_o.root_module.addIncludePath(all_h.dirname()); | 2817 | simple_string_owner_o.root_module.addIncludePath(all_h.dirname()); |
| 2818 | simple_string_owner_o.linkLibCpp(); | 2818 | simple_string_owner_o.linkLibCpp(); |
| ... | @@ -2848,52 +2848,52 @@ fn testUnwindInfoNoSubsectionsArm64(b: *Build, opts: Options) *Step { | ... | @@ -2848,52 +2848,52 @@ fn testUnwindInfoNoSubsectionsArm64(b: *Build, opts: Options) *Step { |
| 2848 | const test_step = addTestStep(b, "unwind-info-no-subsections-arm64", opts); | 2848 | const test_step = addTestStep(b, "unwind-info-no-subsections-arm64", opts); |
| 2849 | | 2849 | |
| 2850 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = | 2850 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = |
| 2851 | \\.globl _foo | 2851 | \\.globl _foo |
| 2852 | \\.align 4 | 2852 | \\.align 4 |
| 2853 | \\_foo: | 2853 | \\_foo: |
| 2854 | \\ .cfi_startproc | 2854 | \\ .cfi_startproc |
| 2855 | \\ stp x29, x30, [sp, #-32]! | 2855 | \\ stp x29, x30, [sp, #-32]! |
| 2856 | \\ .cfi_def_cfa_offset 32 | 2856 | \\ .cfi_def_cfa_offset 32 |
| 2857 | \\ .cfi_offset w30, -24 | 2857 | \\ .cfi_offset w30, -24 |
| 2858 | \\ .cfi_offset w29, -32 | 2858 | \\ .cfi_offset w29, -32 |
| 2859 | \\ mov x29, sp | 2859 | \\ mov x29, sp |
| 2860 | \\ .cfi_def_cfa w29, 32 | 2860 | \\ .cfi_def_cfa w29, 32 |
| 2861 | \\ bl _bar | 2861 | \\ bl _bar |
| 2862 | \\ ldp x29, x30, [sp], #32 | 2862 | \\ ldp x29, x30, [sp], #32 |
| 2863 | \\ .cfi_restore w29 | 2863 | \\ .cfi_restore w29 |
| 2864 | \\ .cfi_restore w30 | 2864 | \\ .cfi_restore w30 |
| 2865 | \\ .cfi_def_cfa_offset 0 | 2865 | \\ .cfi_def_cfa_offset 0 |
| 2866 | \\ ret | 2866 | \\ ret |
| 2867 | \\ .cfi_endproc | 2867 | \\ .cfi_endproc |
| 2868 | \\ | 2868 | \\ |
| 2869 | \\.globl _bar | 2869 | \\.globl _bar |
| 2870 | \\.align 4 | 2870 | \\.align 4 |
| 2871 | \\_bar: | 2871 | \\_bar: |
| 2872 | \\ .cfi_startproc | 2872 | \\ .cfi_startproc |
| 2873 | \\ sub sp, sp, #32 | 2873 | \\ sub sp, sp, #32 |
| 2874 | \\ .cfi_def_cfa_offset -32 | 2874 | \\ .cfi_def_cfa_offset -32 |
| 2875 | \\ stp x29, x30, [sp, #16] | 2875 | \\ stp x29, x30, [sp, #16] |
| 2876 | \\ .cfi_offset w30, -24 | 2876 | \\ .cfi_offset w30, -24 |
| 2877 | \\ .cfi_offset w29, -32 | 2877 | \\ .cfi_offset w29, -32 |
| 2878 | \\ mov x29, sp | 2878 | \\ mov x29, sp |
| 2879 | \\ .cfi_def_cfa w29, 32 | 2879 | \\ .cfi_def_cfa w29, 32 |
| 2880 | \\ mov w0, #4 | 2880 | \\ mov w0, #4 |
| 2881 | \\ ldp x29, x30, [sp, #16] | 2881 | \\ ldp x29, x30, [sp, #16] |
| 2882 | \\ .cfi_restore w29 | 2882 | \\ .cfi_restore w29 |
| 2883 | \\ .cfi_restore w30 | 2883 | \\ .cfi_restore w30 |
| 2884 | \\ add sp, sp, #32 | 2884 | \\ add sp, sp, #32 |
| 2885 | \\ .cfi_def_cfa_offset 0 | 2885 | \\ .cfi_def_cfa_offset 0 |
| 2886 | \\ ret | 2886 | \\ ret |
| 2887 | \\ .cfi_endproc | 2887 | \\ .cfi_endproc |
| 2888 | }); | 2888 | }); |
| 2889 | | 2889 | |
| 2890 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 2890 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 2891 | \\#include <stdio.h> | 2891 | \\#include <stdio.h> |
| 2892 | \\int foo(); | 2892 | \\int foo(); |
| 2893 | \\int main() { | 2893 | \\int main() { |
| 2894 | \\ printf("%d\n", foo()); | 2894 | \\ printf("%d\n", foo()); |
| 2895 | \\ return 0; | 2895 | \\ return 0; |
| 2896 | \\} | 2896 | \\} |
| 2897 | }); | 2897 | }); |
| 2898 | exe.addObject(a_o); | 2898 | exe.addObject(a_o); |
| 2899 | | 2899 | |
| ... | @@ -2908,44 +2908,44 @@ fn testUnwindInfoNoSubsectionsX64(b: *Build, opts: Options) *Step { | ... | @@ -2908,44 +2908,44 @@ fn testUnwindInfoNoSubsectionsX64(b: *Build, opts: Options) *Step { |
| 2908 | const test_step = addTestStep(b, "unwind-info-no-subsections-x64", opts); | 2908 | const test_step = addTestStep(b, "unwind-info-no-subsections-x64", opts); |
| 2909 | | 2909 | |
| 2910 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = | 2910 | const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = |
| 2911 | \\.globl _foo | 2911 | \\.globl _foo |
| 2912 | \\_foo: | 2912 | \\_foo: |
| 2913 | \\ .cfi_startproc | 2913 | \\ .cfi_startproc |
| 2914 | \\ push %rbp | 2914 | \\ push %rbp |
| 2915 | \\ .cfi_def_cfa_offset 8 | 2915 | \\ .cfi_def_cfa_offset 8 |
| 2916 | \\ .cfi_offset %rbp, -8 | 2916 | \\ .cfi_offset %rbp, -8 |
| 2917 | \\ mov %rsp, %rbp | 2917 | \\ mov %rsp, %rbp |
| 2918 | \\ .cfi_def_cfa_register %rbp | 2918 | \\ .cfi_def_cfa_register %rbp |
| 2919 | \\ call _bar | 2919 | \\ call _bar |
| 2920 | \\ pop %rbp | 2920 | \\ pop %rbp |
| 2921 | \\ .cfi_restore %rbp | 2921 | \\ .cfi_restore %rbp |
| 2922 | \\ .cfi_def_cfa_offset 0 | 2922 | \\ .cfi_def_cfa_offset 0 |
| 2923 | \\ ret | 2923 | \\ ret |
| 2924 | \\ .cfi_endproc | 2924 | \\ .cfi_endproc |
| 2925 | \\ | 2925 | \\ |
| 2926 | \\.globl _bar | 2926 | \\.globl _bar |
| 2927 | \\_bar: | 2927 | \\_bar: |
| 2928 | \\ .cfi_startproc | 2928 | \\ .cfi_startproc |
| 2929 | \\ push %rbp | 2929 | \\ push %rbp |
| 2930 | \\ .cfi_def_cfa_offset 8 | 2930 | \\ .cfi_def_cfa_offset 8 |
| 2931 | \\ .cfi_offset %rbp, -8 | 2931 | \\ .cfi_offset %rbp, -8 |
| 2932 | \\ mov %rsp, %rbp | 2932 | \\ mov %rsp, %rbp |
| 2933 | \\ .cfi_def_cfa_register %rbp | 2933 | \\ .cfi_def_cfa_register %rbp |
| 2934 | \\ mov $4, %rax | 2934 | \\ mov $4, %rax |
| 2935 | \\ pop %rbp | 2935 | \\ pop %rbp |
| 2936 | \\ .cfi_restore %rbp | 2936 | \\ .cfi_restore %rbp |
| 2937 | \\ .cfi_def_cfa_offset 0 | 2937 | \\ .cfi_def_cfa_offset 0 |
| 2938 | \\ ret | 2938 | \\ ret |
| 2939 | \\ .cfi_endproc | 2939 | \\ .cfi_endproc |
| 2940 | }); | 2940 | }); |
| 2941 | | 2941 | |
| 2942 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 2942 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 2943 | \\#include <stdio.h> | 2943 | \\#include <stdio.h> |
| 2944 | \\int foo(); | 2944 | \\int foo(); |
| 2945 | \\int main() { | 2945 | \\int main() { |
| 2946 | \\ printf("%d\n", foo()); | 2946 | \\ printf("%d\n", foo()); |
| 2947 | \\ return 0; | 2947 | \\ return 0; |
| 2948 | \\} | 2948 | \\} |
| 2949 | }); | 2949 | }); |
| 2950 | exe.addObject(a_o); | 2950 | exe.addObject(a_o); |
| 2951 | | 2951 | |
| ... | @@ -2961,27 +2961,27 @@ fn testWeakBind(b: *Build, opts: Options) *Step { | ... | @@ -2961,27 +2961,27 @@ fn testWeakBind(b: *Build, opts: Options) *Step { |
| 2961 | const test_step = addTestStep(b, "weak-bind", opts); | 2961 | const test_step = addTestStep(b, "weak-bind", opts); |
| 2962 | | 2962 | |
| 2963 | const lib = addSharedLibrary(b, opts, .{ .name = "foo", .asm_source_bytes = | 2963 | const lib = addSharedLibrary(b, opts, .{ .name = "foo", .asm_source_bytes = |
| 2964 | \\.globl _weak_dysym | 2964 | \\.globl _weak_dysym |
| 2965 | \\.weak_definition _weak_dysym | 2965 | \\.weak_definition _weak_dysym |
| 2966 | \\_weak_dysym: | 2966 | \\_weak_dysym: |
| 2967 | \\ .quad 0x1234 | 2967 | \\ .quad 0x1234 |
| 2968 | \\ | 2968 | \\ |
| 2969 | \\.globl _weak_dysym_for_gotpcrel | 2969 | \\.globl _weak_dysym_for_gotpcrel |
| 2970 | \\.weak_definition _weak_dysym_for_gotpcrel | 2970 | \\.weak_definition _weak_dysym_for_gotpcrel |
| 2971 | \\_weak_dysym_for_gotpcrel: | 2971 | \\_weak_dysym_for_gotpcrel: |
| 2972 | \\ .quad 0x1234 | 2972 | \\ .quad 0x1234 |
| 2973 | \\ | 2973 | \\ |
| 2974 | \\.globl _weak_dysym_fn | 2974 | \\.globl _weak_dysym_fn |
| 2975 | \\.weak_definition _weak_dysym_fn | 2975 | \\.weak_definition _weak_dysym_fn |
| 2976 | \\_weak_dysym_fn: | 2976 | \\_weak_dysym_fn: |
| 2977 | \\ ret | 2977 | \\ ret |
| 2978 | \\ | 2978 | \\ |
| 2979 | \\.section __DATA,__thread_vars,thread_local_variables | 2979 | \\.section __DATA,__thread_vars,thread_local_variables |
| 2980 | \\ | 2980 | \\ |
| 2981 | \\.globl _weak_dysym_tlv | 2981 | \\.globl _weak_dysym_tlv |
| 2982 | \\.weak_definition _weak_dysym_tlv | 2982 | \\.weak_definition _weak_dysym_tlv |
| 2983 | \\_weak_dysym_tlv: | 2983 | \\_weak_dysym_tlv: |
| 2984 | \\ .quad 0x1234 | 2984 | \\ .quad 0x1234 |
| 2985 | }); | 2985 | }); |
| 2986 | | 2986 | |
| 2987 | { | 2987 | { |
| ... | @@ -2995,61 +2995,61 @@ fn testWeakBind(b: *Build, opts: Options) *Step { | ... | @@ -2995,61 +2995,61 @@ fn testWeakBind(b: *Build, opts: Options) *Step { |
| 2995 | } | 2995 | } |
| 2996 | | 2996 | |
| 2997 | const exe = addExecutable(b, opts, .{ .name = "main", .asm_source_bytes = | 2997 | const exe = addExecutable(b, opts, .{ .name = "main", .asm_source_bytes = |
| 2998 | \\.globl _main, _weak_external, _weak_external_for_gotpcrel, _weak_external_fn | 2998 | \\.globl _main, _weak_external, _weak_external_for_gotpcrel, _weak_external_fn |
| 2999 | \\.weak_definition _weak_external, _weak_external_for_gotpcrel, _weak_external_fn, _weak_internal, _weak_internal_for_gotpcrel, _weak_internal_fn | 2999 | \\.weak_definition _weak_external, _weak_external_for_gotpcrel, _weak_external_fn, _weak_internal, _weak_internal_for_gotpcrel, _weak_internal_fn |
| 3000 | \\ | 3000 | \\ |
| 3001 | \\_main: | 3001 | \\_main: |
| 3002 | \\ mov _weak_dysym_for_gotpcrel@GOTPCREL(%rip), %rax | 3002 | \\ mov _weak_dysym_for_gotpcrel@GOTPCREL(%rip), %rax |
| 3003 | \\ mov _weak_external_for_gotpcrel@GOTPCREL(%rip), %rax | 3003 | \\ mov _weak_external_for_gotpcrel@GOTPCREL(%rip), %rax |
| 3004 | \\ mov _weak_internal_for_gotpcrel@GOTPCREL(%rip), %rax | 3004 | \\ mov _weak_internal_for_gotpcrel@GOTPCREL(%rip), %rax |
| 3005 | \\ mov _weak_tlv@TLVP(%rip), %rax | 3005 | \\ mov _weak_tlv@TLVP(%rip), %rax |
| 3006 | \\ mov _weak_dysym_tlv@TLVP(%rip), %rax | 3006 | \\ mov _weak_dysym_tlv@TLVP(%rip), %rax |
| 3007 | \\ mov _weak_internal_tlv@TLVP(%rip), %rax | 3007 | \\ mov _weak_internal_tlv@TLVP(%rip), %rax |
| 3008 | \\ callq _weak_dysym_fn | 3008 | \\ callq _weak_dysym_fn |
| 3009 | \\ callq _weak_external_fn | 3009 | \\ callq _weak_external_fn |
| 3010 | \\ callq _weak_internal_fn | 3010 | \\ callq _weak_internal_fn |
| 3011 | \\ mov $0, %rax | 3011 | \\ mov $0, %rax |
| 3012 | \\ ret | 3012 | \\ ret |
| 3013 | \\ | 3013 | \\ |
| 3014 | \\_weak_external: | 3014 | \\_weak_external: |
| 3015 | \\ .quad 0x1234 | 3015 | \\ .quad 0x1234 |
| 3016 | \\ | 3016 | \\ |
| 3017 | \\_weak_external_for_gotpcrel: | 3017 | \\_weak_external_for_gotpcrel: |
| 3018 | \\ .quad 0x1234 | 3018 | \\ .quad 0x1234 |
| 3019 | \\ | 3019 | \\ |
| 3020 | \\_weak_external_fn: | 3020 | \\_weak_external_fn: |
| 3021 | \\ ret | 3021 | \\ ret |
| 3022 | \\ | 3022 | \\ |
| 3023 | \\_weak_internal: | 3023 | \\_weak_internal: |
| 3024 | \\ .quad 0x1234 | 3024 | \\ .quad 0x1234 |
| 3025 | \\ | 3025 | \\ |
| 3026 | \\_weak_internal_for_gotpcrel: | 3026 | \\_weak_internal_for_gotpcrel: |
| 3027 | \\ .quad 0x1234 | 3027 | \\ .quad 0x1234 |
| 3028 | \\ | 3028 | \\ |
| 3029 | \\_weak_internal_fn: | 3029 | \\_weak_internal_fn: |
| 3030 | \\ ret | 3030 | \\ ret |
| 3031 | \\ | 3031 | \\ |
| 3032 | \\.data | 3032 | \\.data |
| 3033 | \\ .quad _weak_dysym | 3033 | \\ .quad _weak_dysym |
| 3034 | \\ .quad _weak_external + 2 | 3034 | \\ .quad _weak_external + 2 |
| 3035 | \\ .quad _weak_internal | 3035 | \\ .quad _weak_internal |
| 3036 | \\ | 3036 | \\ |
| 3037 | \\.tbss _weak_tlv$tlv$init, 4, 2 | 3037 | \\.tbss _weak_tlv$tlv$init, 4, 2 |
| 3038 | \\.tbss _weak_internal_tlv$tlv$init, 4, 2 | 3038 | \\.tbss _weak_internal_tlv$tlv$init, 4, 2 |
| 3039 | \\ | 3039 | \\ |
| 3040 | \\.section __DATA,__thread_vars,thread_local_variables | 3040 | \\.section __DATA,__thread_vars,thread_local_variables |
| 3041 | \\.globl _weak_tlv | 3041 | \\.globl _weak_tlv |
| 3042 | \\.weak_definition _weak_tlv, _weak_internal_tlv | 3042 | \\.weak_definition _weak_tlv, _weak_internal_tlv |
| 3043 | \\ | 3043 | \\ |
| 3044 | \\_weak_tlv: | 3044 | \\_weak_tlv: |
| 3045 | \\ .quad __tlv_bootstrap | 3045 | \\ .quad __tlv_bootstrap |
| 3046 | \\ .quad 0 | 3046 | \\ .quad 0 |
| 3047 | \\ .quad _weak_tlv$tlv$init | 3047 | \\ .quad _weak_tlv$tlv$init |
| 3048 | \\ | 3048 | \\ |
| 3049 | \\_weak_internal_tlv: | 3049 | \\_weak_internal_tlv: |
| 3050 | \\ .quad __tlv_bootstrap | 3050 | \\ .quad __tlv_bootstrap |
| 3051 | \\ .quad 0 | 3051 | \\ .quad 0 |
| 3052 | \\ .quad _weak_internal_tlv$tlv$init | 3052 | \\ .quad _weak_internal_tlv$tlv$init |
| 3053 | }); | 3053 | }); |
| 3054 | exe.linkLibrary(lib); | 3054 | exe.linkLibrary(lib); |
| 3055 | | 3055 | |
| ... | @@ -3111,23 +3111,23 @@ fn testWeakLibrary(b: *Build, opts: Options) *Step { | ... | @@ -3111,23 +3111,23 @@ fn testWeakLibrary(b: *Build, opts: Options) *Step { |
| 3111 | const test_step = addTestStep(b, "weak-library", opts); | 3111 | const test_step = addTestStep(b, "weak-library", opts); |
| 3112 | | 3112 | |
| 3113 | const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = | 3113 | const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = |
| 3114 | \\#include<stdio.h> | 3114 | \\#include<stdio.h> |
| 3115 | \\int a = 42; | 3115 | \\int a = 42; |
| 3116 | \\const char* asStr() { | 3116 | \\const char* asStr() { |
| 3117 | \\ static char str[3]; | 3117 | \\ static char str[3]; |
| 3118 | \\ sprintf(str, "%d", 42); | 3118 | \\ sprintf(str, "%d", 42); |
| 3119 | \\ return str; | 3119 | \\ return str; |
| 3120 | \\} | 3120 | \\} |
| 3121 | }); | 3121 | }); |
| 3122 | | 3122 | |
| 3123 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 3123 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 3124 | \\#include<stdio.h> | 3124 | \\#include<stdio.h> |
| 3125 | \\extern int a; | 3125 | \\extern int a; |
| 3126 | \\extern const char* asStr(); | 3126 | \\extern const char* asStr(); |
| 3127 | \\int main() { | 3127 | \\int main() { |
| 3128 | \\ printf("%d %s", a, asStr()); | 3128 | \\ printf("%d %s", a, asStr()); |
| 3129 | \\ return 0; | 3129 | \\ return 0; |
| 3130 | \\} | 3130 | \\} |
| 3131 | }); | 3131 | }); |
| 3132 | exe.root_module.linkSystemLibrary("a", .{ .weak = true }); | 3132 | exe.root_module.linkSystemLibrary("a", .{ .weak = true }); |
| 3133 | exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory()); | 3133 | exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory()); |
| ... | @@ -3154,11 +3154,11 @@ fn testWeakRef(b: *Build, opts: Options) *Step { | ... | @@ -3154,11 +3154,11 @@ fn testWeakRef(b: *Build, opts: Options) *Step { |
| 3154 | const test_step = addTestStep(b, "weak-ref", opts); | 3154 | const test_step = addTestStep(b, "weak-ref", opts); |
| 3155 | | 3155 | |
| 3156 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = | 3156 | const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = |
| 3157 | \\#include <stdio.h> | 3157 | \\#include <stdio.h> |
| 3158 | \\#include <sys/_types/_fd_def.h> | 3158 | \\#include <sys/_types/_fd_def.h> |
| 3159 | \\int main(int argc, char** argv) { | 3159 | \\int main(int argc, char** argv) { |
| 3160 | \\ printf("__darwin_check_fd_set_overflow: %p\n", __darwin_check_fd_set_overflow); | 3160 | \\ printf("__darwin_check_fd_set_overflow: %p\n", __darwin_check_fd_set_overflow); |
| 3161 | \\} | 3161 | \\} |
| 3162 | }); | 3162 | }); |
| 3163 | | 3163 | |
| 3164 | const check = exe.checkObject(); | 3164 | const check = exe.checkObject(); |