Skip to content

Commit

Permalink
macho: test -force_load option
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jan 13, 2024
1 parent 5737fb1 commit 5383423
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions test/macho.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn addMachOTests(b: *Build, options: common.Options) *Step {
macho_step.dependOn(testFlatNamespace(b, opts));
macho_step.dependOn(testFlatNamespaceExe(b, opts));
macho_step.dependOn(testFlatNamespaceWeak(b, opts));
macho_step.dependOn(testForceLoad(b, opts));
macho_step.dependOn(testHeaderpad(b, opts));
macho_step.dependOn(testHeaderWeakFlags(b, opts));
macho_step.dependOn(testHelloC(b, opts));
Expand Down Expand Up @@ -1069,6 +1070,52 @@ fn testFlatNamespaceWeak(b: *Build, opts: Options) *Step {
return test_step;
}

fn testForceLoad(b: *Build, opts: Options) *Step {
const test_step = b.step("test-macho-force-load", "");

const obj = cc(b, "a.o", opts);
obj.addCSource("int foo = 1;");
obj.addArg("-c");

const lib = ar(b, "liba.a");
lib.addFileSource(obj.getFile());

const main_o = cc(b, "main.o", opts);
main_o.addEmptyMain();
main_o.addArg("-c");

{
const exe = cc(b, "a.out", opts);
exe.addFileSource(main_o.getFile());
exe.addFileSource(lib.getFile());

const run = exe.run();
test_step.dependOn(run.step());

const check = exe.check();
check.checkInSymtab();
check.checkNotPresent("external _foo");
test_step.dependOn(&check.step);
}

{
const exe = cc(b, "a.out", opts);
exe.addFileSource(main_o.getFile());
exe.addArg("-force_load");
exe.addFileSource(lib.getFile());

const run = exe.run();
test_step.dependOn(run.step());

const check = exe.check();
check.checkInSymtab();
check.checkContains("external _foo");
test_step.dependOn(&check.step);
}

return test_step;
}

fn testHeaderpad(b: *Build, opts: Options) *Step {
const test_step = b.step("test-macho-headerpad", "");

Expand Down
2 changes: 1 addition & 1 deletion test/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub const SysCmd = struct {
}

pub fn addPrefixedFileSource(sys_cmd: SysCmd, prefix: []const u8, file: LazyPath) void {
sys_cmd.cmd.addPrefixedFileSourceArg(prefix, file);
sys_cmd.cmd.addPrefixedFileArg(prefix, file);
}

pub fn addDirectorySource(sys_cmd: SysCmd, dir: LazyPath) void {
Expand Down

0 comments on commit 5383423

Please sign in to comment.