Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing --stack to zig test makes the getrlimit/setrlimit test case fail #18395

Closed
andrewrk opened this issue Dec 29, 2023 · 3 comments · Fixed by #19051
Closed

passing --stack to zig test makes the getrlimit/setrlimit test case fail #18395

andrewrk opened this issue Dec 29, 2023 · 3 comments · Fixed by #19051
Labels
bug Observed behavior contradicts documented or intended behavior os-macos standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Dec 29, 2023

$ stage3/bin/zig test ../lib/std/std.zig --stack 16777216
Test [775/2593] test.getrlimit and setrlimit... FAIL (LimitTooBig)
/Users/andy/dev/zig/lib/std/os.zig:7130:19: 0x100e045b3 in setrlimit (test)
        .INVAL => return error.LimitTooBig, // this could also mean "invalid resource", but that would be unreachable
                  ^
/Users/andy/dev/zig/lib/std/os/test.zig:773:13: 0x100e03eb3 in test.getrlimit and setrlimit (test)
            try os.setrlimit(resource, limit);
            ^

zig/lib/std/os/test.zig

Lines 754 to 776 in b0dba46

test "getrlimit and setrlimit" {
if (!@hasDecl(os.system, "rlimit")) {
return error.SkipZigTest;
}
inline for (std.meta.fields(os.rlimit_resource)) |field| {
const resource = @as(os.rlimit_resource, @enumFromInt(field.value));
const limit = try os.getrlimit(resource);
// On 32 bit MIPS musl includes a fix which changes limits greater than -1UL/2 to RLIM_INFINITY.
// See http://git.musl-libc.org/cgit/musl/commit/src/misc/getrlimit.c?id=8258014fd1e34e942a549c88c7e022a00445c352
//
// This happens for example if RLIMIT_MEMLOCK is bigger than ~2GiB.
// In that case the following the limit would be RLIM_INFINITY and the following setrlimit fails with EPERM.
if (comptime builtin.cpu.arch.isMIPS() and builtin.link_libc) {
if (limit.cur != os.linux.RLIM.INFINITY) {
try os.setrlimit(resource, limit);
}
} else {
try os.setrlimit(resource, limit);
}
}
}

It has something to do with these lines:

grep -RI stack_size_override ../src/link/MachO*
../src/link/MachO/zld.zig:    const stack_size = options.stack_size_override orelse 0;
../src/link/MachO/zld.zig:                    .stacksize = macho_file.base.options.stack_size_override orelse 0,
../src/link/MachO.zig:                .stacksize = self.base.options.stack_size_override orelse 0,

This is problematic because we want to be able to control the stack size from the compiler/linker. Relevant issues:

cc @kubkon

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library. os-macos labels Dec 29, 2023
@andrewrk andrewrk added this to the 0.13.0 milestone Dec 29, 2023
@nektro
Copy link
Contributor

nektro commented Dec 29, 2023

to me the trace makes it look like the error is from picking a number larger than ulimit -s, not intrinsic to passing --stack.

andrewrk added a commit that referenced this issue Dec 29, 2023
@mikdusan
Copy link
Member

THIS. IS. APPLE. KERNEL.

        case RLIMIT_STACK:
                if (p->p_lflag & P_LCUSTOM_STACK) {
                        /* Process has a custom stack set - rlimit cannot be used to change it */
                        error = EINVAL;
                        goto out;
                }

source: https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/bsd/kern/kern_resource.c#L1173-L1178

@andrewrk
Copy link
Member Author

Nice, OK that's fine actually. We just need to not call setrlimit on the stack size in that std lib test.

andrewrk added a commit that referenced this issue Dec 29, 2023
andrewrk added a commit that referenced this issue Jan 1, 2024
andrewrk added a commit that referenced this issue Jan 2, 2024
andrewrk added a commit that referenced this issue Jan 2, 2024
andrewrk added a commit that referenced this issue Jan 2, 2024
andrewrk added a commit that referenced this issue Jan 2, 2024
mikdusan added a commit to mikdusan/zig that referenced this issue Feb 23, 2024
- skip only RLIMIT_STACK test on macos

closes ziglang#18395
mikdusan added a commit to mikdusan/zig that referenced this issue Feb 24, 2024
- skip only RLIMIT_STACK test on macos

closes ziglang#18395
andrewrk pushed a commit that referenced this issue Feb 25, 2024
- skip only RLIMIT_STACK test on macos

closes #18395
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Feb 25, 2024
Rexicon226 pushed a commit to Rexicon226/zig that referenced this issue Feb 25, 2024
- skip only RLIMIT_STACK test on macos

closes ziglang#18395
RossComputerGuy pushed a commit to ExpidusOS-archive/zig that referenced this issue Mar 20, 2024
- skip only RLIMIT_STACK test on macos

closes ziglang#18395
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-macos standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants