Varnish on OS X and bug #118

Dag-Erling Smørgrav des at linpro.no
Tue Aug 7 10:00:35 CEST 2007


Martin Aspeli <optilude at gmx.net> writes:
> Two questions:
>
>   - Is there some workaround I can do to make this work without having
> to patch the source?
>
>   - Is there some way Varnish's configure script could detect OS X and
> make this change as appropriate?
>
> I can't work out what export_dynamic_flag_spec="-flat_namespace"
> actually *does, making it hard to explore the space.

We link varnishd with -export-dynamic, which tells libtool that
symbols defined in varnishd should be available to libraries linked
with varnishd.  Otherwise, varnishd would be able to call VCL code but
the VCL code would not be able to call the VCL runtime (VRT_*) which
is contained partly in varnishd and partly in libvarnish.

The export_dynamic_flag_spec variable tells libtool how it should
translate -export-dynamic when invoking the native linker.  On systems
using the GNU toolchain, this is simply ld's --export-dynamic option
(or gcc's -Wl,--export-dynamic which tells it to invoke ld with the
--export-dynamic option).  On MacOS X, this is -flat_namespace, which
tells the linker to use a single namespace for program and libraries
instead of a two-level namespace where the program can look up symbols
in the libraries but not the other way around.  Note than until 10.3,
-flat_namespace used to be the default.

There is another option you might try instead of the libtool hack,
although I haven't tested it so I don't know if it will actually work:

Index: bin/varnishd/mgt_vcc.c
===================================================================
--- bin/varnishd/mgt_vcc.c      (revision 1808)
+++ bin/varnishd/mgt_vcc.c      (working copy)
@@ -182,7 +182,7 @@
        len = snprintf(buf, sizeof buf,
             "ln -f %s _.c ;"                   /* XXX: for debugging */
 #ifdef __APPLE__
-           "exec cc -dynamiclib -Wl,-flat_namespace,-undefined,suppress -o %s -x c - < %s 2>&1",
+           "exec cc -dynamiclib -Wl,-undefined,dynamic_lookup -o %s -x c - < %s 2>&1",
 #else
            "exec cc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1",
 #endif

The downside is that this will not work at all on pre-10.3 systems,
whereas -flat_namespace is simply a nop on pre-10.3.

Let me know how it works out...

DES
-- 
Dag-Erling Smørgrav
Senior Software Developer
Linpro AS - www.linpro.no



More information about the varnish-misc mailing list