fix altivec.h redefinition issue

fix #426
This commit is contained in:
Yann Collet 2020-07-23 16:37:57 -07:00
parent c006eb7fbb
commit cd59de7b58
4 changed files with 86 additions and 5 deletions

View File

@ -93,10 +93,12 @@ matrix:
- CC=powerpc-linux-gnu-gcc RUN_ENV=qemu-ppc-static LDFLAGS=-static make check # Scalar code path
- make clean
- CC=powerpc64-linux-gnu-gcc RUN_ENV=qemu-ppc64-static CPPFLAGS=-DXXH_VECTOR=XXH_SCALAR CFLAGS="-O3" LDFLAGS="-static -m64" make check # Scalar code path
- make clean
# VSX code
- CC=powerpc64-linux-gnu-gcc RUN_ENV="qemu-ppc64-static -cpu power8" CPPFLAGS=-DXXH_VECTOR=XXH_VSX CFLAGS="-O3 -maltivec -mvsx -mcpu=power8 -mpower8-vector" LDFLAGS="-static -m64" make check # Auto code path
- make clean
- CC=powerpc64-linux-gnu-gcc RUN_ENV="qemu-ppc64-static -cpu power8" CPPFLAGS=-DXXH_VECTOR=XXH_VSX CFLAGS="-O3 -maltivec -mvsx -mcpu=power8 -mpower8-vector" LDFLAGS="-static -m64" make check # VSX code path
# altivec.h redefinition issue #426
- make clean
- CC=powerpc64-linux-gnu-gcc CPPFLAGS=-DXXH_VECTOR=XXH_VSX CFLAGS="-maltivec -mvsx -mcpu=power8 -mpower8-vector" make -C tests test_ppc_redefine
- name: PPC64LE compilation and consistency checks
dist: xenial
@ -107,6 +109,9 @@ matrix:
# VSX code path (64-bit)
- make clean
- CPPFLAGS=-DXXH_VECTOR=XXH_VSX CFLAGS="-O3 -maltivec -mvsx -mpower8-vector -mcpu=power8" LDFLAGS="-static" make check
# altivec.h redefinition issue #426
- make clean
- CPPFLAGS=-DXXH_VECTOR=XXH_VSX CFLAGS="-maltivec -mvsx -mcpu=power8 -mpower8-vector" make -C tests test_ppc_redefine
- name: IBM s390x compilation and consistency checks
dist: bionic

View File

@ -1,4 +1,4 @@
CFLAGS += -Wall -Wextra -g
CFLAGS += -Wall -Wextra -Wundef -g
NM = nm
GREP = grep
@ -47,6 +47,11 @@ test_multiInclude:
# ! $(NM) multiInclude | $(GREP) TESTN_
#@$(MAKE) clean
.PHONY: test_ppc_redefine
test_ppc_redefine: ppc_define.c
@$(MAKE) clean
$(CC) $(CPPFLAGS) $(CFLAGS) -c $^
xxhsum$(EXT): ../xxhash.c ../xxhash.h ../xxhsum.c
$(CC) $(CFLAGS) $(LDFLAGS) ../xxhash.c ../xxhsum.c -o $@

62
tests/ppc_define.c Normal file
View File

@ -0,0 +1,62 @@
/*
* Multi-include test program
* ensure that pixel, bool and vector are not redefined
*
* Copyright (C) 2020 Yann Collet
*
* GPL v2 License
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* You can contact the author at:
* - xxHash homepage: https://www.xxhash.com
* - xxHash source repository: https://github.com/Cyan4973/xxHash
*/
/* gcc's altivec.h, included for the VSX code path,
* may, in some circumstances, redefine
* bool, vector and pixel keywords.
*
* This unit checks if it happens.
* It's a compile test.
* The test is mostly meaningful for PPC target using altivec.h
* hence XXH_VECTOR == XXH_VSX
*/
#define BOOL_VALUE 32123456
#define bool BOOL_VALUE
#define VECTOR_VALUE 374464784
#define vector VECTOR_VALUE
#define PIXEL_VALUE 5846841
#define pixel PIXEL_VALUE
#define XXH_INLINE_ALL
#include "../xxhash.h"
#if (bool != BOOL_VALUE)
# error "bool macro was redefined !"
#endif
#if (vector != VECTOR_VALUE)
# error "vector macro was redefined !"
#endif
#if (pixel != PIXEL_VALUE)
# error "pixel macro was redefined !"
#endif
int g_nonEmptyUnit = 0;

View File

@ -2398,11 +2398,20 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src
# if defined(__s390x__)
# include <s390intrin.h>
# else
/* gcc's altivec.h can have the unwanted consequence to unconditionally
* #define bool, vector, and pixel keywords,
* with bad consequences for programs already using these keywords for other purposes.
* The paragraph defining these macros is skipped when __APPLE_ALTIVEC__ is defined.
* __APPLE_ALTIVEC__ is _generally_ defined automatically by the compiler,
* but it seems that, in some cases, it isn't.
* Force the build macro to be defined, so that keywords are not altered.
*/
# if defined(__GNUC__) && !defined(__APPLE_ALTIVEC__)
# define __APPLE_ALTIVEC__
# endif
# include <altivec.h>
# endif
# undef vector /* Undo the pollution */
typedef __vector unsigned long long xxh_u64x2;
typedef __vector unsigned char xxh_u8x16;
typedef __vector unsigned xxh_u32x4;