Repository navigation
rt: the host name is rt_gethostname; the Windows runtime no longer defines the C symbol gethostname - #1756
Merged
Conversation
…fines the C symbol gethostname
rt/windows_x86_64.w (and windows_aarch64, wasm) defined `pub fn gethostname`
so rt_core's `@[link_name("gethostname")] extern fn rt_libc_gethostname`
resolved where there is no libc gethostname. FnAbi's
codegen_is_runtime_abi_symbol and CCodegen's cc_is_public_abi_name kept that
bare name. ws2_32.lib is on every Windows link (Link.w), and its gethostname
member defines both __imp_gethostname and the gethostname thunk. So:
- A C library that calls Winsock's gethostname (libcurl; any code built
against winsock2.h) references __imp_gethostname, pulls that member in,
and the link fails:
lld-link: error: duplicate symbol: gethostname
>>> defined at .../rt/windows_x86_64.w:878 out/tmp/with_runtime/rt_windows_x86_64.o
>>> defined at ws2_32.lib(WS2_32.dll)
llvm-nm: rt_windows_x86_64.o `T gethostname`; the C object
`U __imp_gethostname`; WS2_32.Lib member WS2_32.dll `T __imp_gethostname`,
`T gethostname`.
- With code that c_imports Winsock's gethostname links to the runtime's
function instead: before WSAStartup it returns 0 and the NetBIOS name,
where Winsock returns -1 with WSAGetLastError() == WSANOTINITIALISED.
Every backend now provides rt_gethostname, as it provides rt_getenv and
rt_sysinfo_os: Windows and wasm under the new name, same body; Linux and
Darwin forward to libc through @[link_name("gethostname")] extern fn
rt_libc_gethostname, whose domain row moves from rt_core's facade to theirs.
rt_core declares rt_gethostname. Nothing in rt/ defines a bare gethostname
now, so the name leaves codegen_is_runtime_abi_symbol and
cc_is_public_abi_name, and docs/with-abi.sha256 is re-recorded. No
WITH_ABI_VERSION bump: no produced symbol or pass mode changes.
test/behavior/behav_c_import_winsock_gethostname.w (only-on: windows) calls
Winsock's gethostname before and after WSAStartup and std.os.hostname() in
one program. On 3ccb998 it fails at line 19 (the runtime's function answers).
ehartford
force-pushed
the
josh/win-gethostname
branch
from
September 27, 2026 21:05
e7c7825 to
b7d2346
Compare
Contributor
|
Rebased onto Rebase.
windows-x86_64 (native Windows 10, VS 2026 Build Tools, pinned seed
linux-x86_64 (the pinned seed and SDK):
|
ehartford
marked this pull request as ready for review
September 27, 2026 21:06
ehartford
pushed a commit
to joshhickson/with
that referenced
this pull request
Sep 27, 2026
…#1756's name and takes this PR's UTF-8 body Both conflicts were the one Windows host-name function: main renamed it gethostname -> rt_gethostname so the runtime no longer defines Winsock's C symbol (withlang-dev#1756, eb2c86f); this branch rewrote its body to return the wide name as UTF-8 and to fail when it does not fit, and dropped the redundant `0 as u16` fill cast as it did at every other site. The resolution is main's name with this branch's body. rt_core.w merged cleanly (main's rt_gethostname extern, this branch's rt_args call; rt_args is defined in every backend). Checked: `with check --target=x86_64-pc-windows-msvc rt/windows_x86_64.w` and `--target=aarch64-pc-windows-msvc rt/windows_aarch64.w` are ok.
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.
Fixes #1755.
The Windows runtime defined
gethostnameso rt_core's@[link_name("gethostname")]extern resolved wherethere is no libc one.
ws2_32.libis on every Windows link, and itsgethostnamemember defines both__imp_gethostnameand agethostnamethunk, so:gethostname(libcurl) failed to link:duplicate symbol: gethostname,defined at
rt/windows_x86_64.w:878and atws2_32.lib(WS2_32.dll);gethostnamesilently called the runtime's (0 and the NetBIOS namebefore
WSAStartup, where Winsock answers -1 /WSANOTINITIALISED).Change. Every backend provides
rt_gethostname, as it providesrt_getenvandrt_sysinfo_os:rt/windows_x86_64.w,rt/windows_aarch64.w,rt/wasm.w:gethostname→rt_gethostname, same body.rt/linux_x86_64.w,rt/linux_aarch64.w,rt/darwin_aarch64.w:rt_gethostnameforwards to libcthrough
@[link_name("gethostname")] extern fn rt_libc_gethostname; its domain row moves here fromrt_core's facade (same
preserveslines).rt/rt_core.w:extern fn rt_gethostname;with_sysinfo_hostnamecalls it.src/FnAbi.w,src/CCodegen.w:"gethostname"leaves the runtime-ABI name lists; nothing inrt/defines it now.
docs/with-abi.sha256re-recorded. NoWITH_ABI_VERSIONbump: no produced symbol orpass mode changes. Happy to add a v6 entry if you read the list edit as a convention change.
test/behavior/behav_c_import_winsock_gethostname.w(only-on: windows): Winsock'sgethostnamebeforeand after
WSAStartup, andstd.os.hostname(), in one program.Evidence (native windows-x86_64). There is no Windows seed release that can evaluate main's build layer
(v0.15.2.1 fails with the four
build/selfhost.w"missing return" errors #1686 describes), so both runs weredriven by the same locally built compiler:
8db10d1abuilt by a334739d2build, then1e839443'ssources built with
8db10d1a's build layer.seed-driver, and thereforetest-green, refuse that driverby design in both runs.
3ccb998e+ the new teste7c78254abi-hash-checkpasses:fixpointspec_ss14_11_await_combinator_cancel_joins), deep-debug, contract-view, uat and examples failuresThe other failures reproduce on the unmodified base with the same driver.
unit-return-reviewis ok onboth clean trees.
with analyzeon the new test:audit:allok, 0 violations.The repros: the C-library program now links and
host_probereturns 0. The c_import program printsrc -1, WSAGetLastError 10093. The runtime objects:rt_windows_x86_64.odefinesrt_gethostnameand nogethostname.--targetbuilds for linux x86_64/aarch64 showU gethostname+T rt_gethostname, and forwindows aarch64
T rt_gethostname. Darwin and wasm could only be type-checked here (with check --no-prelude: ok). They still need a battery on those hosts.Not in this PR:
rt/windows_*.walso definepthread_self(the compiler calls it,src/compiler/LlvmBridge.w:445), which would collide the same way with a linked pthreads library.