Skip to content

SIGSEGV on exit with unix port #539

@ozobotnovako

Description

@ozobotnovako

Describe the bug
When i execute the unix binary, the process seems to work fine, but throws SIGSEGV when on exit. This happens both when I run a script or when I just enter and exit REPL without any commands.

Simple repro steps:

$ build/lvgl_micropy_unix -c 'import sys; print(sys.implementation)'
(name='micropython', version=(1, 27, 0, ''), _machine='linux [GCC 15.2.1] version', _mpy=2822, _build='standard', _thread='unsafe')
fish: Job 1, 'build/lvgl_micropy_unix -c 'imp…' terminated by signal SIGSEGV (Address boundary error)

By examining gdb output, I found a workaround. It's enough to construct a machine.Timer object before the interpreter quits:

$ build/lvgl_micropy_unix -c 'import machine; machine.Timer(0); import sys; print(sys.implementation)'
(name='micropython', version=(1, 27, 0, ''), _machine='linux [GCC 15.2.1] version', _mpy=2822, _build='standard', _thread='unsafe')

As seen in the gdb output, the program crashes in machine_timer_deinit_all():

__pthread_clockjoin_ex (threadid=0, thread_return=thread_return@entry=0x0, 
    clockid=clockid@entry=0, abstime=abstime@entry=0x0, block=block@entry=true)
    at pthread_join_common.c:43
43	  if (INVALID_NOT_TERMINATED_TD_P (pd))
(gdb) bt
#0  __pthread_clockjoin_ex (threadid=0, thread_return=thread_return@entry=0x0, 
    clockid=clockid@entry=0, abstime=abstime@entry=0x0, block=block@entry=true)
    at pthread_join_common.c:43
#1  0x00007ffff7d15043 in ___pthread_join (threadid=<optimized out>, 
    thread_return=thread_return@entry=0x0) at pthread_join.c:24
#2  0x000055555571def6 in machine_timer_deinit_all () at machine_timer.c:94
#3  0x000055555571aaae in main_ (argc=argc@entry=1, argv=argv@entry=0x7fffffffb4e8)
    at main.c:731
#4  0x000055555571abc2 in main (argc=1, argv=0x7fffffffb4e8) at main.c:468

Expected behavior
The process quits without SIGSEGV.

Exact make and model number

unix port
Fedora 43 x86_64

Build Command

python make.py unix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions