-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Progress towards tier 1 support for FreeBSD x86_64 #1859
Conversation
Since the stable kernel ABI is through libc ziglang#1759
All supported versions of FreeBSD have libc++ in the base system.
Remove all syscalls references * dup2() * chdir() * execve() * fork() * getcwd() * isatty() * readlink() * mkdir() * mmap() * munmap() * read() * rmdir() * symlink() * pread() * write() * pwrite() * rename() * open() * close() * lseek() * exit() * unlink() * waitpid() * nanosleep() * setreuid() * setregid() * raise() * fstat() * pipe() * added pipe2() extern c fn
The system call getrandom(2) just landed on FreeBSD 12, so if we want to support some earlier version or at least FreeBSD 11, we can't depend on the system call.
FreeBSD doesn't mount procfs as default on the base system, so we can't depend on it to get the current path, In this case, we use sysctl(3) to retrieves the system information and get the same information. - CTL_KERN: High kernel limits - KERN_PROC: Return selected information about specific running processes. - KERN_PROC_PATHNAME: The path of the process - Process ID: a process ID of -1 implies the current process.
Stack trace is partially working, with only a few symbols missing. Uses the same functions that we use in Linux to get the necessary debug info.
Fix dirent/stat, add preadv
Use libc interface for: - getdents - kill - openat - setgid - setuid
Prior to this fix, the compare-outputs test suite was showing a strange behavior, the tests always stopped between tests 6-8 and had a stack track similar to each other. ``` Test 8/68 compare-output multiple files with private function (ReleaseSmall)...OK /usr/home/mgxm/dev/zig/zig-cache/source.zig:7:2: error: invalid token: '&' }&(getStdOut() catch unreachable).outStream().stream; ^ The following command exited with error code 1: ``` With the wrong O_* flags, the source code was being written in append mode which resulted in an invalid file ```zig use @import("foo.zig"); use @import("bar.zig"); pub fn main() void { foo_function(); bar_function(); }&(getStdOut() catch unreachable).outStream().stream; stdout.print("OK 2\n") catch unreachable; } fn privateFunction() void { printText(); } ```
Looks like the problem is in trying to cross compile, targeting FreeBSD.
We'll have to figure out how to target FreeBSD on non-FreeBSD operating systems to continue zig's promise of "use any target to build for any target". However you don't have to solve this problem in this PR. One step at a time is OK, and this PR already does a lot. |
I completely forgot about that, I will work on it too There's anything I can do? |
Yeah, for now, remove it from the test matrix, and manually add the native tests in the CI script:
And then do these with --release-fast, --release-small, and --library c variants. |
Don't expect anything that touches the filesystem to work on both when the filesystem structures are defined for 12 :) I think it's fine to not support versions older than 12 in a young language.
You can't cross-link without having the libraries. Try extracting the system https://download.freebsd.org/ftp/snapshots/amd64/12.0-STABLE/base.txz into some directory and passing (You can only extract lib directories: (btw do you target macOS from non-macOS operating systems?) |
@@ -116,7 +116,7 @@ pub fn getRandomBytes(buf: []u8) !void { | |||
else => return unexpectedErrorPosix(errno), | |||
} | |||
}, | |||
Os.macosx, Os.ios => return getRandomBytesDevURandom(buf), | |||
Os.macosx, Os.ios, Os.freebsd => return getRandomBytesDevURandom(buf), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: FreeBSD 12 has getrandom, I used it on purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use getrandom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because getrandom just landed on FreeBSD 12 and I was considering we were going to support version 11, but as @myfreeweb said if it's ok to no support, we can bring it back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks.
I think it's fine to not support versions older than 12 in a young language.
I agree with this statement.
Yes, and it works, although LLD is not great at mach-o files. The newest darwin versions do not require the crt1.o startup files or anything like that.
We're going to have to provide these in source form (probably ported to zig, just like we do with compiler-rt) and have the ability to build them for any target. |
A whole |
A whole libc for any target is #514. But that's not needed for FreeBSD cross compilation. Only crt1.o & friends, compatible with the FreeBSD libc is necessary. That's a much smaller component. These .o files are statically linked into executables when building against FreeBSD libc. Try it for yourself with the system compiler and look at the linker line. So your ABI question would apply to using C with the system compiler as much as it would apply to Zig here. |
- Manually add all the native tests to CI manifest.
I removed the FreeBSD from the test matrix and added the native's tests as |
Looks good! I'm ready to merge this if the tests passed for you locally. Looks like the CI failure was a temporary hiccup. |
test ../std/index.zig will fail, clock-related functions need to be implemented yet. |
That's ok, let's disable that test for this PR and then part of tier 1 support is working on those tests. |
I'm ready to merge this, do you consider it ready @mgxm? |
Yes, but because I made a mess running the tests in the beginning, I think we My apologies for the confusion. |
No worries! This patch still represents significant progress. Thank you for your contribution. |
Continuing the work already done by @tiehuis and @myfreeweb, I have completed
some missing points to finish the Tier 1 support. One of the
main points was that we get rid of all the syscalls and now we are using the
libc interface, which is the stable ABI.
Almost all tests are passing, missing
only one to fix and which I'm workinga lot of fixes. The said test is the test-cli, which works on FreeBSD 12 but fails onon
FreeBSD 11.
FreeBSD 11 Stack Trace