Squash warnings from pointer aliasing in dlmalloc
PATCH 1/1 Squash warnings from pointer aliasing in dlmalloc
When we building with gcc-4.3.x on a ppc host we get the following 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
This is due to pointer aliasing that the dlmalloc code does and depends on. Instead of trying trying to work around the warnings, we use the per file CFLAGs to disable the warnings via -fno-strict-aliasing.
--- common/Makefile | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
common/Makefile +1 -0
@@ -104,6 +104,7 @@ COBJS-y += console.o COBJS-y += cyclon2.o COBJS-y += stratixII.o COBJS-y += devices.o +CFLAGS_dlmalloc.o += -fno-strict-aliasing COBJS-y += dlmalloc.o COBJS-y += docecc.o COBJS-y += environment.o
Signature · 1 line
1.5.5.1
PATCH 1/1 Squash warnings from pointer aliasing in dlmalloc
Quoted 5 lines · In message <[email protected]> you wrote:
When we building with gcc-4.3.x on a ppc host we get the following 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
...
Quoted 1 line
This is due to pointer aliasing that the dlmalloc code does and depends on.
Can you please explain why the dlmalloc code depends on this?
In my experience so far it has always been possible to avoid such warnings by trivial changes to the code (the tricky part was usually to understand what the exact problem was and what changes were necessary).
Quoted 2 lines
Instead of trying trying to work around the warnings, we use the per file CFLAGs to disable the warnings via -fno-strict-aliasing.
I tend to reject this patch. I would much rather have the problem fixed in the sources. Hushing up compiler warnings has never been a good idea.
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Our business is run on trust. We trust you will pay in advance.
PATCH 1/1 Squash warnings from pointer aliasing in dlmalloc
Quoted 10 lines · Wolfgang Denk
In message <[email protected]>
Quoted 8 lines · you
When we building with gcc-4.3.x on a ppc host we get the following 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
Quoted 5 lines
...
Quoted 2 lines
This is due to pointer aliasing that the dlmalloc code does and depends on.
Can you please explain why the dlmalloc code depends on this?
That's what Scott said when I asked about this on the list.
Quoted 5 lines
In my experience so far it has always been possible to avoid such warnings by trivial changes to the code (the tricky part was usually to understand what the exact problem was and what changes were necessary).
Quoted 7 lines
Quoted 3 lines
Instead of trying trying to work around the warnings, we use the per file
CFLAGs to disable the warnings via -fno-strict-aliasing.I tend to reject this patch. I would much rather have the problem fixed in the sources. Hushing up compiler warnings has never been a good idea.
I'm all for trying to fix the code to git rid of the warnings, however nothing I tried was able to accomplish that.
The root of the warnings is the bin_at() macro:
#define bin_at(i) ((mbinptr)((char*)&(av_[2*(i) + 2]) - 2*SIZE_SZ)) #define next_bin(b) ((mbinptr)((char*)(b) + 2 * sizeof(mbinptr))) #define prev_bin(b) ((mbinptr)((char*)(b) - 2 * sizeof(mbinptr)))
- k