| ... | @@ -21,6 +21,10 @@ pub fn build(b: *Build) void { | ... | @@ -21,6 +21,10 @@ pub fn build(b: *Build) void { |
| 21 | .abi = .gnu, | 21 | .abi = .gnu, |
| 22 | }; | 22 | }; |
| 23 | | 23 | |
| | 24 | // Exercise linker in -r mode |
| | 25 | elf_step.dependOn(testEmitRelocatable(b, .{ .use_llvm = false, .target = musl_target })); |
| | 26 | elf_step.dependOn(testEmitRelocatable(b, .{ .target = musl_target })); |
| | 27 | |
| 24 | // Exercise linker in ar mode | 28 | // Exercise linker in ar mode |
| 25 | elf_step.dependOn(testEmitStaticLib(b, .{ .target = musl_target })); | 29 | elf_step.dependOn(testEmitStaticLib(b, .{ .target = musl_target })); |
| 26 | | 30 | |
| ... | @@ -629,6 +633,53 @@ fn testDsoUndef(b: *Build, opts: Options) *Step { | ... | @@ -629,6 +633,53 @@ fn testDsoUndef(b: *Build, opts: Options) *Step { |
| 629 | return test_step; | 633 | return test_step; |
| 630 | } | 634 | } |
| 631 | | 635 | |
| | 636 | fn testEmitRelocatable(b: *Build, opts: Options) *Step { |
| | 637 | const test_step = addTestStep(b, "emit-relocatable", opts); |
| | 638 | |
| | 639 | const obj1 = addObject(b, "obj1", opts); |
| | 640 | addZigSourceBytes(obj1, |
| | 641 | \\const std = @import("std"); |
| | 642 | \\extern var bar: i32; |
| | 643 | \\export fn foo() i32 { |
| | 644 | \\ return bar; |
| | 645 | \\} |
| | 646 | \\export fn printFoo() void { |
| | 647 | \\ std.debug.print("foo={d}\n", .{foo()}); |
| | 648 | \\} |
| | 649 | ); |
| | 650 | addCSourceBytes(obj1, |
| | 651 | \\#include <stdio.h> |
| | 652 | \\int bar = 42; |
| | 653 | \\void printBar() { |
| | 654 | \\ fprintf(stderr, "bar=%d\n", bar); |
| | 655 | \\} |
| | 656 | , &.{}); |
| | 657 | obj1.linkLibC(); |
| | 658 | |
| | 659 | const exe = addExecutable(b, "test", opts); |
| | 660 | addZigSourceBytes(exe, |
| | 661 | \\const std = @import("std"); |
| | 662 | \\extern fn printFoo() void; |
| | 663 | \\extern fn printBar() void; |
| | 664 | \\pub fn main() void { |
| | 665 | \\ printFoo(); |
| | 666 | \\ printBar(); |
| | 667 | \\} |
| | 668 | ); |
| | 669 | exe.addObject(obj1); |
| | 670 | exe.linkLibC(); |
| | 671 | |
| | 672 | const run = addRunArtifact(exe); |
| | 673 | run.expectStdErrEqual( |
| | 674 | \\foo=42 |
| | 675 | \\bar=42 |
| | 676 | \\ |
| | 677 | ); |
| | 678 | test_step.dependOn(&run.step); |
| | 679 | |
| | 680 | return test_step; |
| | 681 | } |
| | 682 | |
| 632 | fn testEmitStaticLib(b: *Build, opts: Options) *Step { | 683 | fn testEmitStaticLib(b: *Build, opts: Options) *Step { |
| 633 | const test_step = addTestStep(b, "emit-static-lib", opts); | 684 | const test_step = addTestStep(b, "emit-static-lib", opts); |
| 634 | | 685 | |
| ... | @@ -951,7 +1002,6 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { | ... | @@ -951,7 +1002,6 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 951 | const obj = addObject(b, "obj", .{ | 1002 | const obj = addObject(b, "obj", .{ |
| 952 | .target = opts.target, | 1003 | .target = opts.target, |
| 953 | .use_llvm = true, | 1004 | .use_llvm = true, |
| 954 | .use_lld = true, | | |
| 955 | }); | 1005 | }); |
| 956 | addCSourceBytes(obj, | 1006 | addCSourceBytes(obj, |
| 957 | \\int live_var1 = 1; | 1007 | \\int live_var1 = 1; |