diff --git a/CMakeLists.txt b/CMakeLists.txt index d57e18275..8dcf6793d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,9 @@ if(HAVE_X86_SSE_MATH) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -mfpmath=sse") endif() +# On i386 Linux we can fix unaligned SSE malloc (see GitHub issue #4432) +include(FindUnalignedMalloc) + if(WIN32) # Add additional paths. Look in the MinGW path first, then in the Gtkmm path. # If you wish to build some dependent libraries, you have to install them in MinGW to use them: diff --git a/cmake/modules/FindUnalignedMalloc.cmake b/cmake/modules/FindUnalignedMalloc.cmake new file mode 100644 index 000000000..4ddfb2afc --- /dev/null +++ b/cmake/modules/FindUnalignedMalloc.cmake @@ -0,0 +1,49 @@ +# This file is part of RawTherapee. +# +# Copyright (C) 2018 Flössie +# +# RawTherapee 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 3 of the License, or +# (at your option) any later version. +# +# RawTherapee 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 RawTherapee. If not, see . + +include(CheckCXXSourceCompiles) + +set(CMAKE_REQUIRED_QUIET_COPY "${CMAKE_REQUIRED_QUIET}") +set(CMAKE_REQUIRED_QUIET ON) + +set(TEST_SOURCE +" +#include +#include + +int main() +{ +#if defined(__SSE2__) && (defined(__i386) || defined(_M_IX86)) && defined(__linux) + static_assert(std::alignment_of::value >= 16, \"Unaligned heap objects possible\"); +#endif + + return 0; +} +") + +CHECK_CXX_SOURCE_COMPILES("${TEST_SOURCE}" HAVE_ALIGNED_MALLOC) + +if(NOT HAVE_ALIGNED_MALLOC) + set(HAVE_UNALIGNED_MALLOC 1) +else() + unset(HAVE_ALIGNED_MALLOC) +endif() + +unset(TEST_SOURCE) + +set(CMAKE_REQUIRED_QUIET "${CMAKE_REQUIRED_QUIET_COPY}") +unset(CMAKE_REQUIRED_QUIET_COPY) diff --git a/rtgui/CMakeLists.txt b/rtgui/CMakeLists.txt index 540b4d267..c39ed004c 100644 --- a/rtgui/CMakeLists.txt +++ b/rtgui/CMakeLists.txt @@ -1,5 +1,6 @@ # Common source files for both CLI and non-CLI execautables set(CLISOURCEFILES + alignedmalloc.cc edit.cc main-cli.cc multilangmgr.cc @@ -11,6 +12,7 @@ set(CLISOURCEFILES set(NONCLISOURCEFILES adjuster.cc + alignedmalloc.cc batchqueue.cc batchqueuebuttonset.cc batchqueueentry.cc diff --git a/rtgui/alignedmalloc.cc b/rtgui/alignedmalloc.cc new file mode 100644 index 000000000..91fe15a85 --- /dev/null +++ b/rtgui/alignedmalloc.cc @@ -0,0 +1,31 @@ +/* + * This file is part of RawTherapee. + * + * Copyright (C) 2018 Flössie + * + * RawTherapee 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 3 of the License, or + * (at your option) any later version. + * + * RawTherapee 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 RawTherapee. If not, see . + */ + +#include "config.h" + +#ifdef HAVE_UNALIGNED_MALLOC + +#include + +void* malloc(size_t size) +{ + return memalign(16, size); +} + +#endif diff --git a/rtgui/config.h.in b/rtgui/config.h.in index fdf64b73c..2d1f41dbc 100644 --- a/rtgui/config.h.in +++ b/rtgui/config.h.in @@ -21,6 +21,7 @@ #define __CONFIG_H__ #cmakedefine BUILD_BUNDLE +#cmakedefine HAVE_UNALIGNED_MALLOC #define DATA_SEARCH_PATH "${DATADIR}" #define DOC_SEARCH_PATH "${DOCDIR}" #define CREDITS_SEARCH_PATH "${CREDITSDIR}"