| ... | @@ -21,6 +21,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { | ... | @@ -21,6 +21,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step { |
| 21 | macho_step.dependOn(testMhExecuteHeader(b, .{ .target = default_target })); | 21 | macho_step.dependOn(testMhExecuteHeader(b, .{ .target = default_target })); |
| 22 | macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target })); | 22 | macho_step.dependOn(testSectionBoundarySymbols(b, .{ .target = default_target })); |
| 23 | macho_step.dependOn(testSegmentBoundarySymbols(b, .{ .target = default_target })); | 23 | macho_step.dependOn(testSegmentBoundarySymbols(b, .{ .target = default_target })); |
| | 24 | macho_step.dependOn(testUndefinedFlag(b, .{ .target = default_target })); |
| 24 | macho_step.dependOn(testWeakBind(b, .{ .target = x86_64_target })); | 25 | macho_step.dependOn(testWeakBind(b, .{ .target = x86_64_target })); |
| 25 | | 26 | |
| 26 | // Tests requiring symlinks when tested on Windows | 27 | // Tests requiring symlinks when tested on Windows |
| ... | @@ -636,6 +637,83 @@ fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step { | ... | @@ -636,6 +637,83 @@ fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step { |
| 636 | return test_step; | 637 | return test_step; |
| 637 | } | 638 | } |
| 638 | | 639 | |
| | 640 | fn testUndefinedFlag(b: *Build, opts: Options) *Step { |
| | 641 | const test_step = addTestStep(b, "macho-undefined-flag", opts); |
| | 642 | |
| | 643 | const obj = addObject(b, opts, .{ .name = "a", .c_source_bytes = "int foo = 42;" }); |
| | 644 | |
| | 645 | const lib = addStaticLibrary(b, opts, .{ .name = "a" }); |
| | 646 | lib.addObject(obj); |
| | 647 | |
| | 648 | const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = "int main() { return 0; }" }); |
| | 649 | |
| | 650 | { |
| | 651 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| | 652 | exe.addObject(main_o); |
| | 653 | exe.linkLibrary(lib); |
| | 654 | exe.forceUndefinedSymbol("_foo"); |
| | 655 | |
| | 656 | const run = addRunArtifact(exe); |
| | 657 | run.expectExitCode(0); |
| | 658 | test_step.dependOn(&run.step); |
| | 659 | |
| | 660 | const check = exe.checkObject(); |
| | 661 | check.checkInSymtab(); |
| | 662 | check.checkContains("_foo"); |
| | 663 | test_step.dependOn(&check.step); |
| | 664 | } |
| | 665 | |
| | 666 | { |
| | 667 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| | 668 | exe.addObject(main_o); |
| | 669 | exe.linkLibrary(lib); |
| | 670 | exe.forceUndefinedSymbol("_foo"); |
| | 671 | exe.link_gc_sections = true; |
| | 672 | |
| | 673 | const run = addRunArtifact(exe); |
| | 674 | run.expectExitCode(0); |
| | 675 | test_step.dependOn(&run.step); |
| | 676 | |
| | 677 | const check = exe.checkObject(); |
| | 678 | check.checkInSymtab(); |
| | 679 | check.checkContains("_foo"); |
| | 680 | test_step.dependOn(&check.step); |
| | 681 | } |
| | 682 | |
| | 683 | { |
| | 684 | const exe = addExecutable(b, opts, .{ .name = "main3" }); |
| | 685 | exe.addObject(main_o); |
| | 686 | exe.addObject(obj); |
| | 687 | |
| | 688 | const run = addRunArtifact(exe); |
| | 689 | run.expectExitCode(0); |
| | 690 | test_step.dependOn(&run.step); |
| | 691 | |
| | 692 | const check = exe.checkObject(); |
| | 693 | check.checkInSymtab(); |
| | 694 | check.checkContains("_foo"); |
| | 695 | test_step.dependOn(&check.step); |
| | 696 | } |
| | 697 | |
| | 698 | { |
| | 699 | const exe = addExecutable(b, opts, .{ .name = "main4" }); |
| | 700 | exe.addObject(main_o); |
| | 701 | exe.addObject(obj); |
| | 702 | exe.link_gc_sections = true; |
| | 703 | |
| | 704 | const run = addRunArtifact(exe); |
| | 705 | run.expectExitCode(0); |
| | 706 | test_step.dependOn(&run.step); |
| | 707 | |
| | 708 | const check = exe.checkObject(); |
| | 709 | check.checkInSymtab(); |
| | 710 | check.checkNotPresent("_foo"); |
| | 711 | test_step.dependOn(&check.step); |
| | 712 | } |
| | 713 | |
| | 714 | return test_step; |
| | 715 | } |
| | 716 | |
| 639 | // Adapted from https://github.com/llvm/llvm-project/blob/main/lld/test/MachO/weak-binding.s | 717 | // Adapted from https://github.com/llvm/llvm-project/blob/main/lld/test/MachO/weak-binding.s |
| 640 | fn testWeakBind(b: *Build, opts: Options) *Step { | 718 | fn testWeakBind(b: *Build, opts: Options) *Step { |
| 641 | const test_step = addTestStep(b, "macho-weak-bind", opts); | 719 | const test_step = addTestStep(b, "macho-weak-bind", opts); |
| ... | @@ -839,6 +917,7 @@ const addCSourceBytes = link.addCSourceBytes; | ... | @@ -839,6 +917,7 @@ const addCSourceBytes = link.addCSourceBytes; |
| 839 | const addRunArtifact = link.addRunArtifact; | 917 | const addRunArtifact = link.addRunArtifact; |
| 840 | const addObject = link.addObject; | 918 | const addObject = link.addObject; |
| 841 | const addExecutable = link.addExecutable; | 919 | const addExecutable = link.addExecutable; |
| | 920 | const addStaticLibrary = link.addStaticLibrary; |
| 842 | const addSharedLibrary = link.addSharedLibrary; | 921 | const addSharedLibrary = link.addSharedLibrary; |
| 843 | const expectLinkErrors = link.expectLinkErrors; | 922 | const expectLinkErrors = link.expectLinkErrors; |
| 844 | const link = @import("link.zig"); | 923 | const link = @import("link.zig"); |