[ElectricFence] Work around too eager (and maybe buggy) GCC optimization

Petr Machata pmachata at fedoraproject.org
Thu Sep 9 16:00:21 UTC 2010


commit cb23414c9fa4899b7039e3cbf32b3d244f515252
Author: Petr Machata <pmachata at redhat.com>
Date:   Thu Sep 9 17:59:54 2010 +0200

    Work around too eager (and maybe buggy) GCC optimization

 .gitignore                       |    1 +
 ElectricFence-2.2.2-malloc.patch |   61 ++++++++++++++++++++++++++++++++++++++
 ElectricFence.spec               |   10 +++++-
 3 files changed, 71 insertions(+), 1 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 09077fd..2a0a242 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
 ElectricFence-2.2.2.tar.gz
+ElectricFence-*/
diff --git a/ElectricFence-2.2.2-malloc.patch b/ElectricFence-2.2.2-malloc.patch
new file mode 100644
index 0000000..3124a53
--- /dev/null
+++ b/ElectricFence-2.2.2-malloc.patch
@@ -0,0 +1,61 @@
+diff -up ElectricFence-2.2.2/efence.c\~ ElectricFence-2.2.2/efence.c
+--- ElectricFence-2.2.2/efence.c~	2010-09-09 17:44:35.000000000 +0200
++++ ElectricFence-2.2.2/efence.c	2010-09-09 17:47:12.000000000 +0200
+@@ -436,6 +436,8 @@ __libc_malloc_pthread_startup (bool firs
+ }
+ #endif
+ 
++extern C_LINKAGE void *__efence__malloc(size_t size);
++
+ /*
+  * allocateMoreSlots is called when there are only enough slot structures
+  * left to support the allocation of a single malloc buffer.
+@@ -451,7 +453,7 @@ allocateMoreSlots(void)
+ 	noAllocationListProtection = 1;
+ 	internalUse = 1;
+ 
+-	newAllocation = malloc(newSize);
++	newAllocation = __efence__malloc(newSize);
+ 	memcpy(newAllocation, allocationList, allocationListSize);
+ 	memset(&(((char *)newAllocation)[allocationListSize]), 0, bytesPerPage);
+ 
+@@ -853,7 +855,7 @@ realloc(void * oldBuffer, size_t newSize
+ 
+ 	lock();
+ 
+-	newBuffer = malloc(newSize);
++	newBuffer = __efence__malloc(newSize);
+ 
+ 	if ( oldBuffer ) {
+ 		size_t	size;
+@@ -893,7 +895,7 @@ realloc(void * oldBuffer, size_t newSize
+ }
+ 
+ extern C_LINKAGE void *
+-malloc(size_t size)
++__efence__malloc(size_t size)
+ {
+ 	if ( allocationList == 0 )
+ 		initialize();	/* This sets EF_ALIGNMENT */
+@@ -905,7 +907,7 @@ extern C_LINKAGE void *
+ calloc(size_t nelem, size_t elsize)
+ {
+ 	size_t	size = nelem * elsize;
+-	void *	allocation = malloc(size);
++	void *	allocation = __efence__malloc(size);
+ 
+ 	memset(allocation, 0, size);
+ 	return allocation;
+@@ -921,6 +923,10 @@ valloc (size_t size)
+ 	return memalign(bytesPerPage, size);
+ }
+ 
++C_LINKAGE void *malloc(size_t size)
++  __attribute__ ((alias ("__efence__malloc")));
++
++
+ #ifdef __hpux
+ /*
+  * HP-UX 8/9.01 strcat reads a word past source when doing unaligned copies!
+
+Diff finished.  Thu Sep  9 17:48:17 2010
diff --git a/ElectricFence.spec b/ElectricFence.spec
index e66b5fa..f45fdf7 100644
--- a/ElectricFence.spec
+++ b/ElectricFence.spec
@@ -1,7 +1,7 @@
 Summary: A debugger which detects memory allocation violations
 Name: ElectricFence
 Version: 2.2.2
-Release: 27%{?dist}
+Release: 28%{?dist}
 License: GPLv2
 Group: Development/Tools
 URL: http://perens.com/FreeSoftware/ElectricFence/
@@ -16,6 +16,7 @@ Patch4: ElectricFence-2.2.2-madvise.patch
 Patch5: ElectricFence-mmap-size.patch
 Patch6: ElectricFence-2.2.2-banner.patch
 Patch7: ElectricFence-2.2.2-ef.patch
+Patch8: ElectricFence-2.2.2-malloc.patch
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 %description
@@ -39,6 +40,7 @@ violations.
 %patch5 -p1
 %patch6 -p1
 %patch7 -p1
+%patch8 -p1
 
 %build
 make CFLAGS='${RPM_OPT_FLAGS} -DUSE_SEMAPHORE -fpic'
@@ -71,6 +73,12 @@ rm -rf $RPM_BUILD_ROOT
 %{_mandir}/*/*
 
 %changelog
+* Thu Sep  9 2010 root <pmachata at redhat.com> - 2.2.2-28
+- GCC optimizes out write to internalUse in call from
+  allocateMoreSlots to malloc.  Rename malloc to __efence__malloc to
+  pacify the trigger.  Later sneak the malloc symbol in with an alias.
+- Resolves: #631316
+
 * Fri Jul 24 2009 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 2.2.2-27
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild
 


More information about the scm-commits mailing list