[vlc-devel] [PATCH] configure: restrict from applying gcc only flags to other compilers.

Rafaël Carré funman at videolan.org
Fri Mar 2 03:25:56 CET 2012


Hi,

Le 2012-03-01 19:39, Francois Cartegnie a écrit :
> Applying gcc's optimizations to other compilers lead to undefined
> behavior.
> In the suncc case, the build will fail later because of default
> propagation of unknown flags to the linker.
> ---
>  configure.ac |   95 +++++++++++++++++++++++++++++++++++++++-------------------
>  1 files changed, 64 insertions(+), 31 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 2a74fe6..4f042e2 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -858,6 +858,13 @@ AS_IF([test "${enable_debug}" != "no"], [
>    AC_DEFINE(NDEBUG)
>  ])
>  
> +dnl Set up version & compiler variables for various hacks
> +if test "$GCC" != "yes"; then
> +  AC_CHECK_DECL([__SUNPRO_C], [COMPILER="suncc"], [COMPILER=""])

Perhaps we should set it to "unknown" and display the result with
AC_MSG, that might give a hint to people using other compilers that they
want to look at configure.ac

> +else
> +  COMPILER="gcc"
> +fi
> +
>  dnl
>  dnl  Profiling
>  dnl
> @@ -895,11 +902,19 @@ AS_IF([test "${enable_coverage}" != "no"], [
>  ])
>  
>  AS_IF([test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"], [
> +  case "${COMPILER}" in
> +  "suncc")
> +    SYMBOLSVISIBILITY="-xldscope=symbolic"
> +  ;;
> +  *)
> +    SYMBOLSVISIBILITY="-fvisibility=hidden"
> +  ;;
> +  esac
>    VLC_SAVE_FLAGS
> -  CFLAGS="${CFLAGS} -fvisibility=hidden"
> -  CXXFLAGS="${CXXFLAGS} -fvisibility=hidden"
> -  OBJCFLAGS="${OBJCFLAGS} -fvisibility=hidden"
> -  AC_CACHE_CHECK([if $CC accepts -fvisibility=hidden],
> +  CFLAGS="${CFLAGS} ${SYMBOLSVISIBILITY}"
> +  CXXFLAGS="${CXXFLAGS} ${SYMBOLSVISIBILITY}"
> +  OBJCFLAGS="${OBJCFLAGS} ${SYMBOLSVISIBILITY}"
> +  AC_CACHE_CHECK([if $CC accepts $SYMBOLSVISIBILITY],
>                   [ac_cv_c_visibility_hidden], [
>      AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
>        ac_cv_c_visibility_hidden=yes
> @@ -910,7 +925,6 @@ AS_IF([test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"], [
>    AS_IF([test "${ac_cv_c_visibility_hidden}" = "no"], [VLC_RESTORE_FLAGS])
>  ])
>  
> -
>  dnl
>  dnl  Enable/disable optimizations
>  dnl

cosmetics

> @@ -925,10 +939,10 @@ AS_IF([test "${enable_optimizations}" != "no"], [
>    dnl -O4 and -O3 only in production builds
>    AS_IF([test "{enable_debug}" = "no"], [
>      VLC_SAVE_FLAGS
> -    CFLAGS="${CFLAGS} -O4"
> -    CXXFLAGS="${CXXFLAGS} -O4"
> -    OBJCFLAGS="${OBJCFLAGS} -O4"
> -    AC_CACHE_CHECK([if $CC accepts -O4], [ac_cv_c_o4], [
> +    CFLAGS="${CFLAGS} ${OPTIMIZATION_LEVEL4}"
> +    CXXFLAGS="${CXXFLAGS} ${OPTIMIZATION_LEVEL4}"
> +    OBJCFLAGS="${OBJCFLAGS} ${OPTIMIZATION_LEVEL4}"
> +    AC_CACHE_CHECK([if $CC accepts $OPTIMIZATION_LEVEL4], [ac_cv_c_o4], [
>        AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
>          ac_cv_c_o4=yes
>        ], [

Afaik gcc doesn't know what -O4 is, optimizations level only go up to 3,
so we should probably remove this.
I think I brought this question previously, don't remember if I didn't
do it by laziness or for a valid reason.

Some programs (libdvbpsi for example) use -O6 which breaks clang, those
levels probably come from another compiler which was somehow widely used.

> @@ -937,10 +951,10 @@ AS_IF([test "${enable_optimizations}" != "no"], [
>      ])
>      AS_IF([test "${ac_cv_c_o4}" = "no"], [
>        VLC_RESTORE_FLAGS
> -      CFLAGS="${CFLAGS} -O3"
> -      CXXFLAGS="${CXXFLAGS} -O3"
> -      OBJCFLAGS="${OBJCFLAGS} -O3"
> -      AC_CACHE_CHECK([if $CC accepts -O3],  [ac_cv_c_o3], [
> +      CFLAGS="${CFLAGS} ${OPTIMIZATION_LEVEL3}"

Where is OPTIMIZATION_LEVEL3 defined?

> +      CXXFLAGS="${CXXFLAGS} ${OPTIMIZATION_LEVEL3}"
> +      OBJCFLAGS="${OBJCFLAGS} ${OPTIMIZATION_LEVEL3}"
> +      AC_CACHE_CHECK([if $CC accepts $OPTIMIZATION_LEVEL3],  [ac_cv_c_o3], [
>          AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
>            ac_cv_c_o3=yes
>          ], [
> @@ -953,10 +967,10 @@ AS_IF([test "${enable_optimizations}" != "no"], [
>  
>    dnl Check for -ffast-math
>    VLC_SAVE_FLAGS
> -  CFLAGS="${CFLAGS} -ffast-math"
> -  CXXFLAGS="${CXXFLAGS} -ffast-math"
> -  OBJCFLAGS="${OBJCFLAGS} -ffast-math"
> -  AC_CACHE_CHECK([if $CC accepts -ffast-math], [ac_cv_c_fast_math], [
> +  CFLAGS="${CFLAGS} ${OPTIMIZATION_MATH}"
> +  CXXFLAGS="${CXXFLAGS} ${OPTIMIZATION_MATH}"
> +  OBJCFLAGS="${OBJCFLAGS} ${OPTIMIZATION_MATH}"
> +  AC_CACHE_CHECK([if $CC accepts $OPTIMIZATION_MATH], [ac_cv_c_fast_math], [
>      AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
>        ac_cv_c_fast_math=yes
>      ], [

Same here

> @@ -967,10 +981,10 @@ AS_IF([test "${enable_optimizations}" != "no"], [
>  
>    dnl Check for -funroll-loops
>    VLC_SAVE_FLAGS
> -  CFLAGS="${CFLAGS} -funroll-loops"
> -  CXXFLAGS="${CXXFLAGS} -funroll-loops"
> -  OBJCFLAGS="${OBJCFLAGS} -funroll-loops"
> -  AC_CACHE_CHECK([if $CC accepts -funroll-loops], [ac_cv_c_unroll_loops], [
> +  CFLAGS="${CFLAGS} ${OPTIMIZATION_UNROLL}"
> +  CXXFLAGS="${CXXFLAGS} ${OPTIMIZATION_UNROLL}"
> +  OBJCFLAGS="${OBJCFLAGS} ${OPTIMIZATION_UNROLL}"
> +  AC_CACHE_CHECK([if $CC accepts $OPTIMIZATION_UNROLL], [ac_cv_c_unroll_loops], [
>      AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
>        ac_cv_c_unroll_loops=yes
>      ], [

Same here

> @@ -982,10 +996,10 @@ AS_IF([test "${enable_optimizations}" != "no"], [
>    AS_IF([test "$enable_debug" = "no"], [
>      dnl Check for -fomit-frame-pointer
>      VLC_SAVE_FLAGS
> -    CFLAGS="${CFLAGS} -fomit-frame-pointer"
> -    CXXFLAGS="${CXXFLAGS} -fomit-frame-pointer"
> -    OBJCFLAGS="${OBJCFLAGS} -fomit-frame-pointer"
> -    AC_CACHE_CHECK([if $CC accepts -fomit-frame-pointer],
> +    CFLAGS="${CFLAGS} ${OPTIMIZATION_OMITFRAMEPTR}"
> +    CXXFLAGS="${CXXFLAGS} ${OPTIMIZATION_OMITFRAMEPTR}"
> +    OBJCFLAGS="${OBJCFLAGS} ${OPTIMIZATION_OMITFRAMEPTR}"
> +    AC_CACHE_CHECK([if $CC accepts $OPTIMIZATION_OMITFRAMEPTR],
>        [ac_cv_c_omit_frame_pointer], [
>        AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
>          ac_cv_c_omit_frame_pointer=yes

Same here

> @@ -995,6 +1009,7 @@ AS_IF([test "${enable_optimizations}" != "no"], [
>      ])
>      AS_IF([test "${ac_cv_c_omit_frame_pointer}" = "no"], [VLC_RESTORE_FLAGS])
>    ])
> +
>  ])
>  
>  dnl Check for Darwin plugin linking flags

cosmetics

> @@ -1489,21 +1504,39 @@ dnl
>  AC_ARG_WITH(tuning,
>    [AS_HELP_STRING([--with-tuning=ARCH],
>      [tune compilation for an architecture (default varies)])])
> +case "${COMPILER}" in
> +"suncc")
> +  TUNING_KEYWORD="-xtarget="
> +  TUNING_DARWINi686="-xtarget=generic"
> +  TUNING_DARWINx8664="-xtarget=generic"
> +  TUNING_i686="-xtarget=generic"
> +  TUNING_x8664="-xtarget=generic"
> +  TUNING_POWERPC="-xarch=ppc"
> +;;
> +*)

Shouldn't this be "gcc" ?

> +  TUNING_KEYWORD="-mtune="
> +  TUNING_DARWINi686="-march=prescott -mtune=generic"
> +  TUNING_DARWINx8664="-march=core2 -mtune=core2"

cosmetics but I would prefer TUNING_DARWIN_x86_64

> +  TUNING_i686="-mtune=pentium2"
> +  TUNING_x8664="-mtune=athlon64"

And x86_64 here too

> +  TUNING_POWERPC="-mtune=G4"
> +;;
> +esac
>  if test -n "${with_tuning}"; then
>      if test "${with_tuning}" != "no"; then
> -        CFLAGS_TUNING="-mtune=${with_tuning}"
> +        CFLAGS_TUNING="${TUNING_KEYWORD}${with_tuning}"
>      fi
>  else
>      if test "${SYS}" = "darwin" -a "${host_cpu}" = "i686"; then
> -        CFLAGS_TUNING="-march=prescott -mtune=generic"
> +        CFLAGS_TUNING="${TUNING_DARWINi686}"
>      elif test "${SYS}" = "darwin" -a "${host_cpu}" = "x86_64"; then
> -        CFLAGS_TUNING="-march=core2 -mtune=core2"
> +        CFLAGS_TUNING="${TUNING_DARWINx8664}"
>      elif test "${host_cpu}" = "i686" -o "${host_cpu}" = "i586" -o "${host_cpu}" = "i486" -o "${host_cpu}" = "i386"; then
> -        CFLAGS_TUNING="-mtune=pentium2"
> +        CFLAGS_TUNING="${TUNING_i686}"
>      elif test "${host_cpu}" = "x86_64"; then
> -        CFLAGS_TUNING="-mtune=athlon64"
> +        CFLAGS_TUNING="${TUNING_x8664}"
>      elif test "${host_cpu}" = "powerpc"; then
> -        CFLAGS_TUNING="-mtune=G4";
> +        CFLAGS_TUNING="${TUNING_POWERPC}"
>      fi
>  fi
>  




More information about the vlc-devel mailing list