[Libreoffice-commits] core.git: Branch 'aoo/trunk' - sal/cpprt sal/rtl set_soenv.in solenv/gbuild solenv/inc
Don Lewis
truckman at apache.org
Sat Apr 28 04:09:43 UTC 2018
sal/cpprt/operators_new_delete.cxx | 12 ++++++++++++
sal/rtl/source/alloc_cache.c | 6 ++++++
sal/rtl/source/alloc_global.c | 5 +++++
sal/rtl/source/alloc_impl.h | 6 ++++++
set_soenv.in | 11 ++++++++++-
solenv/gbuild/platform/freebsd.mk | 2 +-
solenv/gbuild/platform/linux.mk | 2 +-
solenv/gbuild/platform/macosx.mk | 2 +-
solenv/gbuild/platform/os2.mk | 2 +-
solenv/gbuild/platform/solaris.mk | 2 +-
solenv/gbuild/platform/windows.mk | 2 +-
solenv/gbuild/platform/winmingw.mk | 2 +-
solenv/inc/settings.mk | 2 +-
13 files changed, 47 insertions(+), 9 deletions(-)
New commits:
commit a3e1123456ebafe8aed405534557230a833460a0
Author: Don Lewis <truckman at apache.org>
Date: Sat Apr 28 02:47:11 2018 +0000
Fix potential memory alignment issues on X86_64.
Clang version 4.0 and newer uses SSE instructions that require
16-byte alignment to zero memory allocated using the C++ new operator.
The internal memory allocator does not understand anything larger
than 8-byte alignment. Modify it to be capable of doing 16-byte
alignment when necessary.
There is also a debug layer beneath the C++ new and delete operators
that is enabled by the --enable-debug configure option. This layer
adds 8 to the requested size of any allocations before calling the
underlying allocator, adds a known signature to the start of the
memory block, and then adds an 8 byte offset to the pointer before
returning it to the caller. The delete operator basically does the
reverse, checking for the proper signature. Modify this code so
that it adds and subtracts a 16-byte offset on X86_64 so that a
properly aligned block from the underlying allocator does not cause
new to return a misaligned pointer.
Modify set_soenv.in so that it always requests 16-byte alignment
on X86_64 so that the ABI is the same independent of the toolchain.
diff --git a/sal/cpprt/operators_new_delete.cxx b/sal/cpprt/operators_new_delete.cxx
index abd4c73aa116..da05584da124 100644
--- a/sal/cpprt/operators_new_delete.cxx
+++ b/sal/cpprt/operators_new_delete.cxx
@@ -68,7 +68,11 @@ struct AllocatorTraits
{
n = std::max(n, std::size_t(1));
#if OSL_DEBUG_LEVEL > 0
+# ifdef NEED_ALIGN16
+ n += 2*sizeof(signature_type);
+# else
n += sizeof(signature_type);
+# endif
#endif /* OSL_DEBUG_LEVEL */
return n;
}
@@ -77,7 +81,11 @@ struct AllocatorTraits
{
#if OSL_DEBUG_LEVEL > 0
memcpy (p, m_signature, sizeof(signature_type));
+# ifdef NEED_ALIGN16
+ p = static_cast<char*>(p) + 2*sizeof(signature_type);
+# else
p = static_cast<char*>(p) + sizeof(signature_type);
+# endif
#endif /* OSL_DEBUG_LEVEL */
return p;
}
@@ -85,7 +93,11 @@ struct AllocatorTraits
void* fini (void * p) const SAL_THROW(())
{
#if OSL_DEBUG_LEVEL > 0
+# ifdef NEED_ALIGN16
+ p = static_cast<char*>(p) - 2*sizeof(signature_type);
+# else
p = static_cast<char*>(p) - sizeof(signature_type);
+# endif
if (memcmp (p, m_signature, sizeof(signature_type)) != 0)
{
OSL_ENSURE(0, "operator delete mismatch");
diff --git a/sal/rtl/source/alloc_cache.c b/sal/rtl/source/alloc_cache.c
index 7f026968ce9f..30c0d9f687c4 100644
--- a/sal/rtl/source/alloc_cache.c
+++ b/sal/rtl/source/alloc_cache.c
@@ -894,7 +894,13 @@ rtl_cache_activate (
if (objalign == 0)
{
/* determine default alignment */
+#ifdef NEED_ALIGN16
+ if (objsize >= RTL_MEMORY_ALIGNMENT_16)
+ objalign = RTL_MEMORY_ALIGNMENT_16;
+ else if (objsize >= RTL_MEMORY_ALIGNMENT_8)
+#else
if (objsize >= RTL_MEMORY_ALIGNMENT_8)
+#endif
objalign = RTL_MEMORY_ALIGNMENT_8;
else
objalign = RTL_MEMORY_ALIGNMENT_4;
diff --git a/sal/rtl/source/alloc_global.c b/sal/rtl/source/alloc_global.c
index f8c71284fffa..c525b77e7a30 100644
--- a/sal/rtl/source/alloc_global.c
+++ b/sal/rtl/source/alloc_global.c
@@ -75,8 +75,13 @@ static rtl_cache_type * g_alloc_caches[RTL_MEMORY_CACHED_SIZES] =
0,
};
+#ifdef NEED_ALIGN16
+#define RTL_MEMALIGN 16
+#define RTL_MEMALIGN_SHIFT 4
+#else
#define RTL_MEMALIGN 8
#define RTL_MEMALIGN_SHIFT 3
+#endif
static rtl_cache_type * g_alloc_table[RTL_MEMORY_CACHED_LIMIT >> RTL_MEMALIGN_SHIFT] =
{
diff --git a/sal/rtl/source/alloc_impl.h b/sal/rtl/source/alloc_impl.h
index b6ee2d5ce504..866d1db30fa0 100644
--- a/sal/rtl/source/alloc_impl.h
+++ b/sal/rtl/source/alloc_impl.h
@@ -45,6 +45,12 @@ extern "C" {
#define RTL_MEMORY_ALIGNMENT_8 sizeof(void*)
#endif /* SAL_TYPES_ALIGNMENT8 */
+#if defined(SAL_TYPES_ALIGNMENT16) && SAL_TYPES_ALIGNMENT16 > 1
+#define RTL_MEMORY_ALIGNMENT_16 SAL_TYPES_ALIGNMENT16
+#else
+#define RTL_MEMORY_ALIGNMENT_16 16
+#endif /* SAL_TYPES_ALIGNMENT16 */
+
#if 0 /* @@@ */
#define RTL_MEMORY_ALIGNMENT_1 8
#define RTL_MEMORY_ALIGNMENT_2 (sizeof(void*) * 2)
diff --git a/set_soenv.in b/set_soenv.in
index 7343f2061455..b4acb948299e 100644
--- a/set_soenv.in
+++ b/set_soenv.in
@@ -74,7 +74,7 @@ my ( $CALL_CDECL, $COMMON_OUTDIR, $BMP_WRITES_FLAG,
$BUILD_SOSL_RELEASE, $RSC_ONCE );
#
# Platform dependent constant values.
-my ( $BIG_SVX, $ARCH, $CPU, $CPUNAME, $CVER, $GLIBC, $GUI, $GUIBASE,
+my ( $BIG_SVX, $ALIGN, $ARCH, $CPU, $CPUNAME, $CVER, $GLIBC, $GUI, $GUIBASE,
$GVER, $OS, $OSVERSION, $OUTPATH, $INPATH, $PATH_SEPERATOR,
$DYNAMIC_CRT, $SET_EXCEPTIONS, $use_shl_versions, $CDPATHx, $JRELIBDIR,
$JRETOOLKITDIR, $JRETHREADDIR,
@@ -850,6 +850,14 @@ else {
print "For $platform.\n";
exit 1;
}
+
+if ( $CPUNAME eq "X86_64") {
+ $ALIGN = "NEED_ALIGN16";
+}
+else {
+ $ALIGN = "NEED_ALIGN8";
+}
+
print "done\n";
#
@@ -1727,6 +1735,7 @@ ToFile( "CCVER", "@CCVER@", "e" );
ToFile( "CXX_X64_BINARY", $CXX_X64_BINARY, "e" );
ToFile( "LINK_X64_BINARY", $LINK_X64_BINARY, "e" );
ToFile( "LIBMGR_X64_BINARY", $LIBMGR_X64_BINARY, "e" );
+ToFile( "ALIGN", $ALIGN, "e" );
ToFile( "CPU", $CPU, "e" );
ToFile( "CPUNAME", $CPUNAME, "e" );
ToFile( "CVER", $CVER, "e" );
diff --git a/solenv/gbuild/platform/freebsd.mk b/solenv/gbuild/platform/freebsd.mk
index 0148fc23fe57..e7f6a2836958 100644
--- a/solenv/gbuild/platform/freebsd.mk
+++ b/solenv/gbuild/platform/freebsd.mk
@@ -61,7 +61,7 @@ gb_COMPILERDEFS := \
-DHAVE_GCC_VISIBILITY_FEATURE \
-DCPPU_ENV=$(COMNAME) \
-gb_CPUDEFS := -D$(CPUNAME)
+gb_CPUDEFS := -D$(ALIGN) -D$(CPUNAME)
ifeq ($(CPUNAME),INTEL)
gb_CPUDEFS += -DX86
endif
diff --git a/solenv/gbuild/platform/linux.mk b/solenv/gbuild/platform/linux.mk
index 8ae6a5e005ba..e9e991f4d566 100644
--- a/solenv/gbuild/platform/linux.mk
+++ b/solenv/gbuild/platform/linux.mk
@@ -58,7 +58,7 @@ gb_COMPILERDEFS := \
-DHAVE_GCC_VISIBILITY_FEATURE \
-DCPPU_ENV=$(COMNAME) \
-gb_CPUDEFS := -D$(CPUNAME)
+gb_CPUDEFS := -D$(ALIGN) -D$(CPUNAME)
ifeq ($(CPUNAME),INTEL)
gb_CPUDEFS += -DX86
endif
diff --git a/solenv/gbuild/platform/macosx.mk b/solenv/gbuild/platform/macosx.mk
index 8497342ddaf6..fc54d1e66f1b 100644
--- a/solenv/gbuild/platform/macosx.mk
+++ b/solenv/gbuild/platform/macosx.mk
@@ -59,7 +59,7 @@ gb_COMPILERDEFS := \
-DHAVE_GCC_VISIBILITY_FEATURE \
-DCPPU_ENV=$(COMNAME) \
-gb_CPUDEFS := -D$(CPUNAME)
+gb_CPUDEFS := -D$(ALIGN) -D$(CPUNAME)
ifeq ($(CPUNAME),POWERPC)
gb_CPUDEFS += -DPOWERPC -DPPC
else ifeq ($(CPUNAME),INTEL)
diff --git a/solenv/gbuild/platform/os2.mk b/solenv/gbuild/platform/os2.mk
index cccbdc90ef29..aa6965a46b55 100644
--- a/solenv/gbuild/platform/os2.mk
+++ b/solenv/gbuild/platform/os2.mk
@@ -60,7 +60,7 @@ gb_COMPILERDEFS := \
-DHAVE_GCC_VISIBILITY_FEATURE \
-DCPPU_ENV=$(COMNAME) \
-gb_CPUDEFS := -DINTEL -D_X86_=1 -DX86
+gb_CPUDEFS := -D$(ALIGN) -DINTEL -D_X86_=1 -DX86
gb_RCDEFS := \
-DOS2 \
diff --git a/solenv/gbuild/platform/solaris.mk b/solenv/gbuild/platform/solaris.mk
index 17961a7ea124..bf2f57318a73 100644
--- a/solenv/gbuild/platform/solaris.mk
+++ b/solenv/gbuild/platform/solaris.mk
@@ -57,7 +57,7 @@ gb_COMPILERDEFS := \
-D$(COM) \
-DCPPU_ENV=$(COMNAME) \
-gb_CPUDEFS := -D$(CPUNAME)
+gb_CPUDEFS := -D$(ALIGN) -D$(CPUNAME)
ifeq ($(CPUNAME),SPARC)
gb_CPUDEFS += -D__sparcv8plus
endif
diff --git a/solenv/gbuild/platform/windows.mk b/solenv/gbuild/platform/windows.mk
index 5f8baab0d52c..0b549aeeef5b 100644
--- a/solenv/gbuild/platform/windows.mk
+++ b/solenv/gbuild/platform/windows.mk
@@ -63,7 +63,7 @@ gb_COMPILERDEFS := \
-DFULL_DESK \
-DM1500 \
-gb_CPUDEFS := -D$(CPUNAME)
+gb_CPUDEFS := -D$(ALIGN) -D$(CPUNAME)
ifeq ($(CPUNAME),INTEL)
gb_CPUDEFS += -D_X86_=1
endif
diff --git a/solenv/gbuild/platform/winmingw.mk b/solenv/gbuild/platform/winmingw.mk
index f48ae6caac23..4cbf914e25b9 100644
--- a/solenv/gbuild/platform/winmingw.mk
+++ b/solenv/gbuild/platform/winmingw.mk
@@ -87,7 +87,7 @@ ifeq ($(USE_MINGW),cygwin-w64-mingw32)
gb_COMPILERDEFS +=-D_declspec=__declspec
endif
-gb_CPUDEFS := -D$(CPUNAME)
+gb_CPUDEFS := -D$(ALIGN) -D$(CPUNAME)
gb_CPUDEFS += \
-D_M_IX86 \
diff --git a/solenv/inc/settings.mk b/solenv/inc/settings.mk
index 4a7ac377af2d..a7aa9295d315 100644
--- a/solenv/inc/settings.mk
+++ b/solenv/inc/settings.mk
@@ -878,7 +878,7 @@ UNOIDLDEPFLAGS=-Mdepend=$(SOLARVER)
UNOIDLINC+=-I. -I.. -I$(PRJ) -I$(PRJ)/inc -I$(PRJ)/$(INPATH)/idl -I$(OUT)/inc -I$(SOLARIDLDIR) -I$(SOLARINCDIR)
-CDEFS= -D$(OS) -D$(GUI) -D$(GVER) -D$(COM) -D$(CVER) -D$(CPUNAME) -DCPPU_ENV=$(COMNAME)
+CDEFS= -D$(OS) -D$(GUI) -D$(GVER) -D$(COM) -D$(CVER) -D$(ALIGN) -D$(CPUNAME) -DCPPU_ENV=$(COMNAME)
.IF "$(USE_STLP_DEBUG)" != "" && "$(GUI)"!="OS2"
CDEFS+=-D_STLP_DEBUG
More information about the Libreoffice-commits
mailing list