ワールドニュース strat_ai_server
-
Static C linking without Cgo: Automating Plan 9 stubs and libc-free .syso objects from Go-syntax glue
golangbridge | 2026-09-04 15:23 | id : 160998
Cgo provides access to native C code, but at a well-known cost: it breaks straightforward cross-compilation, complicates single-binary distribution, and incurs runtime invocation overhead from switching between goroutine stacks and OS threads. For dynamic linking, tools like PureGo solved this on Unix, and standard runtime lazy DLLs handle Windows. However, for static linking without Cgo (CGO_ENABLED=0), the available path has always been painful: writing manual Plan 9 assembly stubs and stitching together raw object files. I built a toolchain called Hike (hikec) to automate this pipeline end-to-end. It allows you to write low-level C-ABI compatible routines and glue logic using Go syntax, automatically emitting Plan 9 assembly stubs and clean .syso files that go build merges directly into the final binary. The Go linker (cmd/link) has a built-in feature: any name_GOOS_GOARCH.syso file placed inside a package directory is statically linked into the final binary, even when Cgo is completely disabled. Making this work requires solving two problems: 1. ABI Mismatch: Go’s internal ABI differs from standard C ABIs (e.g., Windows x64 ABI or System V AMD64 ABI). A Plan 9 assembly stub must bridge register assignments, allocate shadow stack space, and pass return values back to the Go frame pointer. 2. Zero Libc / CRT Dependencies: Because the pure Go linker does not link against the C runtime, the .syso file cannot contain any unresolved external symbols (such as malloc, printf, or platform-specific probes like ___chkstk_ms). Instead of writing C glue and hand-crafting Plan 9 assembly, you write .go.hike files using standard Go syntax with a cfunc keyword: ```go package fizzlib // Standard C-ABI exported function cfunc GetFizzFileSize(fn_ptr cstring, fn_len int) int { return 15 } // passthrough: Emits NOSPLIT in assembly, executing directly // on the goroutine stack with zero context-switching overhead passthrough cfunc GetMetaData(fn_ptr cstring, fn_len int, outLen *int) cstring { \*outLen = 4 return "fizz" } ``` Running `hikec go ./fizzlib` executes the following pipeline: 1. LLVM IR Generation: Compiles the Hike AST into LLVM IR. 2. Dead-Code Elimination (-O2): Unused runtime symbols (e.g., libc allocations) are completely eliminated by the optimizer. 3. Probe Suppression: Clang compiles the IR with -mno-stack-arg-probe to suppress Windows CRT stack-probe helper symbols. 4. Assembly Stub Generation: Automatically generates stub_windows_amd64.s handling the register setup (mapping Go arguments from FP to CX, DX, R8, R9 and reserving 32 bytes of shadow space). 5. Output: Produces fizzlib_windows_amd64.syso and stub_windows_amd64.s directly in the package directory. The assembly bridge generated by the compiler looks like this: ```plan9 #include “textflag.h” // GetFizzFileSize TEXT ·_hike_GetFizzFileSize(SB), 0, $32-24 MOVQ ptr_arg+0(FP), CX MOVQ len_arg+8(FP), DX SUBQ $32, SP CALL c_GetFizzFileSize(SB) ADDQ $32, SP MOVQ AX, ret+16(FP) RET // GetMetaData (passthrough: NOSPLIT) TEXT ·_hike_GetMetaData(SB), NOSPLIT, $32-32 MOVQ fn_ptr_arg+0(FP), CX MOVQ fn_len_arg+8(FP), DX MOVQ outLen_arg+16(FP), R8 SUBQ $32, SP CALL c_GetMetaData(SB) ADDQ $32, SP MOVQ AX, ret+24(FP) RET ``` In Go, you interact with the package using standard idiomatic Go code (fizzlib.go): ```go package fizzlib import “unsafe” //go:noescape func _hike_GetFizzFileSize(ptr unsafe.Pointer, length int) int //go:noescape func _hike_GetMetaData(fn unsafe.Pointer, fnLen int, outLen *int) unsafe.Pointer func GetFizzFileSize(filename string) int { p := unsafe.StringData(filename) return \_hike_GetFizzFileSize(unsafe.Pointer(p), len(filename)) } func GetMetaData(filename string) string { p := unsafe.StringData(filename) var outLen int resPtr := \_hike_GetMetaData(unsafe.Pointer(p), len(filename), &outLen) if resPtr == nil || outLen == 0 { return "" } return string(unsafe.Slice((\*byte)(resPtr), outLen)) } ``` Running `go build` or `go run` produces a single static binary without needing GCC, MinGW, or CGO_ENABLED=1. Constraints & Scope: * Leaf Functions & Stack Budgets: Functions marked with passthrough execute directly on the calling goroutine’s stack (NOSPLIT). Large stack allocations must be avoided or allocated on the Go side. * No Libc Calls: The static native code cannot call arbitrary standard library C functions like malloc or printf unless those implementations are bundled into the .syso without external symbol references. * Platform Support: Currently tested and validated on Windows x86_64. Extending to Linux/macOS System V AMD64 ABI requires adapting the register mapping sequence in the stub generator (DI, SI, DX, CX, R8, R9). 2 posts - 2 participants Read full topic
-
Germany urges EU to cut Russians’ holiday visas after sabotage attacks
guardian_world | 2026-09-04 15:22 | id : 151921
Belarusian said to have had tourist visa issued by Italy is investigated over alleged attempt to attack Leipzig airportGermany is urging its European partners to introduce tighter limitations on Russian citizens entering the EU on tourist visas, after recent sabotage attacks which Berlin has blamed on Moscow.German authorities are investigating a Belarusian national, who also holds a Russian passport, over the alleged attempt to attack Leipzig airport using drones and explosives. Continue reading...
-
India's NSE eyes September 21-week listing after regulator clears IPO, sources say - Reuters
reuters_world | 2026-09-04 15:16 | id : 151778
India's NSE eyes September 21-week listing after regulator clears IPO, sources say Reuters
-
Israel releases five detainees to Lebanon after US-mediated negotiations
aljazeera_all | 2026-09-04 15:16 | id : 151896
Israel has released five people to Lebanon after US-mediated negotiations. Dozens of Lebanese remain detained by Israel.
-
EXCLUSIVE: Nigeria's Dangote seeks around $1.5 billion with refinery IPO, sources say - Reuters
reuters_world | 2026-09-04 15:15 | id : 151794
EXCLUSIVE: Nigeria's Dangote seeks around $1.5 billion with refinery IPO, sources say Reuters
-
China rare earth firms halt some US shipments over geopolitical worries, sources say - Reuters
reuters_world | 2026-09-04 15:15 | id : 151753
China rare earth firms halt some US shipments over geopolitical worries, sources say Reuters
-
Israelis shoot dead two Palestinian teenagers after settlers encircle village
guardian_world | 2026-09-04 15:12 | id : 151924
Troops escort settlers into al-Mughayyir and raze village outside Hebron as ethnic cleansing of West Bank continuesIsraelis have shot dead two teenagers in a Palestinian village encircled by settlers, and Israeli troops have razed an entire village outside Hebron, in the latest attacks in a surge of Israeli terror and ethnic cleansing across the occupied West Bank.The shootings targeted Khalil Abu Alia, 16, who was about to start 11th grade at the al-Mughayyir boys school, and 19-year-old Omar al-Nassan, who graduated from the same institution with top marks this summer. Continue reading...
-
EXCLUSIVE: Hedge fund giant Citadel seeking to buy US shale oil production assets, sources say - Reuters
reuters_world | 2026-09-04 15:12 | id : 151783
EXCLUSIVE: Hedge fund giant Citadel seeking to buy US shale oil production assets, sources say Reuters
-
Australia’s housing prices are trending down. See which suburbs have had the biggest falls
guardian_world | 2026-09-04 15:00 | id : 151914
Cotality says prices have declined in most capital cities over winter. Search the data to see how they have changed in your areaGet our breaking news email, free app or daily news podcastAustralia’s property market is facing a rare price correction, as rising interest rates and less favourable tax settings for investors accelerate a downturn.Most capital cities recorded winter price falls, according to Cotality data, with Sydney leading the decline. That weakness is expected to continue, as higher inflation could lead to further interest rate hikes, denting demand. Continue reading...
-
三省堂書店の池袋本店 12月末閉店へ
dmenu_business | 2026-09-04 14:58 | id : 151868
-
Israeli investors in crosshairs of Argentina's Milei over Falklands oil project - reuters.com
reuters_world | 2026-09-04 14:52 | id : 151930
Israeli investors in crosshairs of Argentina's Milei over Falklands oil project reuters.com
-
Israel frees four more Lebanese prisoners in Red Cross-mediated handover
aljazeera_all | 2026-09-04 14:50 | id : 151897
Lebanese President Joseph Aoun praises the release and thanks US President Donald Trump for his efforts.
-
ASX.AX - | Stock Price & Latest News - Reuters
reuters_business | 2026-09-04 14:45 | id : 151958
ASX.AX - | Stock Price & Latest News Reuters
-
露がデンマーク国民勧誘 破壊工作に
dmenu_world | 2026-09-04 14:41 | id : 151835
-
'A rare moment of joy': Nepal tunnel rescues bring hope for more flood survivors
bbc_world | 2026-09-04 14:40 | id : 151792
There are still hundreds of workers trapped in a network of tunnels that run along the Trishuli river.
-
Why is Farage’s Reform accused of violating the UK’s foreign funding rules?
aljazeera_all | 2026-09-04 14:38 | id : 151898
Undercover footage allegedly shows top Reform officials discussing ways to evade foreign funding laws.
-
Deadly escalation in Black Sea attacks prompts fears of even higher food prices
guardian_world | 2026-09-04 14:35 | id : 151922
Russian and Ukrainian strikes in July killed more crew than in whole war to that month, preventing grain exportsA summer of hostilities in the Black Sea proved deadly for seafarers, as Russia and Ukraine attacked each other’s ships and port infrastructure, preventing vital grain exports and prompting concerns that the conflict will push global food prices even higher.More crew were killed in the Black Sea in July than during the entirety of the war before that month as the conflict has intensified, making the body of water the most dangerous in the world for commercial shipping. This is despite the conflict between the US and Iran, with vessels still being targeted in the strait of Hormuz, Red Sea and Gulf of Aden. Continue reading...
-
VGTL.PK - | Stock Price & Latest News - Reuters
reuters_business | 2026-09-04 14:32 | id : 152129
VGTL.PK - | Stock Price & Latest News Reuters
-
氷河崩落の兆候あった 研究チーム
dmenu_world | 2026-09-04 14:32 | id : 151836
-
DMPG.H - Reuters
reuters_business | 2026-09-04 14:30 | id : 151942
DMPG.H Reuters
-
Stellantis in talks with Huawei, JAC over Maserati partnership, sources say - Reuters
reuters_world | 2026-09-04 14:17 | id : 151809
Stellantis in talks with Huawei, JAC over Maserati partnership, sources say Reuters
-
Body of King Oyo Nyimba, once world's youngest monarch, returns to Uganda for burial - Reuters
reuters_world | 2026-09-04 14:15 | id : 151949
Body of King Oyo Nyimba, once world's youngest monarch, returns to Uganda for burial Reuters
-
Lululemon shares dive on risks of prolonged overhaul under new CEO - Reuters
reuters_world | 2026-09-04 14:09 | id : 151766
Lululemon shares dive on risks of prolonged overhaul under new CEO Reuters
-
露 侵攻批判者への締め付け強化
dmenu_world | 2026-09-04 14:03 | id : 151837
-
Can the Green Party’s Polanski take on Labour and win Starmer’s old seat?
aljazeera_all | 2026-09-04 13:59 | id : 151899
Analysts say although Polanski has gained popularity, toppling Labour in its traditional stronghold may be difficult.
-
Woman, 45, killed in Florence in seventh alleged femicide in Italy since mid-August
guardian_world | 2026-09-04 13:56 | id : 151923
Lorena Isceri was thrown off a motorway bridge, allegedly by ex-boyfriend Federico VellaA 45-year-old woman abducted and thrown off a motorway bridge near Florence has become the seventh alleged femicide in Italy since mid-August.Lorena Isceri was abducted on Thursday afternoon, allegedly by her ex-boyfriend, Federico Vella, in the Rifredi area of Florence, before being forced into the boot of his car and driven towards a bridge on the A1 motorway.In the UK, Samaritans can be contacted on freephone 116 123 and the domestic abuse helpline is 0808 2000 247. In the US, the suicide prevention lifeline is 988 and the domestic violence hotline is 1-800-799-SAFE (7233). In Australia, the crisis support service Lifeline is on 13 11 14 and the national family violence counselling service is on 1800 737 732. Other international helplines can be found via www.befrienders.org Continue reading...
-
002371.SZ - | Stock Price & Latest News - Reuters
reuters_business | 2026-09-04 13:55 | id : 151944
002371.SZ - | Stock Price & Latest News Reuters
-
Colombia president provokes disgust by posing with bodies of ‘terrorists’
guardian_world | 2026-09-04 13:50 | id : 151910
Abelardo De La Espriella posts video of himself with rows of body bags as performative populism continues to sweep AmericasColombia’s hardline president, Abelardo De La Espriella, has provoked outrage after posting a video on social media in which he strides through rows of white body bags that he says contained the corpses of 23 “neutralised” guerrillas.De La Espriella took power last month vowing “all-out war” against illegal armed groups and he published the footage on Thursday in an apparent attempt to show he was fulfilling that pledge. Continue reading...
-
B9BG.F - Reuters
reuters_business | 2026-09-04 13:49 | id : 151943
B9BG.F Reuters
-
SGRX.OQ - | Stock Price & Latest News - Reuters
reuters_business | 2026-09-04 13:44 | id : 151951
SGRX.OQ - | Stock Price & Latest News Reuters