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

OpenBSD port #5324

Closed
wants to merge 12 commits into from
Closed

OpenBSD port #5324

wants to merge 12 commits into from

Conversation

abdelq
Copy link

@abdelq abdelq commented May 12, 2020

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
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 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
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 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 {
Copy link
Member

@mikdusan mikdusan May 12, 2020

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

// 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);
Copy link
Member

@mikdusan mikdusan May 12, 2020

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

@@ -1655,6 +1664,48 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
// TODO could this slice from 0 to out_len instead?
return mem.spanZ(@ptrCast([*:0]u8, out_buffer));
},
.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
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
Copy link
Member

andrewrk commented Jul 5, 2020

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.

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

Successfully merging this pull request may close these issues.

5 participants