Skip to content

Add NetBSD support - #1972

Merged
andrewrk merged 3 commits into
ziglang:masterfrom
coypoop:netbsd
Feb 18, 2019
Merged

andrewrk merged 3 commits into
ziglang:masterfrom
coypoop:netbsd

Conversation

@coypoop

@coypoop coypoop commented Feb 17, 2019

Copy link
Copy Markdown
Contributor

Mostly picking the same paths as FreeBSD.
We need a little special handling for crt files, as netbsd uses its
own (and not GCC's) for those, with slightly different names.

While running the tests I think it's building the self-hosted zig, I had to explicitly link against /usr/lib/libstdc++.a:

env LD_LIBRARY_PATH=/usr/pkg/lib /home/fly/zig/build/bin/zig build-exe /home/fly/zig/src-self-hosted/main.zig --object /home/fly/zig/build/zig_cpp/libzig_cpp.a --object /home/fly/zig/build/zig_cpp/libembedded_lld_wasm.a --object /home/fly/zig/build/zig_cpp/libembedded_lld_elf.a --object /home/fly/zig/build/zig_cpp/libembedded_lld_coff.a --object /home/fly/zig/build/zig_cpp/libembedded_lld_lib.a --cache-dir /home/fly/zig/zig-cache --output /home/fly/zig/zig-cache/zig --name zig --library c --library LLVM-7 -isystem /home/fly/zig/src -isystem /home/fly/zig/build --object /usr/lib/libstdc++.a -isystem /usr/pkg/include --library-path /usr/pkg/lib

Otherwise it was emitting errors like:

lld: error: undefined symbol: operator delete(void*)
>>> referenced by OutputSections.h:102 (/home/fly/zig/deps/lld/wasm/OutputSections.h:102)
>>>               OutputSections.cpp.o:(lld::wasm::DataSection::~DataSection()) in archive /home/fly/zig/build/zig_cpp/libembedded_lld_wasm.a

lld: error: undefined symbol: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()
>>> referenced by OutputSections.h:88 (/home/fly/zig/deps/lld/wasm/OutputSections.h:88)
>>>               OutputSections.cpp.o:(lld::wasm::CodeSection::~CodeSection()) in archive /home/fly/zig/build/zig_cpp/libembedded_lld_wasm.a

lld: error: undefined symbol: operator delete(void*)
>>> referenced by OutputSections.h:88 (/home/fly/zig/deps/lld/wasm/OutputSections.h:88)
>>>               OutputSections.cpp.o:(lld::wasm::CodeSection::~CodeSection()) in archive /home/fly/zig/build/zig_cpp/libembedded_lld_wasm.a

The following command exited with error code 1:
/home/fly/zig/build/bin/zig build-exe /home/fly/zig/src-self-hosted/main.zig --object /home/fly/zig/build/zig_cpp/libzig_cpp.a --object /home/fly/zig/build/zig_cpp/libembedded_lld_wasm.a --object /home/fly/zig/build/zig_cpp/libembedded_lld_elf.a --object /home/fly/zig/build/zig_cpp/libembedded_lld_coff.a --object /home/fly/zig/build/zig_cpp/libembedded_lld_lib.a --cache-dir /home/fly/zig/zig-cache --output /home/fly/zig/zig-cache/zig --name zig --library c --library LLVM-7 -isystem /home/fly/zig/src -isystem /home/fly/zig/build -isystem /usr/pkg/include --library-path /usr/pkg/lib

Build failed. The following command failed:
/home/fly/.local/share/zig/stage1/artifact/UYlxOUzNCbMTc5_2CnyaMaY4eSw8e8wMEwO0FiSkJ1Qe03FlWCmKZJ8MFNdrhJGV/build /home/fly/zig/build/bin/zig /home/fly/zig /home/fly/zig/zig-cache test

(Also, the LD_LIBRARY_PATH is a substitute for an RPATH for libLLVM-7.so)

Mostly picking the same paths as FreeBSD.
We need a little special handling for crt files, as netbsd uses its
own (and not GCC's) for those, with slightly different names.
@coypoop

coypoop commented Feb 17, 2019

Copy link
Copy Markdown
Contributor Author

I haven't found out whether it's safe to do bc10382#diff-3ce0315ddf9ec17d0e8a5f5a4fcaf8b7R286 but it hasn't bitten me yet

@andrewrk

Copy link
Copy Markdown
Member

Thanks for sending the patch upstream! I enjoyed reading your blog article.

I'll have time to go over this pull request tomorrow (Monday).

Can you confirm that you double checked all the structs and function prototypes with your system header files (as opposed to copying them straight from FreeBSD)? It's OK if you didn't - we can either delete the not-double-checked ones if they're unused, or I don't mind doing it, I'll just have to rent a VPN for an hour. I just want to avoid something like 7a4ed10 which was not a straightforward debug process.

@andrewrk

Copy link
Copy Markdown
Member

I believe EVFILT_USER is necessary for std.event.Loop to function correctly, but we're all waiting for copy-elision/coroutine rewrite before getting back into event-based code. I do think it's better to not define a meaningless constant and set it to 0 - that's surprising behavior. Better behavior is to leave the places that try to use EVFILT_USER a compile error, and then disable the tests for that code. Don't pretend it works if it doesn't!

@coypoop

coypoop commented Feb 17, 2019

Copy link
Copy Markdown
Contributor Author

Yes, I reviewed all the structs and defines rather than copying.

@andrewrk
andrewrk merged commit 3e58626 into ziglang:master Feb 18, 2019
@andrewrk

andrewrk commented Feb 18, 2019 •

Copy link
Copy Markdown
Member

Great work! Thanks for your contribution.

Looks like we need to go add a new column to the README support table, thanks to you. (done)

Comment thread std/os/netbsd/errno.zig
pub const EBADF = 9; // Bad file descriptor
pub const ECHILD = 10; // No child processes
pub const EDEADLK = 11; // Resource deadlock avoided
// 11 was EAGAIN

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean "was"? It seems to be 35 now.
When did it change? Why did it change?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a comment from the original file in /usr/include/sys/errno.h, same thing on OpenBSD.

Comment thread std/os/netbsd/errno.zig
pub const ELOOP = 62; // Too many levels of symbolic links
pub const ENAMETOOLONG = 63; // File name too long

// should be rearranged

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning of this comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I pulled it straight out of the errno.h header in netbsd. I assumed the comments are going to be meaningful, but missed that this one isn't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants