authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-14 10:35:45+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:40+01:00
log9fce2e2233733e1ada2b1440012ae78675e196f9
treee64c44243a56a7c4666dab8f63e92afa5b39df33
parent105655857f02c8bd59f5c0250f124a064df400cf

test/link/macho: test -u flag handling (forceUndefinedSymbol)


1 files changed, 79 insertions(+), 0 deletions(-)

test/link/macho.zig+79
...@@ -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 }));
2526
26 // Tests requiring symlinks when tested on Windows27 // 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}
638639
640fn 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.s717// Adapted from https://github.com/llvm/llvm-project/blob/main/lld/test/MachO/weak-binding.s
640fn testWeakBind(b: *Build, opts: Options) *Step {718fn 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;
839const addRunArtifact = link.addRunArtifact;917const addRunArtifact = link.addRunArtifact;
840const addObject = link.addObject;918const addObject = link.addObject;
841const addExecutable = link.addExecutable;919const addExecutable = link.addExecutable;
920const addStaticLibrary = link.addStaticLibrary;
842const addSharedLibrary = link.addSharedLibrary;921const addSharedLibrary = link.addSharedLibrary;
843const expectLinkErrors = link.expectLinkErrors;922const expectLinkErrors = link.expectLinkErrors;
844const link = @import("link.zig");923const link = @import("link.zig");