Commit dd6afb9
committed
fix: load gopy extensions with RTLD_LOCAL to prevent Go runtime interposition
On macOS, Python's default dlopen flags are RTLD_NOW|RTLD_GLOBAL
(Py_RTLD_DEFAULT in configure.ac for Darwin). Every .so extension
imported via the normal Python import machinery is therefore loaded into
the process-wide flat namespace. When two gopy extensions are loaded in
the same process, the second extension's Go runtime symbols (TLS keys,
mheap_, cgo init pointers) get interposed by the first extension's
definitions, causing the two independent Go runtimes to share GC state
and triggering 'fatal error: bad sweepgen in refill' (issue #385).
The generated Python wrapper now temporarily clears RTLD_GLOBAL before
importing the underlying _<pkg>.so, so each extension's Go runtime keeps
its own isolated copy of these globals. The original flags are restored
immediately after import so the rest of the program is unaffected.1 parent 5072ba0 commit dd6afb9
1 file changed
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
320 | 333 | | |
| 334 | + | |
| 335 | + | |
321 | 336 | | |
322 | 337 | | |
323 | 338 | | |
| |||
0 commit comments