Use atexit() only if it's safe to call from shared library

Apparently they are not (advertised as?) safe on BSD systems.
We ignore the case of static libraries.

Whitelisted on glibc, Android, and MSVC / mingw.

https://bugs.freedesktop.org/show_bug.cgi?id=82246
This commit is contained in:
Behdad Esfahbod 2014-08-06 13:34:49 -04:00
parent d5e61470fa
commit 38fb30d742
6 changed files with 31 additions and 6 deletions

View File

@ -234,7 +234,7 @@ struct hb_language_item_t {
static hb_language_item_t *langs; static hb_language_item_t *langs;
#ifdef HAVE_ATEXIT #ifdef HB_USE_ATEXIT
static inline static inline
void free_langs (void) void free_langs (void)
{ {
@ -269,7 +269,7 @@ retry:
goto retry; goto retry;
} }
#ifdef HAVE_ATEXIT #ifdef HB_USE_ATEXIT
if (!first_lang) if (!first_lang)
atexit (free_langs); /* First person registers atexit() callback. */ atexit (free_langs); /* First person registers atexit() callback. */
#endif #endif

View File

@ -455,7 +455,7 @@ retry:
goto retry; goto retry;
} }
#ifdef HAVE_ATEXIT #ifdef HB_USE_ATEXIT
atexit (free_ft_library); /* First person registers atexit() callback. */ atexit (free_ft_library); /* First person registers atexit() callback. */
#endif #endif
} }

View File

@ -130,6 +130,31 @@
# define STRICT # define STRICT
#endif #endif
#if HAVE_ATEXIT
/* atexit() is only safe to be called from shared libraries on certain
* platforms. Whitelist.
* https://bugs.freedesktop.org/show_bug.cgi?id=82246 */
# if defined(__linux) && defined(__GLIBC_PREREQ)
# if __GLIBC_PREREQ(2,3)
/* From atexit() manpage, it's safe with glibc 2.2.3 on Linux. */
# define HB_USE_ATEXIT 1
# endif
# elif defined(_MSC_VER) || defined(__MINGW32__)
/* For MSVC:
* http://msdn.microsoft.com/en-ca/library/tze57ck3.aspx
* http://msdn.microsoft.com/en-ca/library/zk17ww08.aspx
* mingw32 headers say atexit is safe to use in shared libraries.
*/
# define HB_USE_ATEXIT 1
# elif defined(__ANDROID__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
/* This was fixed in Android NKD r8 or r8b:
* https://code.google.com/p/android/issues/detail?id=6455
* which introduced GCC 4.6:
* https://developer.android.com/tools/sdk/ndk/index.html
*/
# define HB_USE_ATEXIT 1
# endif
#endif
/* Basics */ /* Basics */

View File

@ -320,7 +320,7 @@ retry:
goto retry; goto retry;
} }
#ifdef HAVE_ATEXIT #ifdef HB_USE_ATEXIT
atexit (free_static_shaper_list); /* First person registers atexit() callback. */ atexit (free_static_shaper_list); /* First person registers atexit() callback. */
#endif #endif
} }

View File

@ -100,7 +100,7 @@ retry:
goto retry; goto retry;
} }
#ifdef HAVE_ATEXIT #ifdef HB_USE_ATEXIT
atexit (free_static_shapers); /* First person registers atexit() callback. */ atexit (free_static_shapers); /* First person registers atexit() callback. */
#endif #endif
} }

View File

@ -245,7 +245,7 @@ retry:
goto retry; goto retry;
} }
#ifdef HAVE_ATEXIT #ifdef HB_USE_ATEXIT
atexit (free_uniscribe_funcs); /* First person registers atexit() callback. */ atexit (free_uniscribe_funcs); /* First person registers atexit() callback. */
#endif #endif
} }