Temporary adjustment for strict aliasing (#2582)

* Fixes #2572.
* Added a custom rule to avoid optimization causing monsters to not attack. (From tests this appears to be npc.cpp on Centos 7 and mob.cpp on Windows vc141)
* Added -fno-strict-alising to CMake when building with GCC. (Clang and VS have it by default)
* Fixed cmake output path.
Thanks to @lighta!
This commit is contained in:
lighta
2017-11-06 17:59:59 -04:00
committed by Aleos
parent e7e9cf6d73
commit 673315994b
5 changed files with 29 additions and 10 deletions

View File

@@ -50,11 +50,12 @@ endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/${suffixInstallStr}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/${suffixInstallStr})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/${suffixInstallStr}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib/${suffixInstallStr})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_C_CREATE_SHARED_LIBRARY) set(CMAKE_C_CREATE_SHARED_LIBRARY)
set(CMAKE_CXX_CREATE_SHARED_LIBRARY) set(CMAKE_CXX_CREATE_SHARED_LIBRARY)
set(CMAKE_DEBUG_POSTFIX "d") set(CMAKE_DEBUG_POSTFIX "d")
set(CMAKE_RELEASE_POSTFIX "r") set(CMAKE_RELEASE_POSTFIX "r")
# #
# Prevent building in the source directory by default # Prevent building in the source directory by default
# #
@@ -89,6 +90,10 @@ if( MSVC )
set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} "oldnames.lib" "ws2_32.lib" ) set_property( CACHE GLOBAL_LIBRARIES PROPERTY VALUE ${GLOBAL_LIBRARIES} "oldnames.lib" "ws2_32.lib" )
set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE" ) set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE" )
endif() endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCC)
set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -fno-strict-aliasing" )
#set_property( CACHE GLOBAL_DEFINITIONS PROPERTY VALUE "${GLOBAL_DEFINITIONS} -O2" ); #need more test to enable this
endif()
# #

12
configure vendored
View File

@@ -623,6 +623,7 @@ ac_includes_default="\
ac_subst_vars='LTLIBOBJS ac_subst_vars='LTLIBOBJS
LIBOBJS LIBOBJS
CXXFLAG_CLEARS
CFLAGS_AR CFLAGS_AR
DLLEXT DLLEXT
PCRE_CFLAGS PCRE_CFLAGS
@@ -4460,7 +4461,8 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
CFLAGS="$CFLAGS -pipe -ffast-math -Wall" CFLAGS="$CFLAGS -pipe -ffast-math -Wall"
CPPFLAGS="$CPPFLAGS -I../common" CPPFLAGS="$CPPFLAGS -I../common"
CXXFLAGS="$CXXFLAGS -std=c++11" CXXFLAGS="$CXXFLAGS -std=c++11"
#CXXFLAGS="$CXXFLAGS -std=gnu++11"
CXXFLAG_CLEARS="-std=c++11"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5
$as_echo_n "checking whether byte ordering is bigendian... " >&6; } $as_echo_n "checking whether byte ordering is bigendian... " >&6; }
@@ -5763,8 +5765,8 @@ my_shared_test_flags=""
# #
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fno-strict-aliasing" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fno-strict-aliasing" >&5
$as_echo_n "checking whether $CC supports -fno-strict-aliasing... " >&6; } $as_echo_n "checking whether $CC supports -fno-strict-aliasing... " >&6; }
OLD_CFLAGS="$CFLAGS" OLD_CPPFLAGS="$CPPFLAGS"
CFLAGS="$CFLAGS -fno-strict-aliasing" CPPFLAGS="$CPPFLAGS -fno-strict-aliasing"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */ /* end confdefs.h. */
int foo; int foo;
@@ -5776,7 +5778,7 @@ else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; } $as_echo "no" >&6; }
CFLAGS="$OLD_CFLAGS" CPPFLAGS="$OLD_CPPFLAGS"
fi fi
@@ -7017,10 +7019,12 @@ else
$as_echo "no" >&6; } $as_echo "no" >&6; }
fi fi
CXXFLAG_CLEARS="-std=c++11 $CPPFLAGS"
CFLAGS="$OPT_LTO $CFLAGS" CFLAGS="$OPT_LTO $CFLAGS"
CFLAGS_AR="$OPT_LTO_AR $CFLAGS" CFLAGS_AR="$OPT_LTO_AR $CFLAGS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: Configure finish" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: Configure finish" >&5
$as_echo "$as_me: Configure finish" >&6;} $as_echo "$as_me: Configure finish" >&6;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: CPPFLAGS= $CPPFLAGS" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: CPPFLAGS= $CPPFLAGS" >&5

View File

@@ -442,7 +442,8 @@ AC_LANG([C++])
CFLAGS="$CFLAGS -pipe -ffast-math -Wall" CFLAGS="$CFLAGS -pipe -ffast-math -Wall"
CPPFLAGS="$CPPFLAGS -I../common" CPPFLAGS="$CPPFLAGS -I../common"
CXXFLAGS="$CXXFLAGS -std=c++11" CXXFLAGS="$CXXFLAGS -std=c++11"
#CXXFLAGS="$CXXFLAGS -std=gnu++11"
CXXFLAG_CLEARS="-std=c++11"
AC_C_BIGENDIAN( AC_C_BIGENDIAN(
[AC_MSG_ERROR([[bigendian is not supported... stopping]])], [AC_MSG_ERROR([[bigendian is not supported... stopping]])],
@@ -908,14 +909,14 @@ AC_SUBST([WITH_PLUGINS])
# -O2 implies -fstrict-aliasing, but the code is not safe for that # -O2 implies -fstrict-aliasing, but the code is not safe for that
# #
AC_MSG_CHECKING([whether $CC supports -fno-strict-aliasing]) AC_MSG_CHECKING([whether $CC supports -fno-strict-aliasing])
OLD_CFLAGS="$CFLAGS" OLD_CPPFLAGS="$CPPFLAGS"
CFLAGS="$CFLAGS -fno-strict-aliasing" CPPFLAGS="$CPPFLAGS -fno-strict-aliasing"
AC_COMPILE_IFELSE( AC_COMPILE_IFELSE(
[AC_LANG_SOURCE([int foo;])], [AC_LANG_SOURCE([int foo;])],
[AC_MSG_RESULT([yes])], [AC_MSG_RESULT([yes])],
[ [
AC_MSG_RESULT([no]) AC_MSG_RESULT([no])
CFLAGS="$OLD_CFLAGS" CPPFLAGS="$OLD_CPPFLAGS"
] ]
) )
@@ -1300,9 +1301,11 @@ else
AC_MSG_RESULT([no]) AC_MSG_RESULT([no])
fi fi
CXXFLAG_CLEARS="-std=c++11 $CPPFLAGS"
CFLAGS="$OPT_LTO $CFLAGS" CFLAGS="$OPT_LTO $CFLAGS"
CFLAGS_AR="$OPT_LTO_AR $CFLAGS" CFLAGS_AR="$OPT_LTO_AR $CFLAGS"
AC_SUBST([CFLAGS_AR]) AC_SUBST([CFLAGS_AR])
AC_SUBST([CXXFLAG_CLEARS])
AC_MSG_NOTICE([Configure finish]) AC_MSG_NOTICE([Configure finish])
AC_MSG_NOTICE([CPPFLAGS= $CPPFLAGS]) AC_MSG_NOTICE([CPPFLAGS= $CPPFLAGS])

View File

@@ -78,6 +78,10 @@ map-server: obj $(MAP_DIR_OBJ) $(COMMON_AR) $(LIBCONFIG_AR) $(YAML_CPP_AR)
# map object files # map object files
#cause this one failling otherwise
obj/npc.o: npc.cpp $(MAP_H) $(COMMON_H) $(MT19937AR_H) $(LIBCONFIG_H) $(YAML_CPP_H)
@echo " CXX $< (custom rule)"
@@CXX@ @CXXFLAG_CLEARS@ $(COMMON_INCLUDE) $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) $(PCRE_CFLAGS) $(YAML_CPP_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
obj/%.o: %.c $(MAP_H) $(COMMON_H) $(MT19937AR_H) $(LIBCONFIG_H) $(YAML_CPP_H) obj/%.o: %.c $(MAP_H) $(COMMON_H) $(MT19937AR_H) $(LIBCONFIG_H) $(YAML_CPP_H)
@echo " CC $<" @echo " CC $<"

View File

@@ -233,7 +233,9 @@
<ClCompile Include="map.cpp" /> <ClCompile Include="map.cpp" />
<ClCompile Include="mapreg.cpp" /> <ClCompile Include="mapreg.cpp" />
<ClCompile Include="mercenary.cpp" /> <ClCompile Include="mercenary.cpp" />
<ClCompile Include="mob.cpp" /> <ClCompile Include="mob.cpp">
<Optimization Condition="'$(Configuration)'=='Release'">Disabled</Optimization>
</ClCompile>
<ClCompile Include="npc.cpp" /> <ClCompile Include="npc.cpp" />
<ClCompile Include="npc_chat.cpp" /> <ClCompile Include="npc_chat.cpp" />
<ClCompile Include="party.cpp" /> <ClCompile Include="party.cpp" />
@@ -368,3 +370,4 @@
<Copy SourceFiles="$(SolutionDir)db\import-tmpl\status_disabled.txt" DestinationFolder="$(SolutionDir)db\import\" ContinueOnError="true" Condition="!Exists('$(SolutionDir)db\import\status_disabled.txt')" /> <Copy SourceFiles="$(SolutionDir)db\import-tmpl\status_disabled.txt" DestinationFolder="$(SolutionDir)db\import\" ContinueOnError="true" Condition="!Exists('$(SolutionDir)db\import\status_disabled.txt')" />
</Target> </Target>
</Project> </Project>