WIP: Port dmd and druntime to GNU/Hurd#22829
Conversation
|
Thanks for your pull request and interest in making D better, @yelninei! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#22829" |
|
The error from the circleci is I guess this is expected, is there a way to regenerate the header? |
|
Re: regenerating the headers, if you read a few more lines down in that error message, you will see this:
Which refers to https://github.com/dlang/dmd/tree/master/compiler/src#cxx-headers-test |
I thought dmd triplet (tuples?) matched ldc. Historically, I guess gnu/hurd would be |
| /** | ||
| * D header file for GNU Hurd | ||
| * | ||
| * Copyright: Copyright Martin Nowak 2012. |
There was a problem hiding this comment.
Wrong year, wrong copyright. :-)
If unsure, please use:
Copyright: Copyright (c) 2026 D Language Foundation
| * | ||
| * Copyright: Copyright Martin Nowak 2012. | ||
| * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) | ||
| * Authors: Martin Nowak |
There was a problem hiding this comment.
I assume Martin didn't author this module.
There was a problem hiding this comment.
The file is a copy paste of the linux version with s/linux/hurd/
Is that enough to void the original copyright as it is clearly a derivative?
There was a problem hiding this comment.
I'm not qualified to say. In isolation, I don't consider the file big enough to warrant any copyright claim.
Rather, the body of work as a whole (this PR) ought to be considered as authored by the contributor.
| @@ -0,0 +1,25 @@ | |||
| module core.sys.hurd.unistd; | |||
There was a problem hiding this comment.
Some modules are missing comment headings/notices entirely. Others have inconsistent styles.
As these are newly introduced sources, I'd err towards not repeating previous bad habits, and pick one format, and use it consistently throughout all new files.
| } | ||
| else version (Hurd) | ||
| { | ||
| // What is needed here? |
There was a problem hiding this comment.
Any part of ioctls.h or ioctl-types.h that would be needed to interact with ioctl().
More than happy to commit them to a development branch under |
|
Fixed |
If you want to take a look they are here: https://codeberg.org/Yelninei/dmd/src/branch/version-1.112/patches Mostly the druntime change with minor gdc specific adjustments and then connecting things in configure and Makefile and regenerating them |
|
I think I found the reason for the crash. looking at one backtrace I noticed that it started from Through some divine intervention i then tried looking at my These come from Making these do nothing it stops crashing. To be continued. |
| @@ -0,0 +1,52 @@ | |||
| module core.sys.hurd.sys.types; | |||
There was a problem hiding this comment.
I think this file should be removed, and inline all the values where needed. It just looks odd to have a module with public symbols all starting with __.
| PTHREAD_PROCESS_PRIVATE = __pthread_process_shared.__PTHREAD_PROCESS_PRIVATE, | ||
| PTHREAD_PROCESS_SHARED = __pthread_process_shared.__PTHREAD_PROCESS_SHARED, |
There was a problem hiding this comment.
| PTHREAD_PROCESS_PRIVATE = __pthread_process_shared.__PTHREAD_PROCESS_PRIVATE, | |
| PTHREAD_PROCESS_SHARED = __pthread_process_shared.__PTHREAD_PROCESS_SHARED, | |
| PTHREAD_PROCESS_PRIVATE = 0, | |
| PTHREAD_PROCESS_SHARED, |
|
|
||
| struct pthread_condattr_t | ||
| { | ||
| __pthread_process_shared __pshared; |
There was a problem hiding this comment.
| __pthread_process_shared __pshared; | |
| int __pshared; |
|
|
||
| struct pthread_rwlockattr_t | ||
| { | ||
| __pthread_process_shared __pshared; |
There was a problem hiding this comment.
| __pthread_process_shared __pshared; | |
| int __pshared; |
|
|
||
| struct pthread_barrierattr_t | ||
| { | ||
| __pthread_process_shared __pshared; |
There was a problem hiding this comment.
| __pthread_process_shared __pshared; | |
| int __pshared; |
| PTHREAD_EXPLICIT_SCHED = __pthread_inheritsched.__PTHREAD_EXPLICIT_SCHED, | ||
| PTHREAD_INHERIT_SCHED = __pthread_inheritsched.__PTHREAD_INHERIT_SCHED, |
There was a problem hiding this comment.
| PTHREAD_EXPLICIT_SCHED = __pthread_inheritsched.__PTHREAD_EXPLICIT_SCHED, | |
| PTHREAD_INHERIT_SCHED = __pthread_inheritsched.__PTHREAD_INHERIT_SCHED, | |
| PTHREAD_EXPLICIT_SCHED = 0, | |
| PTHREAD_INHERIT_SCHED, |
| PTHREAD_CREATE_JOINABLE = __pthread_detachstate.__PTHREAD_CREATE_JOINABLE, | ||
| PTHREAD_CREATE_DETACHED = __pthread_detachstate.__PTHREAD_CREATE_DETACHED, |
There was a problem hiding this comment.
| PTHREAD_CREATE_JOINABLE = __pthread_detachstate.__PTHREAD_CREATE_JOINABLE, | |
| PTHREAD_CREATE_DETACHED = __pthread_detachstate.__PTHREAD_CREATE_DETACHED, | |
| PTHREAD_CREATE_JOINABLE = 0, | |
| PTHREAD_CREATE_DETACHED, |
| enum PTHREAD_MUTEX_NORMAL = __pthread_mutex_type.__PTHREAD_MUTEX_TIMED; | ||
| enum PTHREAD_MUTEX_ERRORCHECK = __pthread_mutex_type.__PTHREAD_MUTEX_ERRORCHECK; | ||
| enum PTHREAD_MUTEX_RECURSIVE = __pthread_mutex_type.__PTHREAD_MUTEX_RECURSIVE; |
There was a problem hiding this comment.
| enum PTHREAD_MUTEX_NORMAL = __pthread_mutex_type.__PTHREAD_MUTEX_TIMED; | |
| enum PTHREAD_MUTEX_ERRORCHECK = __pthread_mutex_type.__PTHREAD_MUTEX_ERRORCHECK; | |
| enum PTHREAD_MUTEX_RECURSIVE = __pthread_mutex_type.__PTHREAD_MUTEX_RECURSIVE; | |
| enum PTHREAD_MUTEX_NORMAL = 0; | |
| enum PTHREAD_MUTEX_ERRORCHECK = 1; | |
| enum PTHREAD_MUTEX_RECURSIVE = 2; |
| __pthread_mutex_protocol __protocol; | ||
| __pthread_process_shared __pshared; | ||
| __pthread_mutex_type __mutex_type; |
There was a problem hiding this comment.
| __pthread_mutex_protocol __protocol; | |
| __pthread_process_shared __pshared; | |
| __pthread_mutex_type __mutex_type; | |
| int __protocol; | |
| int __pshared; | |
| int __mutex_type; |
| PTHREAD_PRIO_NONE =__pthread_mutex_protocol.__PTHREAD_PRIO_NONE, | ||
| PTHREAD_PRIO_INHERIT =__pthread_mutex_protocol.__PTHREAD_PRIO_INHERIT, | ||
| PTHREAD_PRIO_PROTECT =__pthread_mutex_protocol.__PTHREAD_PRIO_PROTECT, |
There was a problem hiding this comment.
| PTHREAD_PRIO_NONE =__pthread_mutex_protocol.__PTHREAD_PRIO_NONE, | |
| PTHREAD_PRIO_INHERIT =__pthread_mutex_protocol.__PTHREAD_PRIO_INHERIT, | |
| PTHREAD_PRIO_PROTECT =__pthread_mutex_protocol.__PTHREAD_PRIO_PROTECT, | |
| PTHREAD_PRIO_NONE = 0, | |
| PTHREAD_PRIO_INHERIT, | |
| PTHREAD_PRIO_PROTECT, |
| struct pthread_attr_t | ||
| { | ||
| __sched_param schedparam; |
There was a problem hiding this comment.
| struct pthread_attr_t | |
| { | |
| __sched_param schedparam; | |
| private struct __sched_param | |
| { | |
| int __sched_priority; | |
| } | |
| private struct __pthread; | |
| struct pthread_attr_t | |
| { | |
| __sched_param schedparam; |
| ErrorFilter("core.stdc.math.double_t", "", "Hurd", 0, ""), | ||
| ErrorFilter("core.stdc.math.float_t", "", "Hurd", 0, ""), | ||
| ErrorFilter("core.stdc.signal.sig_atomic_t", "", "FreeBSD", 0, ""), | ||
| ErrorFilter("core.stdc.stdio.FILE", "", "FreeBSD", 0, ""), | ||
| ErrorFilter("core.stdc.stdio.FILE", "", "linux", 0, ""), | ||
| ErrorFilter("core.stdc.stdio._IO_FILE", "", "linux", 0, ""), | ||
| ErrorFilter("core.stdc.stdio.FILE", "", "Hurd", 0, ""), | ||
| ErrorFilter("core.stdc.stdio._IO_FILE", "", "Hurd", 0, ""), |
There was a problem hiding this comment.
these failures are inherited from CRuntime_Glibc
| @@ -0,0 +1,18 @@ | |||
| bytes allocated, allocations, type, function, file:line | |||
| 128 1 float profilegc.main src/profilegc.d:18 | |||
There was a problem hiding this comment.
this is a copy pase of the linux/freebsd one as the the test fails if the file is not present.
having duplicate files for different oses seems a bit weird to me.
|
The remaining test failures in druntime (phobos has some more, but i have not looked yet whether this is because of druntime or phobos)
all dmd compiler tests also pass. |
| version (X86) | ||
| { |
There was a problem hiding this comment.
Our old friend, indentation. :-)
| ushort __seq; | ||
| } | ||
| } | ||
| else |
There was a problem hiding this comment.
To be on the safe side, guard with (X86_64), then add
else
static assert(false, "Unsupported platform");Just in case someone decides to do aarch64-gnu or riscv-gnu.
| else | |
| else version (X86_64) |
| struct msg; | ||
| struct __wait_queue; |
There was a problem hiding this comment.
| struct msg; | |
| struct __wait_queue; | |
| private struct msg; | |
| private struct __wait_queue; |
No need to make these opaque types public.
I'd be almost inclined to actually use void* as the field type instead in the msqid_ds definition.
| else | ||
| alias ipc_pid_t = int; | ||
|
|
||
| struct __vm_area_struct; |
There was a problem hiding this comment.
| struct __vm_area_struct; | |
| private struct __vm_area_struct; |
| ushort __shm_npages; | ||
| c_ulong* __shm_pages; | ||
| __vm_area_struct* __attaches; |
There was a problem hiding this comment.
| ushort __shm_npages; | |
| c_ulong* __shm_pages; | |
| __vm_area_struct* __attaches; | |
| private ushort __shm_npages; | |
| private c_ulong* __shm_pages; | |
| private __vm_area_struct* __attaches; |
Fields not present in the POSIX standard should be private to the user.
https://pubs.opengroup.org/onlinepubs/007904875/basedefs/sys/shm.h.html
| _pthread_fastlock __sem_lock; | ||
| int __sem_value; | ||
| void* __sem_waiting; | ||
| enum __SIZEOF_SEM_T = 20; |
There was a problem hiding this comment.
| enum __SIZEOF_SEM_T = 20; | |
| private enum __SIZEOF_SEM_T = 20; |
| int __policy; | ||
| int[16] __pad; | ||
| } | ||
| struct __spawn_action; |
There was a problem hiding this comment.
| struct __spawn_action; | |
| private struct __spawn_action; |
| // This exists but always return 32 | ||
| // private extern (C) nothrow @nogc | ||
| // { | ||
| // int __libc_current_sigrtmin(); | ||
| // int __libc_current_sigrtmax(); | ||
| // } | ||
|
|
||
| // @property int SIGRTMIN()() nothrow @nogc { | ||
| // __gshared int sig = -1; | ||
| // if (sig == -1) { | ||
| // sig = __libc_current_sigrtmin(); | ||
| // } | ||
| // return sig; | ||
| // } | ||
|
|
||
| // @property int SIGRTMAX()() nothrow @nogc { | ||
| // __gshared int sig = -1; | ||
| // if (sig == -1) { | ||
| // sig = __libc_current_sigrtmax(); | ||
| // } | ||
| // return sig; | ||
| // } |
There was a problem hiding this comment.
My guess is this should be identical to the version (linux) path? Or just don't include this at all - same as OpenBSD.
There was a problem hiding this comment.
yes, but i think this is the gcc-11 version of the linux code.
this is how SIGRTMIN/SIGRTMAX are defined but currently SIGRTMIN == SIGRTMAX == 32 always so it is not useful.
This then caused problem for the gc as the default is using SIGRTMIN and SIGRTMIN + 1 for the suspend/resume signals which is an invalid signo.
I guess removing makes more sense and make it someone elses problem in the future.
|
I think I've managed to get through the entire lot. Just the open comments to address. |
|
@yelninei oh - and thanks for this herculean effort, and the patience. 🙇 |
|
I fixed This was pointed out on the bug-hurd thread. The importc_compare test does not seem to catch this. |
|
@ibuclaw thanks a lot for the very helpful feedback and dealing with my mess of whitespace issues :) |
|
i fixed a few things that were noticed by the probos tests. I went over all tests again to see if the failure is bercause of druntime:
druntime/test/shared: loadDR and host : fail somewhere in pthread . A flaky std/process test but not sure about that. The rest just works (with the linked minimal phobos patch). There are some things that could be done i.e. faking priority on the D side as is already done for netbsd but Ill leave that to someone in the future. This feels like a good place for the initial support to me and should make future updates and bugfixes a lot easier. I hope I can address your comments soon. |
Hi,
As announced on https://forum.dlang.org/thread/agrrykgbdsjlbsgjtatq@forum.dlang.org here is my WIP PR for porting druntime and dmd to GNU Hurd.
To be able to build also #22787 is needed.
Things that I know are still a bit of a mess:
version(linux)whereCRuntime_Glibcis used to mean linux + glibc.I am currently quite happy with the dmd part as all tests pass on 32bit and 64bit except
For the runtime some tests still crash in pthread_join, I am not entirely sure why as the same test outside of libdruntime_ut works fine.
On x86_64 the test runner gets killed after a while with the gc suspend signal, I dont know yet why the runtime does not handle it.
I am not erntirely sure about the format for the dmd triplet as it differs from both the gnu config and llvm triplet.
I have asked people on the bug-hurd mailing list for help as well
https://lists.gnu.org/archive/html/bug-hurd/2026-03/msg00274.html
https://lists.gnu.org/archive/html/bug-hurd/2026-03/msg00275.html
There are some more things needed to bring this back into gdc,