On Sat, Mar 09, 2024 at 06:12:12AM +0100, Willy Tarreau wrote: > Hi Brooks, > > On Fri, Mar 08, 2024 at 09:47:39PM +0000, Brooks Davis wrote: > > On Fri, Mar 08, 2024 at 06:19:42PM +0100, Willy Tarreau wrote: > > > Hi Dmitry, > > > > > > first, sorry for the long delay but these days I've been drained in a > > > bunch of meetings and reviews that took more time than I expected! > > > > > > On Wed, Feb 28, 2024 at 11:06:00PM +0300, Dmitry Sivachenko wrote: > > > > Hello! > > > > > > > > Recently FreeBSD has moved some things out from libc to libsys (see e.g > > > > https://www.mail-archive.com/dev-commits-src-all@freebsd.org/msg50353.html) > > > > So haproxy stopped compiling with "ld: error: undefined symbol: > > > > __elf_aux_vector" error. > > > > > > > > Brooks Davis suggested the attached patch to fix that. > > > > > > > > Please consider including it into the tree. > > > > > > What's the oldest FreeBSD version that will build with this ? Shouldn't > > > we just guard it by version ? This patch is pretty well isolated and in > > > a place already full of ifdefs, so it would cost basically nothing to > > > add a test for the FreeBSD version in addition to defined(): > > > > It looks like __elf_aux_vector is available since FreeBSD 9, > > elf_aux_info since 12, and AT_EXECPATH support since 13. > > I belive it will build on 12, but elf_aux_info will return an error and > > leave execpath unmodified. If you need to support earlier versions then > > I guess a __FreeBSD_version ifdef would be appropriate. > > OK that works for me. Do you want to send a new patch or should I adapt > yours ? If you have a 12 somewhere that would save me time to verify I > don't mess up with the ifdefs, otherwise I can probably handle it and > we'll watch for any report of build error.
I don't have a 12 box handy either, but here's a patch that retains the old code wrapped in ifdefs and should be low risk as such. 1300058 is the next version bump after AT_EXECPATH support was added. Thanks, Brooks >From 9045b0026438dbe4b38a6521b6f7575f06ff9077 Mon Sep 17 00:00:00 2001 From: Brooks Davis <bro...@one-eyed-alien.net> Date: Wed, 28 Feb 2024 18:12:40 +0000 Subject: [PATCH] MINOR: tools: use public interface for FreeBSD get_exec_path() Where possible (FreeBSD 13+), use the public, documented interface to the ELF auxiliary argument vector: elf_aux_info(). __elf_aux_vector is a private interface exported so that the runtime linker can set its value during process startup and not intended for public consumption. In FreeBSD 15 it has been removed from libc and moved to libsys. --- src/tools.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tools.c b/src/tools.c index b2814b5af..839264631 100644 --- a/src/tools.c +++ b/src/tools.c @@ -17,9 +17,14 @@ #endif #if defined(__FreeBSD__) +#include <sys/param.h> +#if __FreeBSD_version < 1300058 #include <elf.h> #include <dlfcn.h> extern void *__elf_aux_vector; +#else +#include <sys/auxv.h> +#endif #endif #if defined(__NetBSD__) @@ -5018,6 +5023,7 @@ const char *get_exec_path() if (execfn && execfn != ENOENT) ret = (const char *)execfn; #elif defined(__FreeBSD__) +#if __FreeBSD_version < 1300058 Elf_Auxinfo *auxv; for (auxv = __elf_aux_vector; auxv->a_type != AT_NULL; ++auxv) { if (auxv->a_type == AT_EXECPATH) { @@ -5025,6 +5031,14 @@ const char *get_exec_path() break; } } +#else + static char execpath[MAXPATHLEN]; + + if (execpath[0] == '\0') + elf_aux_info(AT_EXECPATH, execpath, MAXPATHLEN); + if (execpath[0] != '\0') + ret = execpath; +#endif #elif defined(__NetBSD__) AuxInfo *auxv; for (auxv = _dlauxinfo(); auxv->a_type != AT_NULL; ++auxv) { -- 2.43.0