← index #962PR #18979
Related · high · value 2.654
QUERY · ISSUE

Unix port: ffilib.py: libc.so.6 is no longer the latest version

openby hiwayopened 2025-01-11updated 2026-03-23

While using os.popen() from unix-ffi libraries on FreeBSD 14.1-RELEASE-p5 amd64, I encountered this error:

...
  File "os/__init__.py", line 32, in <module>
  File "ffilib.py", line 43, in libc
  File "ffilib.py", line 39, in open
  File "ffilib.py", line 33, in open
OSError: [Errno 2] ENOENT

On further investigation, I found that libc major version has been upgraded to 7, and ffilib.py is only looking for versions up to 6.

$ ls /lib/libc.so*
/lib/libc.so.7

https://github.com/micropython/micropython-lib/blob/e4cf09527bce7569f5db742cf6ae9db68d50c6a9/unix-ffi/ffilib/ffilib.py#L42

Changing the 6 to 7 fixed the issue.

Only making a note here since the readme for unix-ffi says: "This directory is unmaintained." and I would like to have a reference come up in searches when someone encounters the error.

4 comments
agatti · 2026-03-22

Indeed (as this also applies to 15.0-RELEASE). That's also something that needs to be changed in MicroPython's own test suite, along with other minor things like moving part of the default sys.path from /usr/lib/micropython to /usr/local/lib/micropython, and recognising FreeBSD as its own thing rather than classify that as Linux.

I believe some of these changes are already part of the patches in the ports tree, but last time I checked they still package a relatively old version. It won't hurt to have them in the source tree themselves.

dpgeorge · 2026-03-23

This is fixed in _libc but still needs to be fixed in ffilib.

agatti · 2026-03-23

Right! I can fix that right now but then I'd have to fix it again if https://github.com/micropython/micropython/pull/18979 gets merged. In ffilib there's a check for sys.platform and that PR will make it return freebsd, invalidating any small-scale change I'd make. I can also make it look for either linux or freebsd for the lookup to occur but then it'll take up bytes for nothing if that PR won't make the cut.

I don't mind submitting multiple PRs over time, but maybe you may want to schedule the changes differently.

dpgeorge · 2026-03-23

I can fix that right now but then I'd have to fix it again if micropython/micropython#18979 gets merged.

Yes, I see that now.

We are on the cusp of a release so can't make big changes. I think all this can be postponed until after the release.

CANDIDATE · PULL REQUEST

unix: Improve support for FreeBSD.

openby agattiopened 2026-03-22updated 2026-03-23
port-unix

Summary

This PR addresses a few minor issues related to MicroPython on the FreeBSD platform:

  • FFI tests tried to open a now missing libc library version (libc.so.6 is no longer there, now it's called libc.so.7)
  • The system-wide entry in sys.path for the standard library pointed to /usr/lib/micropyhon, but on FreeBSD anything outside the base system files has to reside elsewhere; the usual root under /usr for third party packages is /usr/local
  • sys.platform now reports it's running on FreeBSD instead of Linux
  • The interpreter banner recognises FreeBSD as a separate platform and sets the correct libc name
  • platform.platform now reports FreeBSD as the operating system
  • The EDEADLK result code returned on failed lock acquisition is handled, aliased to EBUSY at the moment
  • The extmod/select_poll_fd test is skipped on FreeBSD

<hr>

This is technically the continuation of https://github.com/micropython/micropython-lib/pull/1099, as it fixes FFI support on recent FreeBSD versions in micropython/micropython-lib.

Testing

The test suite was executed in a FreeBSD 15.0-RELEASE x64 virtual machine, with no FFI-related test failures. thread/thread_heap_lock, and thread/thread_lock5 were failing before these changes as well. I haven't yet looked into those two tests.

Trade-offs and Alternatives

The changes in this PR should affect MicroPython's behaviour exclusively when built on FreeBSD. FFI and sys.path changes might also apply to OpenBSD, NetBSD, and their derivatives, but they weren't tested on those OSes.

Generative AI

I did not use generative AI tools when creating this PR.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied