[PATCH] libbsd.map: Add guards for LIBBSD_OVERLAY symbols

Guillem Jover guillem at hadrons.org
Mon Jan 8 23:30:06 UTC 2024


Hi!

On Sun, 2024-01-07 at 22:04:46 -0500, Nicholas Vinson wrote:
> When built with the LIBBSD_OVERLAY macro set, the following functions
> are not built which results in undefined symbols in libbsd.map:
> 
>     vwarn, vwarnx, warn, warnx, verr, verrx, err, errx
> 
> leading to build failures similar to
> 
>     ld.lld: error: version script assignment of 'LIBBSD_0.10.0' to
>     symbol 'vwarn' failed: symbol not defined
> 
> when linking with ld.lld since ld.lld does not allow undefined symbols
> in the map by default.
> 
> Add guards, so these functions are excluded from libbsd.map when not
> built. Thereby, allowing ld.lld-16 and newer to link successfully with
> default options. See
> https://maskray.me/blog/2023-03-19-lld-16-elf-changes for ld.lld-16
> change summary.
> 
> Fixes Gentoo Bug 915068 ( https://bugs.gentoo.org/915068 )

Ah, recently closed an issue, which I thought had been handled
already, but I guess not entirely, sorry about that. In any case
thanks for the patch! This makes this problem clear to me now.

> diff --git a/src/Makefile.am b/src/Makefile.am
> index 6f2325c..9492d31 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -64,8 +64,9 @@ libbsd_la_LDFLAGS = \
>  	# EOL
>  if HAVE_LINKER_VERSION_SCRIPT
>  libbsd_la_LDFLAGS += \
> -	-Wl,--version-script=$(srcdir)/libbsd.map \
> +	-Wl,--version-script=$(top_builddir)/src/libbsd.map \
>  	# EOL
> +EXTRA_libbsd_la_DEPENDENCIES += $(top_builddir)/src/libbsd.map
>  else
>  libbsd_la_LDFLAGS += \
>  	-export-symbols libbsd.sym \
> @@ -200,6 +201,9 @@ libbsd_ctor_a_SOURCES = \
>  	setproctitle_ctor.c \
>  	# EOL
>  
> +libbsd.map: libbsd.map.in
> +	$(CC) -E $(AM_CPPFLAGS) $(CPPFLAGS) -x assembler-with-cpp -o $@ $<
> +
>  # Generate a simple libtool symbol export list to be used as a fallback if
>  # there is no version script support.
>  libbsd.sym: libbsd.map
> diff --git a/src/libbsd.map b/src/libbsd.map.in
> similarity index 99%
> rename from src/libbsd.map
> rename to src/libbsd.map.in

I have a similar patch as part of the explicit ABI handling I need to
get ready for the other ports:

  https://git.hadrons.org/cgit/libbsd.git/log/?h=pu/build-abi

Which I'll be cleaning up and merging soon.

> index 6c61235..f645600 100644
> --- a/src/libbsd.map
> +++ b/src/libbsd.map.in
> @@ -174,6 +174,7 @@ LIBBSD_0.9.1 {
>  } LIBBSD_0.9;
>  
>  LIBBSD_0.10.0 {
> +#ifndef LIBBSD_OVERLAY
>      /* These BSD extensions are available on GNU systems, but not on other
>       * systems such as Windows or musl libc based ones. */
>      vwarn;
> @@ -184,6 +185,7 @@ LIBBSD_0.10.0 {
>      verrx;
>      err;
>      errx;
> +#endif
>  } LIBBSD_0.9.1;
>  
>  LIBBSD_0.11.0 {

Although this does not seem correct. The condition deciding whether
the functions are exposed and built into the library is whether the
macro LIBBSD_NEED_ERR_H_FUNCS is defined, but that is only done from
bsd/err.h, which is rather annoying. I'll be adding a configure-time
check for this as part of the pu/build-api rework, but then that needs
to made coherent with whether the system <err.h> is present (which
could appear at a later point while the library does not include the
actual implementation :/), hmm.

Thanks,
Guillem


More information about the libbsd mailing list