Updated varnish patches for cygwin 1.7.8

jdzstz - gmail dot com jdzstz at gmail.com
Thu Mar 10 01:25:50 CET 2011


Hello,

Trunk: http://www.varnish-cache.org/trac/attachment/wiki/VarnishOnCygwinWindows/varnish-githead-cygwin.patch

I have made some minor changes to varnish patches for cygwin 1.7.8, I
reply to your questions.

2011/3/8 Tollef Fog Heen <tfheen at varnish-software.com>:

> In general, I'm a bit unhappy with most of this patch as it leaks too
> much cygwin stuff across the build system.  I'll comment some issues
> inline.
>
> | diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
> | index b8db6e0..f920b42 100644
> | --- a/bin/varnishd/Makefile.am
> | +++ b/bin/varnishd/Makefile.am
> | +
> | +EXTRA_SCRIPTS =
> | +
> | +sbin_SCRIPTS = ${CYGWIN_libvarnishd_OBJECTS}
> | +
> | +
> |  DISTCLEANFILES = default_vcl.h
>
> Why the extra EXTRA_SCRIPTS?  I'd also like to not have to care about
> gcc on cygwin having problems linking a DLL with unresolved symbols in it.

EXTRA_SCRIPTS and sbin_SCRIPTS is a workaround in order to be able to
install fake library in system when "make install" is executed.

>
> |  #
> | diff --git a/configure.ac b/configure.ac
> | index f574764..9f7753e 100644
> | --- a/configure.ac
> | +++ b/configure.ac
>
> This bit has been merged.

I have tested this change with last trunk version and It works fine at cygwin.

>
> | @@ -457,6 +488,19 @@ else
> |       *-*-darwin*)
> |               VCC_CC="exec cc $OCFLAGS -dynamiclib -Wl,-undefined,dynamic_lookup -o %o %s"
> |               ;;
> | +     *-*-cygwin*)
> | +             #calculate ${exec_prefix}/lib, because it is asigned later, and we need now
> | +             prefix_aux=`eval echo ${prefix}`
> | +             test "x$prefix_aux" = xNONE && prefix_aux=`eval echo ${ac_default_prefix}`
> | +             # Let make expand exec_prefix.
> | +             exec_prefix_aux=`eval echo ${exec_prefix}`
> | +             test "x$exec_prefix_aux" = xNONE && exec_prefix_aux=`eval echo ${prefix_aux}`
> | +             # Remove "/" if we are in Root
> | +             test "x$exec_prefix_aux" = "x/" && exec_prefix_aux=""
> | +             #calculate compilation path
> | +             comp_prefix=`pwd`
> | +             VCC_CC="$PTHREAD_CC $OCFLAGS $PTHREAD_CFLAGS -shared %s -L${comp_prefix}/lib/libvarnish/.libs -L${comp_prefix}/bin/varnishd -L${exec_prefix_aux}/lib -L${exec_prefix_aux}/sbin -L${exec_prefix_aux}/bin -lvarnish -lvarnishd -o %o"
> | +             ;;
>
> Adding those -L bits here looks a bit odd.  Doesn't libtool just add the
> necessary rpath if that's needed?

Those lines defines VCC_CC value that is used by varnish only at
execution time in order to compile VCL file at startime, and in order
to search DLL libvarnishd falke DLL so libtools cannot be used.
Also a  comment appears at configuration.ac file that says that
libtool is not used:

           # Command line for compiling VCL code.  I wish there were a
simple way
           # to figure this out dynamically without introducing a run-time
           # dependency on libtool.

>
> | +# Add library dependencies with libvarnish (linker needs it in CYGWIN during compilation time)
> | +# Generate fake library libvarnishd.dll.a in order to successful linking DLL when resolving varnishd.exe simbols
> | +case $target in
> | +*-*-cygwin*)
> | +             CYGWIN_varnishd_LDFLAGS=' -Wl,-out-implib,libvarnishd.dll.a'
> | +             CYGWIN_libvarnishd_OBJECTS='libvarnishd.dll.a'
> | +             CYGWIN_libvmod_std_la_LIBADD='$(top_builddir)/lib/libvarnish/libvarnish.la -lvarnishd -L$(top_builddir)/bin/varnishd'
> | +             AC_SUBST(CYGWIN_varnishd_LDFLAGS)
> | +             AC_SUBST(CYGWIN_libvarnishd_OBJECTS)
> | +             AC_SUBST(CYGWIN_libvmod_std_la_LIBADD)
> | +             cygwin=true
> | +             ;;
> | +*)
> | +             cygwin=false
> | +             ;;
> | +esac
> | +
> | +AM_CONDITIONAL([CYGWIN_COMPILATION], test x$cygwin = xtrue)
>
> Can we get rid of that fake library?  Also, doesn't cygwin support
> inter-library dependencies properly?

Cygwin compilation generate objects in PE/COFF format (win32
executable files) , the problem is that with COFF format, all DLL
dependencies must be defined at compilation time.
If some DLL (shared ojects) uses objects from binary files (EXE) then,
at cygwin you have to specify a fake DLL that is generated from
original EXE file, in order to be able to link against something:

         (from http://www.cygwin.com/ml/cygwin/2006-12/msg00592.html)

         The particular question of having a DLL that imports a
function exported
         from the main .exe comes up from time to time.  It is possible, but not
         necessarily pretty.  If it is only a one-way dependency then
it's rather
         simple to mark the symbol as dllexport in the .exe, create an import
         library for the .exe (yes the .exe) during linking, and then link the
         .dll against that import library.

         Linkage problems ("Undefined reference" errors). The
undefined reference is because
         fundamentally ELF (UNIX) and PE/COFF (Windows) are very
different in terms of how
          linking works under the hood. The short explanation is that
PE/COFF requires all references to be resolved at link-time.

See:
http://www.mail-archive.com/cygwin@cygwin.com/msg81837.html
http://www.cygwin.com/ml/cygwin/2007-06/msg00450.html
http://www.cygwin.com/ml/cygwin/2005-07/msg00675.html
http://www.cygwin.com/ml/cygwin/2006-12/msg00592.html



>
> | --- a/lib/libvarnishapi/Makefile.am
> | +++ b/lib/libvarnishapi/Makefile.am
> | @@ -26,4 +26,6 @@ libvarnishapi_la_SOURCES = \
> |  libvarnishapi_la_CFLAGS = \
> |       -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"'
> |
> | -libvarnishapi_la_LIBADD = @PCRE_LIBS@
> | +libvarnishapi_la_LIBADD = \
> | +     $(top_builddir)/lib/libvarnish/libvarnish.la \
> | +     @PCRE_LIBS@
>
> Why is this?

As said before, Cygwin compilation generate objects in PE/COFF format
(win32 DLL files) , the problem is that with COFF format, all DLL
dependencies must be defined at compilation time.

         http://cygwin.com/ml/cygwin/2007-07/msg00774.html

         Linkage problems ("Undefined reference" errors). The
undefined reference is because
         fundamentally ELF (UNIX) and PE/COFF (Windows) are very
different in terms of how
          linking works under the hood. The short explanation is that
PE/COFF requires all references to be resolved at link-time.

So only in cygwin there is a dependency of libvarnishapi with
libvarnish, at compilation type. On Linux the dependency is only at
execution time, it is not compulsory to add the dependency,  but if it
is added, there is no problem with it, so I have added it for all
platforms.

If remove this line DLL import, following error appears:

/bin/sh ../../libtool --tag=CC   --mode=link gcc -std=gnu99
-I/usr/include/ncurses  -avoid-version -no-undefined -o libvcl.la
-rpath /usr/local/lib/varnish vcc_acl.lo vcc_action.lo vcc_backend.lo
vcc_backend_util.lo vcc_compile.lo vcc_dir_random.lo
vcc_dir_round_robin.lo vcc_dir_dns.lo vcc_expr.lo vcc_parse.lo
vcc_fixed_token.lo vcc_obj.lo vcc_storage.lo vcc_string.lo vcc_symb.lo
vcc_token.lo vcc_var.lo vcc_vmod.lo vcc_xref.lo
libtool: link: gcc -std=gnu99 -shared  .libs/vcc_acl.o
.libs/vcc_action.o .libs/vcc_backend.o .libs/vcc_backend_util.o
.libs/vcc_compile.o .libs/vcc_dir_random.o .libs/vcc_dir_round_robin.o
.libs/vcc_dir_dns.o .libs/vcc_expr.o .libs/vcc_parse.o
.libs/vcc_fixed_token.o .libs/vcc_obj.o .libs/vcc_storage.o
.libs/vcc_string.o .libs/vcc_symb.o .libs/vcc_token.o .libs/vcc_var.o
.libs/vcc_vmod.o .libs/vcc_xref.o      -o .libs/cygvcl.dll
-Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker
.libs/libvcl.dll.a
.libs/vcc_acl.o:vcc_acl.c:(.text+0x14d): undefined reference to `_vsb_printf'
.libs/vcc_acl.o:vcc_acl.c:(.text+0x19c): undefined reference to `_vsb_printf'
.libs/vcc_acl.o:vcc_acl.c:(.text+0x209): undefined reference to `_vas_fail'
.libs/vcc_acl.o:vcc_acl.c:(.text+0x25f): undefined reference to `_vas_fail'
.libs/vcc_acl.o:vcc_acl.c:(.text+0x2f7): undefined reference to `_vsb_printf'
.libs/vcc_acl.o:vcc_acl.c:(.text+0x325): undefined reference to `_vsb_printf'
.libs/vcc_acl.o:vcc_acl.c:(.text+0x461): undefined reference to `_vsb_printf'
.libs/vcc_acl.o:vcc_acl.c:(.text+0x5a1): undefined reference to `_vsb_printf'
.libs/vcc_acl.o:vcc_acl.c:(.text+0x6e6): undefined reference to `_vsb_printf'
.libs/vcc_acl.o:vcc_acl.c:(.text+0x747): more undefined references to
`_vsb_printf' follow
.libs/vcc_acl.o:vcc_acl.c:(.text+0x8d3): undefined reference to `_vas_fail'
.libs/vcc_acl.o:vcc_acl.c:(.text+0xd02): undefined reference to `_vas_fail'
.libs/vcc_acl.o:vcc_acl.c:(.text+0x1167): undefined reference to `_vas_fail'
.libs/vcc_acl.o:vcc_acl.c:(.text+0x12d2): undefined reference to `_vas_fail'
.libs/vcc_action.o:vcc_action.c:(.text+0x31a): undefined reference to
`_vas_fail'
.libs/vcc_action.o:vcc_action.c:(.text+0x51c): more undefined
references to `_vas_fail' follow
.libs/vcc_action.o:vcc_action.c:(.text+0x549): undefined reference to
`_vsb_printf'
.libs/vcc_action.o:vcc_action.c:(.text+0x6bc): undefined reference to
`_vsb_printf'
.libs/vcc_action.o:vcc_action.c:(.text+0x71f): undefined reference to
`_vsb_printf'
.libs/vcc_action.o:vcc_action.c:(.text+0x809): undefined reference to
`_vsb_printf'
.libs/vcc_action.o:vcc_action.c:(.text+0xb0c): undefined reference to
`_vsb_printf'
.libs/vcc_action.o:vcc_action.c:(.text+0x1053): more undefined
references to `_vsb_printf' follow
.libs/vcc_action.o:vcc_action.c:(.text+0x11ce): undefined reference to
`_vas_fail'
.libs/vcc_backend.o:vcc_backend.c:(.text+0x3f): undefined reference to
`_vas_fail'

>
> | diff --git a/lib/libvcl/Makefile.am b/lib/libvcl/Makefile.am
> | index aab8749..4645bba 100644
> | --- a/lib/libvcl/Makefile.am
> | +++ b/lib/libvcl/Makefile.am
> | @@ -33,6 +33,8 @@ libvcl_la_SOURCES = \
> |       vcc_vmod.c \
> |       vcc_xref.c
> |
> | +libvcl_la_LIBADD = $(top_builddir)/lib/libvarnish/libvarnish.la
> | +
> |  EXTRA_DIST = \
> |       generate.py
>
> What does this solve for you?

REMOVED: This line was similar to libvarnishapi change, but I have
removed the patch, for libvcl it is not necesary.

>
> | diff --git a/lib/libvmod_std/Makefile.am b/lib/libvmod_std/Makefile.am
> | index 36147fe..41c32c8 100644
> | --- a/lib/libvmod_std/Makefile.am
> | +++ b/lib/libvmod_std/Makefile.am
> | @@ -13,9 +13,16 @@ libvmod_std_la_SOURCES = \
> |       vmod_std.c \
> |       vmod_std_fileread.c
> |
> | +libvmod_std_la_LIBADD = ${CYGWIN_libvmod_std_la_LIBADD}
> | +
> |  vcc_if.c vcc_if.h: $(top_srcdir)/lib/libvmod_std/vmod.py $(top_srcdir)/lib/libvmod_std/vmod.vcc
> |       @PYTHON@ $(top_srcdir)/lib/libvmod_std/vmod.py $(top_srcdir)/lib/libvmod_std/vmod.vcc
> |
> |  EXTRA_DIST = vmod.py vmod.vcc
> |
> |  CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h
> | +
> | +if CYGWIN_COMPILATION
> | +install-exec-hook:
> | +     $(LN_S) -f cygvmod_std-1.dll .libs/libvmod_std.so.1
> | +endif
>
> What?  You shouldn't symlink stuff into .libs directories.

On cygwin system, all DLL name starts with "cyg*" instead "lib*"
prefix, so all libraries names are similar to "cygvmod_std.dll" .  The
problem is that varnishtests vtc tests: ./tests/m00000.vtc
./tests/m00001.vtc   ./tests/m00002.vtc, etc..., searchs a file named
libvmod_std.so, so this symlink generate a link from created
cygvmod_std.dll   (cygwin file) to libvmod_std.so expected file.

This change is only used in order to pass all varnishtest tests.

>
> --
> Tollef Fog Heen
> Varnish Software
> t: +47 21 98 92 64
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: varnish-githead-cygwin.patch
Type: application/octet-stream
Size: 4257 bytes
Desc: not available
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20110310/a7c61411/attachment-0003.obj>


More information about the varnish-dev mailing list