[U-Boot-Users] [UPDATED][PATCH v2] Fix compile warnings in dlmalloc
Kumar Gala
galak at kernel.crashing.org
Wed Jul 30 15:01:15 CEST 2008
The origional code was using on odd reference to get to the first
real element in av_[]. The first two elements of the array are
not used for actual bins, but for house keeping. If we are more
explicit about how use the first few elements we can get rid of the
warnings:
dlmalloc.c: In function 'malloc_extend_top':
dlmalloc.c:1971: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:1999: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2029: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2031: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2042: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c: In function 'malloc':
dlmalloc.c:2245: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2245: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2253: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2258: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2263: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2318: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2327: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2329: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2344: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2356: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2360: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2362: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2363: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c: In function 'free':
dlmalloc.c:2431: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2444: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2483: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2483: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c: In function 'realloc':
dlmalloc.c:2594: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2599: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2604: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2605: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2637: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2646: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2647: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c: In function 'calloc':
dlmalloc.c:2896: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2897: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c: In function 'malloc_trim':
dlmalloc.c:2987: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:2997: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:3008: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:3012: warning: dereferencing type-punned pointer will break strict-aliasing rules
dlmalloc.c:3021: warning: dereferencing type-punned pointer will break strict-aliasing rules
The logic of how this code came to be is:
bin_at(0) = (char*)&(av_[2]) - 2*SIZE_SZ
SIZE_SZ is the size of pointer, and av_ is arry of pointers so:
bin_at(0) = &(av_[0])
Going from there to bin_at(0)->fd or bin_at(0)->size should be straight forward.
Signed-off-by: Kumar Gala <galak at kernel.crashing.org>
---
Updated against lastest head, added a bit more commit info about the logic
of the change.
common/dlmalloc.c | 21 +++++++++++----------
1 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index c51351e..4a18562 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -1457,7 +1457,7 @@ typedef struct malloc_chunk* mbinptr;
indexing, maintain locality, and avoid some initialization tests.
*/
-#define top (bin_at(0)->fd) /* The topmost chunk */
+#define top (av_[2]) /* The topmost chunk */
#define last_remainder (bin_at(1)) /* remainder from last split */
@@ -1552,13 +1552,14 @@ void malloc_bin_reloc (void)
#define BINBLOCKWIDTH 4 /* bins per block */
-#define binblocks (bin_at(0)->size) /* bitvector of nonempty blocks */
+#define binblocks_r ((INTERNAL_SIZE_T)av_[1]) /* bitvector of nonempty blocks */
+#define binblocks_w (av_[1])
/* bin<->block macros */
#define idx2binblock(ix) ((unsigned)1 << (ix / BINBLOCKWIDTH))
-#define mark_binblock(ii) (binblocks |= idx2binblock(ii))
-#define clear_binblock(ii) (binblocks &= ~(idx2binblock(ii)))
+#define mark_binblock(ii) (binblocks_w = (mbinptr)(binblocks_r | idx2binblock(ii)))
+#define clear_binblock(ii) (binblocks_w = (mbinptr)(binblocks_r & ~(idx2binblock(ii))))
@@ -2250,17 +2251,17 @@ Void_t* mALLOc(bytes) size_t bytes;
search for best fitting chunk by scanning bins in blockwidth units.
*/
- if ( (block = idx2binblock(idx)) <= binblocks)
+ if ( (block = idx2binblock(idx)) <= binblocks_r)
{
/* Get to the first marked block */
- if ( (block & binblocks) == 0)
+ if ( (block & binblocks_r) == 0)
{
/* force to an even block boundary */
idx = (idx & ~(BINBLOCKWIDTH - 1)) + BINBLOCKWIDTH;
block <<= 1;
- while ((block & binblocks) == 0)
+ while ((block & binblocks_r) == 0)
{
idx += BINBLOCKWIDTH;
block <<= 1;
@@ -2315,7 +2316,7 @@ Void_t* mALLOc(bytes) size_t bytes;
{
if ((startidx & (BINBLOCKWIDTH - 1)) == 0)
{
- binblocks &= ~block;
+ av_[1] = (mbinptr)(binblocks_r & ~block);
break;
}
--startidx;
@@ -2324,9 +2325,9 @@ Void_t* mALLOc(bytes) size_t bytes;
/* Get to the next possibly nonempty block */
- if ( (block <<= 1) <= binblocks && (block != 0) )
+ if ( (block <<= 1) <= binblocks_r && (block != 0) )
{
- while ((block & binblocks) == 0)
+ while ((block & binblocks_r) == 0)
{
idx += BINBLOCKWIDTH;
block <<= 1;
--
1.5.5.1
More information about the U-Boot
mailing list