diff options
| author | Alex Bennée <alex.bennee@linaro.org> | 2017-01-11 16:28:36 +0000 |
|---|---|---|
| committer | Paolo Bonzini <pbonzini@redhat.com> | 2017-01-12 13:27:49 +0100 |
| commit | 529046c397059b8c5ef4dc5fb3c258d86fafb126 (patch) | |
| tree | 49308408e2bb910108cf3483f744674c19d52bbe | |
| parent | 8c3f0d96a487fcd1eb4ab219c2ed869dbbfe7c51 (diff) | |
| download | kvm-unit-tests-529046c397059b8c5ef4dc5fb3c258d86fafb126.tar.gz | |
libcflat: add PRI(dux)32 format types
So we can have portable formatting of uint32_t types. However there is
a catch. Different compilers can use legally subtly different types
though so we need to probe the compiler defined intdef.h first.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
| -rw-r--r-- | Makefile | 1 | ||||
| -rwxr-xr-x | configure | 13 | ||||
| -rw-r--r-- | lib/libcflat.h | 9 |
3 files changed, 23 insertions, 0 deletions
@@ -55,6 +55,7 @@ CFLAGS += $(fomit_frame_pointer) CFLAGS += $(fno_stack_protector) CFLAGS += $(fno_stack_protector_all) CFLAGS += $(wno_frame_address) +CFLAGS += $(if $(U32_LONG_FMT),-D__U32_LONG_FMT__,) CXXFLAGS += $(CFLAGS) @@ -109,6 +109,18 @@ if [ -f $testdir/run ]; then ln -fs $testdir/run $testdir-run fi +# check if uint32_t needs a long format modifier +cat << EOF > lib_test.c +#include <inttypes.h> +EOF + +$cross_prefix$cc lib_test.c -E | grep "typedef" | grep "long" | grep "uint32_t" &> /dev/null +exit=$? +if [ $exit -eq 0 ]; then + u32_long=true +fi +rm -f lib_test.c + # check for dependent 32 bit libraries if [ "$arch" != "arm" ]; then cat << EOF > lib_test.c @@ -155,4 +167,5 @@ TEST_DIR=$testdir FIRMWARE=$firmware ENDIAN=$endian PRETTY_PRINT_STACKS=$pretty_print_stacks +U32_LONG_FMT=$u32_long EOF diff --git a/lib/libcflat.h b/lib/libcflat.h index 380395f..e80fc50 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -58,12 +58,21 @@ typedef _Bool bool; #define true 1 #if __SIZEOF_LONG__ == 8 +# define __PRI32_PREFIX # define __PRI64_PREFIX "l" # define __PRIPTR_PREFIX "l" #else +#if defined(__U32_LONG_FMT__) +# define __PRI32_PREFIX "l" +#else +# define __PRI32_PREFIX +#endif # define __PRI64_PREFIX "ll" # define __PRIPTR_PREFIX #endif +#define PRId32 __PRI32_PREFIX "d" +#define PRIu32 __PRI32_PREFIX "u" +#define PRIx32 __PRI32_PREFIX "x" #define PRId64 __PRI64_PREFIX "d" #define PRIu64 __PRI64_PREFIX "u" #define PRIx64 __PRI64_PREFIX "x" |
