This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add exit and atexit
ClosedPublic

Authored by abrachet on Feb 10 2022, 9:01 PM.

Details

Summary

Often atexit is implemented using __cxa_atexit. I have not implemented __cxa_atexit here because it potentially requires more discussion. It is unique for llvm-libc (I think) that it is an exported symbol that wouldn’t be defined in any spec file because it doesn’t have a header. Implementing it will be trivial given what is here already, but I figured it would be more contentious so it can be implemented later.

Diff Detail

Event Timeline

abrachet created this revision.Feb 10 2022, 9:01 PM
lntue accepted this revision.Feb 11 2022, 6:32 AM
lntue added inline comments.
libc/test/src/stdlib/CMakeLists.txt
204–236

if these tests need LLVM_LIBC_FULL_BUILD, why don't you wrap them entirely inside if(LLVM_LIBC_FULL_BUILD) instead of early return? This might be surprising for someone adding new tests to the end of the file.

This revision is now accepted and ready to land.Feb 11 2022, 6:32 AM
abrachet updated this revision to Diff 407900.Feb 11 2022, 8:56 AM
  • Rebase
  • Add locks
  • Add deadlock test

Few notes:

  1. I see an empty diff between 407760 and 407900.
  2. While not required for this patch __cxa_atexit need not be considered as an entry point. You can implement it in a helper object library.
  3. We should not need LLVM_LIBC_HAS_MALLOC. It is not setup that way now so we should fix it before we end up with a lot of these conditionals. One should be able to use allocators from another libc even in full mode.
abrachet updated this revision to Diff 408503.Feb 14 2022, 10:44 AM
  • Upload correct diff...
  • Ensure correct locking
  • Add functions to the spec files
michaelrj added inline comments.Feb 14 2022, 11:49 AM
libc/src/stdlib/atexit.cpp
10

please run clang format on this patch before committing.

abrachet updated this revision to Diff 409679.Feb 17 2022, 8:56 AM

clang-format

lntue accepted this revision.Feb 17 2022, 9:11 AM
lntue accepted this revision.Feb 17 2022, 9:19 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2022, 9:24 AM