[U-Boot-Users] [PATCH] 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.
Signed-off-by: Kumar Gala galak@kernel.crashing.org --- common/Makefile | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/common/Makefile b/common/Makefile index b425795..5f4959a 100644 --- a/common/Makefile +++ b/common/Makefile @@ -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

In message Pine.LNX.4.64.0806042337200.650@blarg.am.freescale.net 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
...
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).
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

On Jul 5, 2008, at 5:32 PM, Wolfgang Denk wrote:
In message Pine.LNX.4.64.0806042337200.650@blarg.am.freescale.net 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
...
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.
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).
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
participants (2)
-
Kumar Gala
-
Wolfgang Denk