mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice-common
synced 2025-12-26 22:55:35 +00:00
For example, something like this:
uint8_t *p8;
uint32_t *p32 = (uint32_t *) p8;
generates a warning like this:
spice-channel.c:1350:10: error: cast from 'uint8_t *' (aka 'unsigned char *') to
'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to
4 [-Werror,-Wcast-align]
The warning indicates that we end up with a pointer to data that
should be 4-byte aligned, but its value may be misaligned. On x86,
this does not make much of a difference, except a relatively minor
performance penalty. However, on platforms such as older ARM, misaligned
accesses are emulated by the kernel, and support for them is optional.
So we may end up with a fault.
The intent of the fix here is to make it easy to identify and rework
places where actual mis-alignment occurs. Wherever casts raise the warning,
they are replaced with a macro:
- SPICE_ALIGNED_CAST(type, value) casts value to type, and indicates that
we believe the resulting pointer is aligned. If it is not, a runtime
warning will be issued. This check is disabled unless
--enable-alignment-checks is passed at configure time
- SPICE_UNALIGNED_CAST(type, value) casts value to type, and indicates that
we believe the resulting pointer is not always aligned.
Any code using SPICE_UNALIGNED_CAST may need to be revisited in order
to improve performance, e.g. by using memcpy.
There are normally no warnings for SPICE_UNALIGNED_CAST, but it is possible
to emit debug messages for mis-alignment in SPICE_UNALIGNED_CAST
by configuring with CFLAGS=-DSPICE_DEBUG_ALIGNMENT.
Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
73 lines
1.7 KiB
Plaintext
73 lines
1.7 KiB
Plaintext
AC_PREREQ([2.63])
|
|
|
|
AC_INIT([spice-common],
|
|
[noversion],
|
|
[spice-devel@lists.freedesktop.org])
|
|
|
|
AC_CONFIG_SRCDIR([common/bitops.h])
|
|
AC_CONFIG_MACRO_DIR([m4])
|
|
AM_CONFIG_HEADER([config.h])
|
|
AC_CONFIG_AUX_DIR([build-aux])
|
|
|
|
# For automake >= 1.12
|
|
m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
|
|
|
|
# Checks for programs
|
|
AM_INIT_AUTOMAKE([1.11 dist-xz no-dist-gzip tar-ustar foreign -Wall -Werror])
|
|
AM_MAINTAINER_MODE
|
|
AM_SILENT_RULES([yes])
|
|
LT_INIT
|
|
SPICE_MANUAL
|
|
|
|
AC_PROG_CC
|
|
AC_PROG_CC_C99
|
|
if test "x$ac_cv_prog_cc_c99" = xno; then
|
|
AC_MSG_ERROR([C99 compiler is required.])
|
|
fi
|
|
AM_PROG_CC_C_O
|
|
|
|
SPICE_CHECK_SYSDEPS
|
|
|
|
AC_ARG_ENABLE([alignment-checks],
|
|
AS_HELP_STRING([--enable-alignment-checks],
|
|
[Enable runtime checks for cast alignment @<:@default=no@:>@]),
|
|
[],
|
|
enable_alignment_checks="no")
|
|
AS_IF([test "x$enable_alignment_checks" = "xyes"],
|
|
[AC_DEFINE([SPICE_DEBUG_ALIGNMENT], 1, [Enable runtime checks for cast alignment])])
|
|
|
|
# Checks for libraries
|
|
PKG_CHECK_MODULES([PROTOCOL], [spice-protocol >= 0.12.12])
|
|
|
|
SPICE_CHECK_PYTHON_MODULES()
|
|
|
|
SPICE_CHECK_PIXMAN
|
|
SPICE_CHECK_SMARTCARD
|
|
SPICE_CHECK_CELT051
|
|
SPICE_CHECK_GLIB2
|
|
SPICE_CHECK_OPUS
|
|
SPICE_CHECK_OPENSSL
|
|
|
|
SPICE_COMMON_CFLAGS='$(PIXMAN_CFLAGS) $(SMARTCARD_CFLAGS) $(CELT051_CFLAGS) $(GLIB2_CFLAGS) $(OPUS_CFLAGS) $(OPENSSL_CFLAGS)'
|
|
SPICE_COMMON_LIBS='$(PIXMAN_LIBS) $(CELT051_LIBS) $(GLIB2_LIBS) $(OPUS_LIBS) $(OPENSSL_LIBS)'
|
|
AC_SUBST(SPICE_COMMON_CFLAGS)
|
|
AC_SUBST(SPICE_COMMON_LIBS)
|
|
|
|
# The End!
|
|
AC_CONFIG_FILES([
|
|
Makefile
|
|
common/Makefile
|
|
python_modules/Makefile
|
|
tests/Makefile
|
|
docs/Makefile
|
|
])
|
|
|
|
AH_BOTTOM([
|
|
/* argh.. this is evil */
|
|
#if defined(FIXME_SERVER_SMARTCARD) && defined(USE_SMARTCARD)
|
|
%:undef USE_SMARTCARD
|
|
#endif
|
|
])
|
|
|
|
AC_OUTPUT
|