Commit 5072ba0
committed
fix: restrict exported symbols in final .so to prevent Go runtime interposition
When two gopy extensions are loaded in the same Python process via
RTLD_GLOBAL, Go runtime data globals (mcache0, allm, mheap_, etc.) from
the first-loaded library win in the dynamic-linker global namespace.
The second runtime's references to those globals are silently redirected,
so both runtimes share the same heap metadata. This corrupts sweep-
generation counters and causes:
fatal error: bad sweepgen in refill
on macOS x86_64 / Go ≥1.24 (the earlier pthread mutex fix serialised
user code but could not stop background GC goroutines that also hit the
shared globals).
Fix: pass a symbol-visibility restriction to the final go build step so
that only PyInit__<name> is exported into the global namespace:
- macOS: -extldflags=-Wl,-exported_symbols_list,<file>
- Linux: -extldflags=-Wl,--version-script,<file>
All CGo bridge symbols (crosscall2, _cgo_topofstack, …) remain in the
.so and are called directly at link time; they no longer pollute the
global namespace and cannot be interposed by a second extension.
Fixes #370 / #385.1 parent 2f3f1ba commit 5072ba0
1 file changed
Lines changed: 40 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
188 | 191 | | |
189 | 192 | | |
190 | 193 | | |
191 | 194 | | |
192 | 195 | | |
193 | | - | |
| 196 | + | |
194 | 197 | | |
195 | 198 | | |
196 | 199 | | |
| |||
214 | 217 | | |
215 | 218 | | |
216 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
217 | 256 | | |
218 | 257 | | |
219 | 258 | | |
| |||
0 commit comments