Skip to content

Fix atexit/on_exit/_Exit#735

Draft
ZERICO2005 wants to merge 11 commits intomasterfrom
fix_atexit
Draft

Fix atexit/on_exit/_Exit#735
ZERICO2005 wants to merge 11 commits intomasterfrom
fix_atexit

Conversation

@ZERICO2005
Copy link
Contributor

@ZERICO2005 ZERICO2005 commented Mar 5, 2026

Fixes #734

  • Fixed return values from on_exit/atexit
  • Fixed the exit-status passed to on_exit functions via returning from main and via exit
  • Re-implemented C99 _Exit
  • Adds HAS_EXIT and HAS_C99__EXIT which will only include exit() and _Exit() in crt0.S if the functions are needed (similar to HAS_ABORT)

There are other issues that this PR does not fix, such as HAS_ABORT being 0 when abort is indirectly linked. Currently this PR just patches it so HAS_ABORT and HAS_EXIT are always set to 1 to prevent linker errors for the user. More here: #736

@ZERICO2005 ZERICO2005 marked this pull request as ready for review March 5, 2026 22:49
@ZERICO2005 ZERICO2005 marked this pull request as draft March 5, 2026 22:49
@ZERICO2005 ZERICO2005 mentioned this pull request Mar 5, 2026
@ZERICO2005 ZERICO2005 marked this pull request as ready for review March 5, 2026 22:54
@ZERICO2005 ZERICO2005 marked this pull request as draft March 5, 2026 23:00
@ZERICO2005
Copy link
Contributor Author

There are other problems that need to be resolved. I think if lto.s does not directly link _abort, then HAS_ABORT = 0. However, lto.s calls __ZNSt3__122__libcpp_verbose_abortEPKcz which does call _abort, but since HAS_ABORT = 0 there is no way for _abort to be emitted:

$ make
[cc] src/main.cpp
[lto] obj/lto.bc
[convimg] description
[linking] bin/DEMO.obj
C:\Users\zerico\Programming\ez80\toolchain\CEdev\binutils\bin\z80-none-elf-ld.exe: C:/Users/zerico/Programming/ez80/toolchain/CEdev/lib/libcxx/libcxx.a(abort_message.cpp.o): in function `___abort_message':
abort_message.cpp:(.text.___abort_message+0x1a): undefined reference to `_abort'
C:\Users\zerico\Programming\ez80\toolchain\CEdev\binutils\bin\z80-none-elf-ld.exe: C:/Users/zerico/Programming/ez80/toolchain/CEdev/lib/libcxx/libcxx.a(verbose_abort.o): in function `__ZNSt3__122__libcpp_verbose_abortEPKcz':
(.text+0xa): undefined reference to `_abort'
mingw32-make: *** [C:\Users\zerico\Programming\ez80\toolchain\CEdev\meta\makefile.mk:354: bin/DEMO.obj] Error 1

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

Development

Successfully merging this pull request may close these issues.

incorrect return value for atexit/on_exit

1 participant