Skip to content

fakecgo: use libthr.so.3 instead of libpthread.so on FreeBSD#481

Merged
hajimehoshi merged 1 commit into
ebitengine:mainfrom
rcina:fix-freebsd-libpthread
Jul 18, 2026
Merged

fakecgo: use libthr.so.3 instead of libpthread.so on FreeBSD#481
hajimehoshi merged 1 commit into
ebitengine:mainfrom
rcina:fix-freebsd-libpthread

Conversation

@rcina

@rcina rcina commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

What issue is this addressing?

Closes #480

What type of issue is this addressing?

bug

What this PR does | solves

FreeBSD 15 removed the libpthread.so compatibility symlink (historically
a symlink to libthr.so) from base. This left any Go binary built with
CGO_ENABLED=0 using purego's FreeBSD fakecgo path with an unresolvable
NEEDED entry for libpthread.so, since it no longer exists anywhere on
FreeBSD 15+.

This change updates gen.go to target libthr.so.3 — FreeBSD's actual
threading implementation, present since at least FreeBSD 12.x — instead
of libpthread.so, and regenerates zsymbols_freebsd.go accordingly via
go generate.

Tested on FreeBSD 15.1-STABLE amd64:

  • examples/libc builds cleanly with CGO_ENABLED=0
  • readelf -d confirms NEEDED libthr.so.3 (no more libpthread.so)
  • the built binary runs correctly ("Calling C from Go without Cgo!")

I haven't touched netbsd's zsymbols (same libpthread.so string appears
there too) since I don't have a NetBSD system to verify the correct
replacement library name — flagging that as a possible follow-up if
maintainers know the right target.

@hajimehoshi

Copy link
Copy Markdown
Member

Resolve the conflicts

FreeBSD 15 removed the libpthread.so compatibility symlink to libthr.so
from base. This caused Go binaries built with CGO_ENABLED=0 using
purego's FreeBSD fakecgo path to have an unresolvable NEEDED entry for
libpthread.so.

libthr.so.3 is FreeBSD's actual threading implementation and has been
present since at least FreeBSD 12.x. Updated gen.go and regenerated
zsymbols_freebsd.go accordingly.

Tested on FreeBSD 15.1-STABLE amd64: examples/libc builds and runs
correctly with CGO_ENABLED=0, and readelf confirms the binary now links
against libthr.so.3 instead of libpthread.so.
@rcina
rcina force-pushed the fix-freebsd-libpthread branch from 853a2cd to 77319b6 Compare July 18, 2026 13:02

@TotallyGamerJet TotallyGamerJet left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Files not reviewed (2)
  • internal/fakecgo/gen.go: Generated file
  • internal/fakecgo/zsymbols_freebsd.go: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rcina

rcina commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

Yes, I'd really appreciate that — a stable-branch cherry-pick would let
downstream consumers (like wandb, which is what led me to find this)
pick up the fix via a patch release rather than waiting for the next
purego release. Thanks for offering!

@hajimehoshi hajimehoshi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@hajimehoshi

Copy link
Copy Markdown
Member

Yes, I'd really appreciate that — a stable-branch cherry-pick would let
downstream consumers (like wandb, which is what led me to find this)
pick up the fix via a patch release rather than waiting for the next
purego release. Thanks for offering!

Is this a reply for the original issue?

@hajimehoshi
hajimehoshi merged commit d476432 into ebitengine:main Jul 18, 2026
25 checks passed
hajimehoshi pushed a commit that referenced this pull request Jul 18, 2026
…#481)

FreeBSD 15 removed the libpthread.so compatibility symlink to libthr.so
from base. This caused Go binaries built with CGO_ENABLED=0 using
purego's FreeBSD fakecgo path to have an unresolvable NEEDED entry for
libpthread.so.

libthr.so.3 is FreeBSD's actual threading implementation and has been
present since at least FreeBSD 12.x. Updated gen.go and regenerated
zsymbols_freebsd.go accordingly.

Tested on FreeBSD 15.1-STABLE amd64: examples/libc builds and runs
correctly with CGO_ENABLED=0, and readelf confirms the binary now links
against libthr.so.3 instead of libpthread.so.

Closes #480
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FreeBSD/NetBSD fakecgo hardcodes "libpthread.so" via go:cgo_import_dynamic, which doesn't exist on FreeBSD 15+

4 participants