Commit 890699a78b892a8591cd465f97d4967ee94d54c9

Guillem Jover 2019-08-06T18:51:45

build: Abstract symbol versioning via new libbsd_symver_* macros This makes it more obvious what they are doing. It will make it easier to make these directives more portable, as they are really ELF specific.

diff --git a/src/local-link.h b/src/local-link.h
index 5f3c0fd..5a17bfe 100644
--- a/src/local-link.h
+++ b/src/local-link.h
@@ -30,4 +30,11 @@
 #define libbsd_link_warning(symbol, msg) \
 	static const char libbsd_emit_link_warning_##symbol[] \
 		__attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg;
+
+#define libbsd_symver_default(alias, symbol, version) \
+	__asm__(".symver " #symbol "," #alias "@@" #version)
+
+#define libbsd_symver_variant(alias, symbol, version) \
+	__asm__(".symver " #symbol "," #alias "@" #version)
+
 #endif
diff --git a/src/setproctitle.c b/src/setproctitle.c
index 6329bf4..ff32aa3 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -31,6 +31,7 @@
 #include <err.h>
 #include <unistd.h>
 #include <string.h>
+#include "local-link.h"
 
 static struct {
 	/* Original value. */
@@ -280,7 +281,7 @@ setproctitle_impl(const char *fmt, ...)
 		*++nul = '\0';
 	}
 }
-__asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5");
+libbsd_symver_default(setproctitle, setproctitle_impl, LIBBSD_0.5);
 
 /* The original function introduced in 0.2 was a stub, it only got implemented
  * in 0.5, make the implementation available in the old version as an alias
@@ -295,4 +296,4 @@ void
 setproctitle_stub(const char *fmt, ...)
 	__attribute__((__alias__("setproctitle_impl")));
 #endif
-__asm__(".symver setproctitle_stub,setproctitle@LIBBSD_0.2");
+libbsd_symver_variant(setproctitle, setproctitle_stub, LIBBSD_0.2);
diff --git a/src/unvis.c b/src/unvis.c
index ae963aa..166421a 100644
--- a/src/unvis.c
+++ b/src/unvis.c
@@ -42,6 +42,8 @@
 #include <vis.h>
 #pragma GCC diagnostic pop
 
+#include "local-link.h"
+
 #ifdef __weak_alias
 __weak_alias(strnunvisx,_strnunvisx)
 #endif
@@ -566,11 +568,11 @@ strnunvis_openbsd(char *dst, const char *src, size_t dlen)
 {
 	return strnunvisx(dst, dlen, src, 0);
 }
-__asm__(".symver strnunvis_openbsd,strnunvis@@LIBBSD_0.2");
+libbsd_symver_default(strnunvis, strnunvis_openbsd, LIBBSD_0.2);
 
 int
 strnunvis_netbsd(char *dst, size_t dlen, const char *src)
 {
 	return strnunvisx(dst, dlen, src, 0);
 }
-__asm__(".symver strnunvis_netbsd,strnunvis@LIBBSD_0.9.1");
+libbsd_symver_variant(strnunvis, strnunvis_netbsd, LIBBSD_0.9.1);
diff --git a/src/vis.c b/src/vis.c
index 260d3c1..c8e5ae8 100644
--- a/src/vis.c
+++ b/src/vis.c
@@ -77,6 +77,8 @@ __weak_alias(strvisx,_strvisx)
 #include <stdio.h>
 #include <string.h>
 
+#include "local-link.h"
+
 #define _DIAGASSERT(x)
 
 /*
@@ -735,14 +737,14 @@ strnvis_openbsd(char *mbdst, const char *mbsrc, size_t dlen, int flags)
 {
 	return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
 }
-__asm__(".symver strnvis_openbsd,strnvis@@LIBBSD_0.2");
+libbsd_symver_default(strnvis, strnvis_openbsd, LIBBSD_0.2);
 
 int
 strnvis_netbsd(char *mbdst, size_t dlen, const char *mbsrc, int flags)
 {
 	return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
 }
-__asm__(".symver strnvis_netbsd,strnvis@LIBBSD_0.9.1");
+libbsd_symver_variant(strnvis, strnvis_netbsd, LIBBSD_0.9.1);
 
 int
 stravis(char **mbdstp, const char *mbsrc, int flags)