]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
build: Add a new libbsd_strong_alias() macro and switch users to it
authorGuillem Jover <guillem@hadrons.org>
Sun, 2 Apr 2023 20:33:25 +0000 (22:33 +0200)
committerGuillem Jover <guillem@hadrons.org>
Mon, 17 Apr 2023 02:12:42 +0000 (04:12 +0200)
We had several cases of code needing a strong alias, so we switch those
to use the new macro. This covers systems that support the alias
attribute and others such as macOS where we need to use assembler
directives to add the alias as the attribute is not supported.

src/local-link.h
src/setproctitle.c

index 7e9053be94d0e2ce9942f767987fd708f4b982eb..a05d5edf404afb19d1bceae47e8edec837816a1d 100644 (file)
 #define libbsd_link_warning(symbol, msg)
 #endif
 
+#if defined(__APPLE__)
+#define libbsd_strong_alias(alias, symbol) \
+       __asm__(".globl _" #alias); \
+       __asm__(".set _" #alias ", _" #symbol); \
+       extern __typeof(symbol) alias
+#elif !defined(_MSC_VER)
+#define libbsd_strong_alias(alias, symbol) \
+       extern __typeof__(symbol) alias __attribute__((__alias__(#symbol)))
+#endif
+
 #ifdef __ELF__
 #  if __has_attribute(symver)
 /* The symver attribute is supported since gcc 10.x. */
@@ -64,7 +74,7 @@
 #  endif
 #else
 #define libbsd_symver_default(alias, symbol, version) \
-       extern __typeof__(symbol) alias __attribute__((__alias__(#symbol)))
+       libbsd_strong_alias(alias, symbol)
 
 #define libbsd_symver_variant(alias, symbol, version)
 
index 64ff92a96c0e89edb0dc4a5d19e060ef13420bfd..3aff0649ca2f691b7833b00242463dcb16eaaeb2 100644 (file)
@@ -295,10 +295,8 @@ libbsd_symver_default(setproctitle, setproctitle_impl, LIBBSD_0.5);
  * in 0.5, make the implementation available in the old version as an alias
  * for code linking against that version, and change the default to use the
  * new version, so that new code depends on the implemented version. */
-#ifdef HAVE_TYPEOF
-extern __typeof__(setproctitle_impl)
-setproctitle_stub
-       __attribute__((__alias__("setproctitle_impl")));
+#if defined(libbsd_strong_alias)
+libbsd_strong_alias(setproctitle_stub, setproctitle_impl);
 #else
 void
 setproctitle_stub(const char *fmt, ...)