Skip to content

[libc] Fix atexit not getting linked on linux #98537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2024

Conversation

michaelrj-google
Copy link
Contributor

Atexit needs to be linked into exit on linux since atexit defines
__cxa_finalize. This should probably be fixed a different way but this
works for now.

Atexit needs to be linked into exit on linux since atexit defines
__cxa_finalize. This should probably be fixed a different way but this
works for now.
@llvmbot llvmbot added the libc label Jul 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2024

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

Atexit needs to be linked into exit on linux since atexit defines
__cxa_finalize. This should probably be fixed a different way but this
works for now.


Full diff: https://github.com/llvm/llvm-project/pull/98537.diff

1 Files Affected:

  • (modified) libc/src/stdlib/CMakeLists.txt (+11-2)
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index 5595664e90a56..2c13b7e4acdc9 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -497,6 +497,16 @@ add_entrypoint_object(
     .exit_handler
 )
 
+list(APPEND exit_deps
+  libc.src.__support.OSUtil.osutil
+  ._Exit
+)
+if (NOT LIBC_TARGET_OS_IS_BAREMETAL)
+  # list(APPEND exit_deps
+  #   .atexit
+  # )
+endif()
+
 add_entrypoint_object(
   exit
   SRCS
@@ -504,8 +514,7 @@ add_entrypoint_object(
   HDRS
     exit.h
   DEPENDS
-    ._Exit
-    libc.src.__support.OSUtil.osutil
+    ${exit_deps}
 )
 
 add_entrypoint_object(

@michaelrj-google michaelrj-google merged commit 8901c1c into llvm:main Jul 11, 2024
4 of 5 checks passed
@michaelrj-google michaelrj-google deleted the libcFixAtexit branch July 11, 2024 21:07
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
Atexit needs to be linked into exit on linux since atexit defines
__cxa_finalize. This should probably be fixed a different way but this
works for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants