[U-Boot] [PATCH 2/9] Fix strict-aliasing warning in dlmalloc

Andreas Bießmann andreas.devel at googlemail.com
Mon Aug 13 17:25:33 CEST 2012


Dear Simon Glass,

On 06.01.2012 04:54, Simon Glass wrote:
> This fixes the following warnings in dlmalloc seen with my gcc 4.6.
> 
> dlmalloc.c: In function 'malloc_bin_reloc':
> dlmalloc.c:1493: warning: dereferencing pointer 'p' does break strict-aliasing rules
> dlmalloc.c:1493: warning: dereferencing pointer 'p' does break strict-aliasing rules
> dlmalloc.c:1490: note: initialized from here
> dlmalloc.c:1493: note: initialized from here

This is really annoying, but ...

> 
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>  common/dlmalloc.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/common/dlmalloc.c b/common/dlmalloc.c
> index c645d73..0a719b4 100644
> --- a/common/dlmalloc.c
> +++ b/common/dlmalloc.c
> @@ -1487,11 +1487,11 @@ static mbinptr av_[NAV * 2 + 2] = {
>  #ifdef CONFIG_NEEDS_MANUAL_RELOC
>  void malloc_bin_reloc (void)
>  {
> -	unsigned long *p = (unsigned long *)(&av_[2]);
> +	mbinptr *p = &av_[2];
>  	int i;
> -	for (i=2; i<(sizeof(av_)/sizeof(mbinptr)); ++i) {
> -		*p++ += gd->reloc_off;
> -	}
> +
> +	for (i = 2; i < ARRAY_SIZE(av_); ++i)
> +		*p = (mbinptr)((ulong)*p + gd->reloc_off);

your patch breaks avr32 boards at runtime:

---8<---
U-Boot 2012.07-00134-g6073aab (Aug 13 2012 - 17:16:34)

U-Boot code: 00000000 -> 00013588  data: 0001ab70 -> 00050448
VMR table @ 0x107ca4bc
DMA: Using memory from 0x1076b000 to 0x1076f000
Flash: 8 MiB at address 0x00000000
DRAM Configuration:
Bank #0: 10000000 8 MiB

 *** Unhandled exception 24 at PC=0x107b442e [0000542e]
MMU exception at address 0x7af1ade4
   pc: 107b442e    lr: 0001b1c8    sp: 1076aecc   r12: 00000001
  r11: 00000000   r10: 00000079    r9: 107c9de8    r8: 107c9de0
   r7: 00010000    r6: 107ca9ac    r5: 1076af90    r4: 0000007e
   r3: 7af1ade0    r2: 107cb8f0    r1: 00000000    r0: 107cb908
Flags: qvnzc
Mode bits: hrje....g
CPU Mode: Supervisor
--->8---

A working solution is http://patchwork.ozlabs.org/patch/176885/

Would be great to remove this aliasing warning in 2012.10

Best regards

Andreas Bießmann


More information about the U-Boot mailing list