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/[email protected]/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.
-- Brooks
> > --- src/tools.c.orig
> > +++ src/tools.c
> > @@ -17,9 +17,7 @@
> > #endif
> >
> > #if defined(__FreeBSD__)
> > -#include <elf.h>
> > -#include <dlfcn.h>
> > -extern void *__elf_aux_vector;
> > +#include <sys/auxv.h>
> > #endif
> >
> > #if defined(__NetBSD__)
> > @@ -5018,13 +5016,11 @@
> > if (execfn && execfn != ENOENT)
> > ret = (const char *)execfn;
> > #elif defined(__FreeBSD__)
> > - Elf_Auxinfo *auxv;
> > - for (auxv = __elf_aux_vector; auxv->a_type != AT_NULL; ++auxv) {
> > - if (auxv->a_type == AT_EXECPATH) {
> > - ret = (const char *)auxv->a_un.a_ptr;
> > - break;
> > - }
> > - }
> > + static char execpath[MAXPATHLEN];
> > + if (execpath[0] == '\0')
> > + elf_aux_info(AT_EXECPATH, execpath, MAXPATHLEN);
> > + if (execpath[0] != '\0')
> > + ret = execpath;
> > #elif defined(__NetBSD__)
> > AuxInfo *auxv;
> > for (auxv = _dlauxinfo(); auxv->a_type != AT_NULL; ++auxv) {
>
> Note that I tested it on a 13.1 and it builds there, I'm just concerned
> about older ones (e.g. I don't have a v12 here).
>
> Thanks!
> Willy
>