[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-commit] [2400] GCC 4.5+ implies malloc() and free() have no si
From: |
Joerg Wunsch |
Subject: |
[avr-libc-commit] [2400] GCC 4.5+ implies malloc() and free() have no side-effects to global |
Date: |
Mon, 13 May 2013 15:21:59 +0000 |
Revision: 2400
http://svn.sv.gnu.org/viewvc/?view=rev&root=avr-libc&revision=2400
Author: joerg_wunsch
Date: 2013-05-13 15:21:58 +0000 (Mon, 13 May 2013)
Log Message:
-----------
GCC 4.5+ implies malloc() and free() have no side-effects to global
variables. Place a memory barrier before any evaluations of __flp or
__brkval to ensure the compiler actually reads them from the
respective memory locations.
Replace private library definitions by "stdlib_private.h".
Modified Paths:
--------------
trunk/avr-libc/ChangeLog
trunk/avr-libc/tests/simulate/stdlib/malloc-7.c
trunk/avr-libc/tests/simulate/stdlib/realloc-2.c
Modified: trunk/avr-libc/ChangeLog
===================================================================
--- trunk/avr-libc/ChangeLog 2013-05-13 15:12:10 UTC (rev 2399)
+++ trunk/avr-libc/ChangeLog 2013-05-13 15:21:58 UTC (rev 2400)
@@ -5,6 +5,9 @@
memory barrier before any evaluations of __flp or __brkval to
ensure the compiler actually reads them from the respective memory
locations.
+ * tests/simulate/stdlib/malloc-7.c: (Dito.) Also replace private
+ library definitions by "stdlib_private.h"
+ * tests/simulate/stdlib/realloc-2.c: (Dito.)
2013-05-08 Joerg Wunsch <address@hidden>
Modified: trunk/avr-libc/tests/simulate/stdlib/malloc-7.c
===================================================================
--- trunk/avr-libc/tests/simulate/stdlib/malloc-7.c 2013-05-13 15:12:10 UTC
(rev 2399)
+++ trunk/avr-libc/tests/simulate/stdlib/malloc-7.c 2013-05-13 15:21:58 UTC
(rev 2400)
@@ -43,17 +43,10 @@
#include <stdint.h>
#include <stdlib.h>
+#include <avr/cpufunc.h>
-struct __freelist {
- size_t sz;
- struct __freelist *nx;
-};
+#include "../../libc/stdlib/stdlib_private.h"
-extern char *__brkval; /* first location not yet allocated */
-extern struct __freelist *__flp; /* freelist pointer (head of freelist) */
-extern char *__malloc_heap_start;
-extern char *__malloc_heap_end;
-
int main(void)
{
void *ptrs[6];
@@ -67,11 +60,13 @@
}
free(ptrs[5]);
+ _MemoryBarrier();
/* Freelist must be still empty, and __brkval reduced. */
if (__flp != NULL) return __LINE__;
if ((char *)(ptrs[5]) - 2 != __brkval) return __LINE__;
free(ptrs[4]);
+ _MemoryBarrier();
/* Still no entry, and __brkval further down. */
if (__flp != NULL) return __LINE__;
if ((char *)(ptrs[4]) - 2 != __brkval) return __LINE__;
@@ -79,17 +74,20 @@
struct __freelist *ofp = __flp;
free(ptrs[1]);
+ _MemoryBarrier();
/* One entry added. */
if ((char *)(ptrs[1]) - 2 != (void *)__flp) return __LINE__;
if (__flp->sz != 10) return __LINE__;
if (__flp->nx != (void *)ofp) return __LINE__;
free(ptrs[3]);
+ _MemoryBarrier();
/* __brkval lowered again. */
if (__flp->nx != NULL) return __LINE__;
if ((char *)(ptrs[3]) - 2 != __brkval) return __LINE__;
free(ptrs[2]);
+ _MemoryBarrier();
/* ...and again. */
if (__flp->nx != NULL) return __LINE__;
if ((char *)(ptrs[1]) - 2 != __brkval) return __LINE__;
Modified: trunk/avr-libc/tests/simulate/stdlib/realloc-2.c
===================================================================
--- trunk/avr-libc/tests/simulate/stdlib/realloc-2.c 2013-05-13 15:12:10 UTC
(rev 2399)
+++ trunk/avr-libc/tests/simulate/stdlib/realloc-2.c 2013-05-13 15:21:58 UTC
(rev 2400)
@@ -44,17 +44,10 @@
#include <stdint.h>
#include <stdlib.h>
+#include <avr/cpufunc.h>
-struct __freelist {
- size_t sz;
- struct __freelist *nx;
-};
+#include "../../libc/stdlib/stdlib_private.h"
-extern char *__brkval; /* first location not yet allocated */
-extern struct __freelist *__flp; /* freelist pointer (head of freelist) */
-extern char *__malloc_heap_start;
-extern char *__malloc_heap_end;
-
#if defined(__AVR_ATmega128__)
static const int sizes[8] =
{
@@ -84,6 +77,7 @@
if (p == NULL) return __LINE__;
ptrs[i] = p;
}
+ _MemoryBarrier();
/* second test: the amount of memory allocated to the heap must
match the expected TARGETVAL */
if (__brkval - __malloc_heap_start != TARGETVAL) return __LINE__;
@@ -95,6 +89,7 @@
free(ptrs[i]);
}
+ _MemoryBarrier();
/* after freeing everything, the freelist must be empty */
if (__flp != NULL) return __LINE__;
if (__brkval != __malloc_heap_start) return __LINE__;
@@ -110,6 +105,7 @@
if (q != p) return __LINE__;
}
+ _MemoryBarrier();
/* Verify the allocation length did not increase. */
if (__brkval > obrk) return __LINE__;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-libc-commit] [2400] GCC 4.5+ implies malloc() and free() have no side-effects to global,
Joerg Wunsch <=