cpp/llvm: use selected LLVM metadata and qualify LLVM 22 - #27
cpp/llvm: use selected LLVM metadata and qualify LLVM 22#27zhouguangyuan0718 wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Code Review: Windows/MSVC/LLVM21 interop bindings
Solid, carefully-executed PR. The //go:build tags fully partition the platform space for every shared symbol I traced (LLGoPackage, Stdin/Stdout/Stderr, StatT, String, Errno, Long/Ulong), so no package ends up with a duplicate or missing definition on any platform. Struct layouts are backed by explicit size/offset tests, which I independently verified as correct: WSAData (400 on 386, 408 on x64), SockaddrStorage = 128, SockaddrIn6 = 28, SockAddr = 16, Hostent offsets, and the MSVC std::string layout (16 + 2×uintptr). The send/recv length parameter correctly uses c.Int on Winsock (vs size_t on POSIX), and the Freeaddrinfo return-type fix (void) matches the real C signature — no callers in the repo depended on the removed c.Int return.
Findings below are inline. A few lower-priority notes:
Bind/Connectsignature divergence. On Windows (c/net/functions_windows.go)Bindtakes*SockAddr, while the non-Windowsnet.godeclaresBind(..., addr *SockaddrIn, ...). The*SockAddrform is arguably more correct, but the inconsistency means portable call sites can't share one signature. Consider a doc note or aligning the Unix side in a follow-up.CanOnNamefield name inc/net/addrinfo_windows.gois a misspelling of the Winsockai_canonnamefield. It deliberately mirrors the same (pre-existing) misspelling inc/net/net.go, so fixing it here alone would create a Windows/Unix API divergence — worth a coordinated rename across both files rather than a one-sided change.- CI caching. Each matrix leg rebuilds
xgo-dev/llgo(pinned ref) from source with noactions/cache; caching keyed on the LLGo ref + OS + Go version would cut repeated cold compiles.
| - name: Set up LLGo dependencies | ||
| uses: ./.llgo/.github/actions/setup-deps | ||
| with: | ||
| llvm-version: '19' |
There was a problem hiding this comment.
[P1] CI installs LLVM 19 but Windows llvm config requires llvm-21
This step installs llvm-version: '19', but cpp/llvm/config_windows.go resolves its flags via pkg-config --cflags llvm-21 and pkg-config --libs llvm-21. The Windows test step runs ./cpp/llvm, so if the LLVM-19 install doesn't provide an llvm-21 pkg-config file, the Windows demangle bindings will fail to configure/link (or silently resolve against a different LLVM). Please align the installed llvm-version with the llvm-21 package the config expects (or parameterize both from one source).
| if value == nil { | ||
| t.Fatal("demangler returned nil") | ||
| } | ||
| defer c.Free(unsafe.Pointer(value)) |
There was a problem hiding this comment.
[P2] Possible cross-CRT free of demangler heap pointer on Windows
The demangle wrappers return heap pointers that LLVM allocates internally (via LLVM's CRT malloc), and callers free them with c.Free, which maps to libc free. On Windows the bridge is compiled against the MSVC CRT and linked to LLVM's MSVC-built binaries, while the LLGo target uses its own C runtime. If the malloc LLVM used and the free behind c.Free resolve to different CRT heaps, this is a cross-heap free (heap corruption). Please confirm both sides resolve to the same CRT heap, or add a matching llgoLLVMDemangleFree(char*) wrapper compiled in demangle_windows.cpp so the free happens on LLVM's heap.
|
|
||
| const ( | ||
| InvalidSocket SocketT = ^SocketT(0) | ||
| SocketError = -1 |
There was a problem hiding this comment.
[P3] SocketError left untyped while InvalidSocket is typed
InvalidSocket is typed SocketT, but SocketError = -1 is untyped. It is the sentinel returned by the c.Int-returning calls (Bind, Connect, etc.), so consider SocketError c.Int = -1 for consistency and to avoid accidental comparisons against unrelated int types.
adc184c to
5762a8b
Compare
1242f1d to
a8f1f82
Compare
Summary
llvmpkg-config alias for the Windows demangle bridge instead of a version-named packagellvm-config --host-target, the selected Windows C++ ABI, ordered LLVM libraries, and the C ABI boundary unchangedLLVM 22 qualification
6fc2ef150f95d8b9331433f325fcb1b6ee5ad4e4with the releasedgithub.com/xgo-dev/llvm v0.9.8,byollvm, and system LLVM 22llvm-configmajor 22 and passes its exact C/C++/link flags to the full Go build; the final link closure contains LLVM 22 onlyd96c2cc1736f4eb7fa43cb9bbdf56d93551a9ae0a9aadb9c99c3c3b2b712a234LLVMDemangle.lib, and executes Itanium, Microsoft, and Rust demangling checksValidation
Exact head
bdf7a1381373d3b8fc679c32bfb02da227fd93a6is clean and all four repository checks pass:Local validation also passed:
GOWORK=off go test ./...dev,byollvm;go build -xcontained LLVM 22 only./c,./c/math/rand,./c/net,./c/os,./c/setjmp,./c/time,./cpp/std, and./cpp/llvmLLVMDemanglegit diff --checkpassed