Skip to content

OpenBSD port - #5324

Closed
abdelq wants to merge 12 commits into
ziglang:masterfrom
abdelq:openbsd
Closed

abdelq wants to merge 12 commits into
ziglang:masterfrom
abdelq:openbsd

Conversation

@abdelq

@abdelq abdelq commented May 12, 2020 •

Copy link
Copy Markdown

First time contribution, a follow-up to #1921. This requires OpenBSD -current or 6.7 (related to #4803), which is slated for release on the 19th. Furthermore, LLVM 10 also needs to be compiled.

Sadly, as it stands, I couldn't get Zig to compile properly (excerpt follows):

[ 98%] Building CXX object CMakeFiles/zig0.dir/src/main.cpp.o
[ 98%] Building CXX object CMakeFiles/zig0.dir/src/stage2.cpp.o
[ 99%] Linking CXX executable zig0
[ 99%] Built target zig0
Scanning dependencies of target zig_build_libstage2
zig0:/usr/lib/../lib/libc++abi.so.2.1: undefined symbol '__sF'
zig0:/usr/lib/../lib/libc++.so.4.0: undefined symbol '__sF'
zig0:/usr/lib/../lib/libm.so.10.1: undefined symbol '_ctype_'
zig0:/usr/lib/../lib/libpthread.so.26.1: undefined symbol '__isthreaded'
zig0:/usr/lib/../lib/libpthread.so.26.1: undefined symbol '_thread_sys_fork'
zig0:/usr/lib/../lib/libpthread.so.26.1: undefined symbol '_thread_sys_vfork'
zig0:/usr/lib/../lib/libcurses.so.14.0: undefined symbol '_ctype_'
zig0:/usr/lib/../lib/libcurses.so.14.0: undefined symbol '__isthreaded'
zig0:/usr/lib/../lib/libcurses.so.14.0: undefined symbol '__sF'
zig0:/usr/lib/../lib/libz.so.5.0: undefined symbol '__isthreaded'
zig0:/usr/lib/../lib/libedit.so.5.2: undefined symbol '__isthreaded'
zig0:/usr/lib/../lib/libedit.so.5.2: undefined symbol '__sF'
zig0:/usr/lib/../lib/libedit.so.5.2: undefined symbol '_ctype_'
zig0:/usr/lib/libLLVM-10.so: /home/julius/zig/build/zig0 : WARNING: symbol(_ZTVNSt3__110__function6__baseIFiRKN4llvm5ErrorEEEE) size mismatch, relink your program
zig0:/usr/lib/libLLVM-10.so: /home/julius/zig/build/zig0 : WARNING: symbol(_ZTVNSt3__110__function6__baseIFyvEEE) size mismatch, relink your program
zig0:/usr/lib/libLLVM-10.so: /home/julius/zig/build/zig0 : WARNING: symbol(_ZTVNSt3__110__function6__baseIFbjRKN4llvm6ModuleEEEE) size mismatch, relink your program
zig0:/usr/lib/libLLVM-10.so: /home/julius/zig/build/zig0 : WARNING: symbol(_ZTVNSt3__110__function6__baseIFN4llvm5ErrorERNS2_11raw_ostreamEEEE) size mismatch, relink your program
zig0:/usr/lib/libLLVM-10.so: /home/julius/zig/build/zig0 : WARNING: symbol(_ZTVNSt3__110__function6__baseIFNS_10unique_ptrIN4llvm3lto18NativeObjectStreamENS_14default_deleteIS5_EEEEjEEE) size mismatch, relink your program
zig0:/usr/lib/libLLVM-10.so: /home/julius/zig/build/zig0 : WARNING: symbol(_ZTVNSt3__110__function6__baseIFvN4llvm13IRBuilderBase11InsertPointEEEE) size mismatch, relink your program
zig0:/usr/lib/libLLVM-10.so: /home/julius/zig/build/zig0 : WARNING: symbol(_ZTVNSt3__110__function6__funcIPFvRKN4llvm18PassManagerBuilderERNS2_6legacy15PassManagerBaseEENS_9allocatorISA_EES9_EE) size mismatch, relink your program
zig0:/usr/lib/libLLVM-10.so: /home/julius/zig/build/zig0 : WARNING: symbol(_ZTVNSt3__110__function6__baseIFvvEEE) size mismatch, relink your program
Segmentation fault (core dumped)

Running a debugger yields:

Error while reading shared library symbols:
Dwarf Error: wrong version in compilation unit header (is 4, should be 2) [in module /usr/libexec/ld.so]

Breakpoint 2, issetugid () at -:3
3	in -
(gdb) step

Breakpoint 2, issetugid () at -:3
3	in -
(gdb)
_libc_pthread_self () at /usr/src/lib/libc/thread/rthread.c:105
105	/usr/src/lib/libc/thread/rthread.c: No such file or directory.
	in /usr/src/lib/libc/thread/rthread.c
Current language:  auto; currently minimal
(gdb)
43		__asm__ ("movq %%fs:(%1),%0" : "=r" (val) : "r" (offset));
(gdb)
Die: DW_TAG_unspecified_type (abbrev = 22, offset = 4638166)
	has children: FALSE
	attributes:
		DW_AT_name (DW_FORM_strp) string: "decltype(nullptr)"

I've tried a few things to no avail. Looking for other people's input (@mikdusan? @jreut?), hence opening this draft PR.

@abdelq
abdelq force-pushed the openbsd branch 2 times, most recently from 7225bf1 to 2f5b8ca Compare May 12, 2020 05:56
@mikdusan

Copy link
Copy Markdown
Member

zig0:/usr/lib/libLLVM-10.so

First get zig building against static llvm/clang/lld libraries. There are many ways to build llvm and we don't ensure our cmake can deal with them all. It can deal with a minimalist static build of llvm and my brain cannot recall if llvm can be built with both static/dynamic libraries, please don't do so even if llvm allows it.

If it helps, around time of #4803 I have an llvm-tarball that was linking zig0. It's here .

Comment thread lib/std/fs.zig
Comment on lines +1677 to +1681
var prg_name = argv[0];
if (prg_name[0] == '/' or prg_name[0] == '.') {
return os.realpathZ(prg_name, out_buffer);
}
prg_name = mem.spanZ(prg_name);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This code assumes pathname beginning with . is a path component of either . or .. but it could also be a dot-named file. Let's use std.mem.indexOfScalar(..., '/') to detect idx == 0 or "." or ".." here.

Comment thread src/os.cpp
Comment on lines +1620 to +1623
if (*prg_name == '/' || *prg_name == '.') {
buf_init_from_str(tmp, prg_name);
return os_path_real(tmp, out_path);
} else {

@mikdusan mikdusan May 12, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here. handle 3 cases explicitly as lib/std/fs.zig equivalent

Comment thread src/os.cpp
// Look for the program in the set of directories
char *path, *paths = buf_ptr(tmp);
while ((path = strsep(&paths, ":")) != nullptr) {
snprintf(out, PATH_MAX, "%s/%s", path, prg_name);

@mikdusan mikdusan May 12, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • use buf_sprintf instead of snprintf
  • use memSplit instead of strsep

Comment thread lib/std/fs.zig
},
.openbsd => {
// OpenBSD has no support for this. Out of the various tried methods,
// the only working workaround comes from stackoverflow.com/a/31495527

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.

It's better to not implement this at all then it is to have a workaround.

@andrewrk

andrewrk commented Jul 5, 2020

Copy link
Copy Markdown
Member

I suggest to take advantage of zig's lazy top level declaration analysis, and the fact that we don't have any OpenBSD CI tests to regress, and break this into a series of smaller changes, landing your progress into master branch. Progress towards another operating system support does not have to be in one giant PR that does everything, you can make progress one piece at a time. This will prevent a situation like this right now, where an entire body of work is abandoned, even though it has plenty of useful changes which could have easily landed in master.

Thanks for your work, I hope we can get some of it landed.

@andrewrk andrewrk closed this Jul 5, 2020
@justjosias justjosias mentioned this pull request Jul 22, 2020
9 of 10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

os-openbsd OpenBSD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants