Repository navigation
Conversation
neomantra
marked this pull request as draft
September 19, 2026 22:50
This adds stubs for the socket family of functions (socket, bind, connect, listen, accept, send*, recv*, etc.) so that programs using them can be linked, such as Go programs using golang.org/x/sys/unix. The sys/socket.h header requires machine/_param.h and net/net_kev.h from xnu, and a __darwin_socklen_t typedef which is added to the machine/_types.h replacement header. Signed-off-by: Evan Wies <evan@neomantra.net>
Signed-off-by: Evan Wies <evan@neomantra.net>
neomantra
force-pushed
the
add-sys-socket
branch
from
September 23, 2026 18:08
e7836db to
07dcfa6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tinygo-org/tinygo#5612 switches TinyGo to link against this SDK's real symbol list, which surfaced that no socket-family symbols are stubbed here: a Go program calling
unix.Socket(golang.org/x/sys/unix) now stops at link time with:(as noted in tinygo-org/tinygo#5612 (comment) — opening this PR as the follow-up instead of an issue.)
Changes, following the pattern of 4e4113e ("Add sys/sysctl.h header file and associated symbols"):
sys/socket.h,net/net_kev.h, andmachine/_param.hfrom the already-pinned xnu-7195.141.2 tarball (all APSL 2.0) and add them toupdate.sh.__darwin_socklen_tto the public-domainmachine/_types.hreplacement (src/_types.h), needed bysys/_types/_socklen_t.h.<sys/socket.h>fromsrc/libSystem.hand regeneratesrc/{arm64,x86_64}/libSystem.s. This adds 22 stubs: accept, bind, connect, connectx, disconnectx, getpeername, getsockname, getsockopt, listen, pfctlinput, recv, recvfrom, recvmsg, send, sendfile, sendmsg, sendto, setsockopt, shutdown, sockatmark, socket, socketpair.test/socket.ctomake test, compiling and linking asocket()/connect()call for both architectures (the failure mode from the review comment).Notes:
CMSG_*macros in sys/socket.h expand to__DARWIN_ALIGN32, which lives inarm/_param.h/i386/_param.h. Sincearm/_param.his intentionally emptied by update.sh (license), those macros are unusable on arm64 for now — same as the existing arm-specific gaps in this tree. Function declarations and everything x/sys/unix needs are unaffected.xnu-xnu-$version/root directory, so the extraction paths in update.sh no longer match freshly downloaded tarballs. I extracted the new headers with the same--strip-componentslayout; happy to fix update.sh separately if wanted.Verified with
make test CLANG=$(brew --prefix llvm)/bin/clangon macOS, plus an explicit-isysrootbuild of test/socket.c against the generated sysroots to confirm the new header itself parses (the default test invocation on macOS picks up host SDK headers), andllvm-nmshows the new symbols exported from the stub libSystem.B.dylib.