aboutsummaryrefslogtreecommitdiff
path: root/include/u.h
diff options
context:
space:
mode:
authorNicholas <nbnoll@eml.cc>2021-11-20 17:07:23 -0800
committerNicholas <nbnoll@eml.cc>2021-11-20 17:07:23 -0800
commitc9a32c1a43d2bdded07eaa45732c3a6e195a5442 (patch)
treecb7e9cb8c34cbe6551b801eff4201afcf71dd0fd /include/u.h
parente97c8c469db0aa27985dab2879dc1f14905c7387 (diff)
Chore: cleaned up the exit code to cleanly interface with libc
We use weak linking to ensure we clean up at exit time correctly. If libc is linked, then we call our cleanup function by registering an atexit callback with the library. If libc is not linked, we have a weak symbol that results in a noop. Similarly, if we call rt·exit while linked with libc, this immediately calls libc's exit (which will call our cleanup as we registered it). If we are not linked to libc, exit() is given as a weak link to a noop function.
Diffstat (limited to 'include/u.h')
-rw-r--r--include/u.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/u.h b/include/u.h
index d415d82..fe251ac 100644
--- a/include/u.h
+++ b/include/u.h
@@ -112,6 +112,7 @@ typedef __builtin_va_list va_list;
#define noreturn _Noreturn
#define hidden __attribute__((__visibility__("hidden")))
#define weakalias(old, new) extern __typeof(old) new __attribute__((weak, alias(#old)))
+#define weaklink __attribute__((weak))
/* offsets */
#define offsetof(t, d) __builtin_offsetof(t, d)