openoffice-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From truck...@apache.org
Subject svn commit: r1830406 - in /openoffice/trunk/main: ./ sal/cpprt/ sal/rtl/source/ solenv/gbuild/platform/ solenv/inc/
Date Sat, 28 Apr 2018 02:47:11 GMT
Author: truckman
Date: Sat Apr 28 02:47:11 2018
New Revision: 1830406

URL: http://svn.apache.org/viewvc?rev=1830406&view=rev
Log:
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.


Modified:
    openoffice/trunk/main/sal/cpprt/operators_new_delete.cxx
    openoffice/trunk/main/sal/rtl/source/alloc_cache.c
    openoffice/trunk/main/sal/rtl/source/alloc_global.c
    openoffice/trunk/main/sal/rtl/source/alloc_impl.h
    openoffice/trunk/main/set_soenv.in
    openoffice/trunk/main/solenv/gbuild/platform/freebsd.mk
    openoffice/trunk/main/solenv/gbuild/platform/linux.mk
    openoffice/trunk/main/solenv/gbuild/platform/macosx.mk
    openoffice/trunk/main/solenv/gbuild/platform/os2.mk
    openoffice/trunk/main/solenv/gbuild/platform/solaris.mk
    openoffice/trunk/main/solenv/gbuild/platform/windows.mk
    openoffice/trunk/main/solenv/gbuild/platform/winmingw.mk
    openoffice/trunk/main/solenv/inc/settings.mk

Modified: openoffice/trunk/main/sal/cpprt/operators_new_delete.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/cpprt/operators_new_delete.cxx?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/sal/cpprt/operators_new_delete.cxx (original)
+++ openoffice/trunk/main/sal/cpprt/operators_new_delete.cxx Sat Apr 28 02:47:11 2018
@@ -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");

Modified: openoffice/trunk/main/sal/rtl/source/alloc_cache.c
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/rtl/source/alloc_cache.c?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/sal/rtl/source/alloc_cache.c (original)
+++ openoffice/trunk/main/sal/rtl/source/alloc_cache.c Sat Apr 28 02:47:11 2018
@@ -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;

Modified: openoffice/trunk/main/sal/rtl/source/alloc_global.c
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/rtl/source/alloc_global.c?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/sal/rtl/source/alloc_global.c (original)
+++ openoffice/trunk/main/sal/rtl/source/alloc_global.c Sat Apr 28 02:47:11 2018
@@ -75,8 +75,13 @@ static rtl_cache_type * g_alloc_caches[R
 	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]
=
 {

Modified: openoffice/trunk/main/sal/rtl/source/alloc_impl.h
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sal/rtl/source/alloc_impl.h?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/sal/rtl/source/alloc_impl.h (original)
+++ openoffice/trunk/main/sal/rtl/source/alloc_impl.h Sat Apr 28 02:47:11 2018
@@ -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)

Modified: openoffice/trunk/main/set_soenv.in
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/set_soenv.in?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/set_soenv.in (original)
+++ openoffice/trunk/main/set_soenv.in Sat Apr 28 02:47:11 2018
@@ -74,7 +74,7 @@ my ( $CALL_CDECL, $COMMON_OUTDIR, $BMP_W
      $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@",
 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" );

Modified: openoffice/trunk/main/solenv/gbuild/platform/freebsd.mk
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/solenv/gbuild/platform/freebsd.mk?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/solenv/gbuild/platform/freebsd.mk (original)
+++ openoffice/trunk/main/solenv/gbuild/platform/freebsd.mk Sat Apr 28 02:47:11 2018
@@ -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

Modified: openoffice/trunk/main/solenv/gbuild/platform/linux.mk
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/solenv/gbuild/platform/linux.mk?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/solenv/gbuild/platform/linux.mk (original)
+++ openoffice/trunk/main/solenv/gbuild/platform/linux.mk Sat Apr 28 02:47:11 2018
@@ -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

Modified: openoffice/trunk/main/solenv/gbuild/platform/macosx.mk
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/solenv/gbuild/platform/macosx.mk?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/solenv/gbuild/platform/macosx.mk (original)
+++ openoffice/trunk/main/solenv/gbuild/platform/macosx.mk Sat Apr 28 02:47:11 2018
@@ -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)

Modified: openoffice/trunk/main/solenv/gbuild/platform/os2.mk
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/solenv/gbuild/platform/os2.mk?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/solenv/gbuild/platform/os2.mk (original)
+++ openoffice/trunk/main/solenv/gbuild/platform/os2.mk Sat Apr 28 02:47:11 2018
@@ -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 \

Modified: openoffice/trunk/main/solenv/gbuild/platform/solaris.mk
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/solenv/gbuild/platform/solaris.mk?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/solenv/gbuild/platform/solaris.mk (original)
+++ openoffice/trunk/main/solenv/gbuild/platform/solaris.mk Sat Apr 28 02:47:11 2018
@@ -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

Modified: openoffice/trunk/main/solenv/gbuild/platform/windows.mk
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/solenv/gbuild/platform/windows.mk?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/solenv/gbuild/platform/windows.mk (original)
+++ openoffice/trunk/main/solenv/gbuild/platform/windows.mk Sat Apr 28 02:47:11 2018
@@ -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

Modified: openoffice/trunk/main/solenv/gbuild/platform/winmingw.mk
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/solenv/gbuild/platform/winmingw.mk?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/solenv/gbuild/platform/winmingw.mk (original)
+++ openoffice/trunk/main/solenv/gbuild/platform/winmingw.mk Sat Apr 28 02:47:11 2018
@@ -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 \
 

Modified: openoffice/trunk/main/solenv/inc/settings.mk
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/solenv/inc/settings.mk?rev=1830406&r1=1830405&r2=1830406&view=diff
==============================================================================
--- openoffice/trunk/main/solenv/inc/settings.mk (original)
+++ openoffice/trunk/main/solenv/inc/settings.mk Sat Apr 28 02:47:11 2018
@@ -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



Mime
View raw message