[master] 777e03ba9 Disable strict aliasing with gcc where vtree.h is used

Nils Goroll nils.goroll at uplex.de
Wed Mar 24 17:38:04 UTC 2021


commit 777e03ba9774bf635a972fa0561b50ff071908a9
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Mar 24 18:25:24 2021 +0100

    Disable strict aliasing with gcc where vtree.h is used
    
    Please replace this commit with a better solution, if you have one.
    
    e1ac59335f749b84280722425b355be344cc76e9 brought us the VRBT node
    color encoded in the lower two bits of pointers.
    
    gcc strict aliasing rules (as enabled with -O2 and higher) forbid
    aliased lvalue access as in the following macro expanded code:
    
    (*(uintptr_t *)&(parent)->entry.rbe_parent) &= ~((uintptr_t)3);
    
    Until we have a better solution, disable strict aliasing with gcc
    for targets with any source file using vtree.h.
    
    Note that we would want to limit -fno-strict-aliasing to individual
    compliation units, but automake does not offer a simple and clean way
    to achieve this:
    
    https://www.gnu.org/software/automake/manual/html_node/Per_002dObject-Flags.html

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index ce7145efd..76a47ad2c 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -159,6 +159,7 @@ nobase_pkginclude_HEADERS = \
 vcldir=$(datarootdir)/$(PACKAGE)/vcl
 
 varnishd_CFLAGS = \
+	@vtree_extra_cflags@ \
 	@PCRE_CFLAGS@ \
 	@SAN_CFLAGS@ \
 	-DNOT_IN_A_VMOD \
diff --git a/bin/varnishtop/Makefile.am b/bin/varnishtop/Makefile.am
index cdb63b5f8..0427e1140 100644
--- a/bin/varnishtop/Makefile.am
+++ b/bin/varnishtop/Makefile.am
@@ -13,6 +13,7 @@ varnishtop_SOURCES = \
 
 
 varnishtop_CFLAGS = \
+	@vtree_extra_cflags@ \
 	@SAN_CFLAGS@
 
 varnishtop_LDADD = \
diff --git a/configure.ac b/configure.ac
index 59aa57b9e..9fcfb5693 100644
--- a/configure.ac
+++ b/configure.ac
@@ -291,6 +291,8 @@ CFLAGS="${save_CFLAGS}"
 if test "x$GCC" = "xyes"; then
 	libvgz_extra_cflags="${libvgz_extra_cflags} -Wno-unknown-warning-option -Wno-implicit-fallthrough"
 	AC_SUBST(libvgz_extra_cflags)
+	vtree_extra_cflags="-fno-strict-aliasing"
+	AC_SUBST(vtree_extra_cflags)
 fi
 
 SAN_CFLAGS=
diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am
index 0cbff3c4d..a2a314581 100644
--- a/lib/libvarnishapi/Makefile.am
+++ b/lib/libvarnishapi/Makefile.am
@@ -37,6 +37,7 @@ endif
 
 libvarnishapi_la_CFLAGS = \
 	-DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' \
+	@vtree_extra_cflags@ \
 	@SAN_CFLAGS@
 
 libvarnishapi_la_LIBADD = \
diff --git a/lib/libvcc/Makefile.am b/lib/libvcc/Makefile.am
index 1e3d6f2d0..965e0b3f4 100644
--- a/lib/libvcc/Makefile.am
+++ b/lib/libvcc/Makefile.am
@@ -9,6 +9,7 @@ AM_CPPFLAGS = \
 noinst_LIBRARIES = libvcc.a
 
 libvcc_a_CFLAGS = \
+	@vtree_extra_cflags@ \
 	@SAN_CFLAGS@
 
 libvcc_a_SOURCES = \


More information about the varnish-commit mailing list