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.
This commit is contained in:
Guillem Jover 2019-08-06 18:51:45 +02:00
parent b0ebb0d4c2
commit 890699a78b
4 changed files with 18 additions and 6 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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)