diff mbox

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

Message ID 1325822097-15227-3-git-send-email-sjg@chromium.org
State Superseded, archived
Headers show

Commit Message

Simon Glass Jan. 6, 2012, 3:54 a.m. UTC
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

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/dlmalloc.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Comments

Wolfgang Denk Jan. 6, 2012, 6:48 a.m. UTC | #1
Dear Simon Glass,

In message <1325822097-15227-3-git-send-email-sjg@chromium.org> you wrote:
> This fixes the following warnings in dlmalloc seen with my gcc 4.6.

Which exact version is this?

> 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

Can you please tell me at least one board configuration that throws
this error (preferrably ppc, arm or mips) ?

Also, at least one for the "mpc5xxx: Fix strict-aliasing warnings in
usb_ohci.c" and "ppc4xx: Fix strict-aliasing warnings in usb_ohci.c"
patches?

I wonder why I don't see any such warnings.  Which exact commit ID are
you building?

Thanks.

Best regards,

Wolfgang Denk
Simon Glass Jan. 6, 2012, 8:39 p.m. UTC | #2
Hi Wolfgang,

On Thu, Jan 5, 2012 at 10:48 PM, Wolfgang Denk <wd@denx.de> wrote:
> Dear Simon Glass,
>
> In message <1325822097-15227-3-git-send-email-sjg@chromium.org> you wrote:
>> This fixes the following warnings in dlmalloc seen with my gcc 4.6.
>
> Which exact version is this?
>
>> 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
>
> Can you please tell me at least one board configuration that throws
> this error (preferrably ppc, arm or mips) ?

I can't see one with those architectures. It does happen for others though:

$ (for b in $(cd ~/cosarm/buildall/logs.master.9a42098 && grep -l 1493
*ERR |sed 's/.ERR//'); do grep $b boards.cfg; done ) |awk '{print $2,
$1}'
avr32 atngw100
avr32 atstk1002
avr32 atstk1003
avr32 atstk1004
avr32 atstk1006
mips dbau1000
mips dbau1100
mips dbau1500
mips dbau1550
mips dbau1550_el
avr32 favr-32-ezkit
avr32 grasshopper
mips gth2
avr32 hammerhead
mips incaip
mips incaip_100MHz
mips incaip_133MHz
mips incaip_150MHz
m68k M54451EVB
m68k M54451EVB_stmicro
m68k M54451EVB_stmicro
m68k M54455EVB_a66
m68k M54455EVB
m68k M54455EVB_a66
m68k M54455EVB_i66
m68k M54455EVB_intel
m68k M54455EVB_stm33
m68k M54455EVB_i66
m68k M54455EVB_intel
m68k M54455EVB_stm33
m68k M5475AFE
m68k M5475BFE
m68k M5475CFE
m68k M5475DFE
m68k M5475EFE
m68k M5475FFE
m68k M5475GFE
m68k M5485AFE
m68k M5485BFE
m68k M5485CFE
m68k M5485DFE
m68k M5485EFE
m68k M5485FFE
m68k M5485GFE
m68k M5485HFE
avr32 mimc200
mips qemu_mips
mips vct_platinumavc
mips vct_platinumavc_onenand
mips vct_platinumavc_onenand_small
mips vct_platinumavc_small
mips vct_platinumavc_onenand
mips vct_platinumavc_onenand_small
mips vct_platinumavc_onenand_small
mips vct_platinumavc_small
mips vct_platinum
mips vct_platinumavc
mips vct_platinumavc_onenand
mips vct_platinumavc_onenand_small
mips vct_platinumavc_small
mips vct_platinum_onenand
mips vct_platinum_onenand_small
mips vct_platinum_small
mips vct_platinum_onenand
mips vct_platinum_onenand_small
mips vct_platinum_onenand_small
mips vct_platinum_small
mips vct_premium
mips vct_premium_onenand
mips vct_premium_onenand_small
mips vct_premium_small
mips vct_premium_onenand
mips vct_premium_onenand_small
mips vct_premium_onenand_small
mips vct_premium_small

Using built-in specs.
Target: mips-linux
Configured with: /home/tony/buildall/src/gcc/configure
--target=mips-linux --enable-targets=all
--prefix=/opt/cross/gcc-4.4.4-nolibc/mips-linux/ --enable-languages=c
--with-newlib --without-headers --enable-sjlj-exceptions
--with-system-libunwind --disable-nls --disable-threads
--disable-shared --disable-libmudflap --disable-libssp
--disable-libgomp --disable-decimal-float --enable-checking=release
--with-mpfr=/home/tony/buildall/src/sys
--with-gmp=/home/tony/buildall/src/sys
Thread model: single
gcc version 4.4.4 (GCC)

Using built-in specs.
Target: m68k-linux
Configured with: /home/tony/buildall/src/gcc/configure
--target=m68k-linux --enable-targets=all
--prefix=/opt/cross/gcc-4.4.4-nolibc/m68k-linux/ --enable-languages=c
--with-newlib --without-headers --enable-sjlj-exceptions
--with-system-libunwind --disable-nls --disable-threads
--disable-shared --disable-libmudflap --disable-libssp
--disable-libgomp --disable-decimal-float --enable-checking=release
--with-mpfr=/home/tony/buildall/src/sys
--with-gmp=/home/tony/buildall/src/sys
Thread model: single
gcc version 4.4.4 (GCC)

Using built-in specs.
Target: powerpc-linux
Configured with: /home/tony/buildall/src/gcc/configure
--target=powerpc-linux --enable-targets=all
--prefix=/opt/cross/gcc-4.4.4-nolibc/powerpc-linux/
--enable-languages=c --with-newlib --without-headers
--enable-sjlj-exceptions --with-system-libunwind --disable-nls
--disable-threads --disable-shared --disable-libmudflap
--disable-libssp --disable-libgomp --disable-decimal-float
--enable-checking=release --with-mpfr=/home/tony/buildall/src/sys
--with-gmp=/home/tony/buildall/src/sys
Thread model: single
gcc version 4.4.4 (GCC)

From here:

http://dev.gentoo.org/~vapier/u-boot/

>
> Also, at least one for the "mpc5xxx: Fix strict-aliasing warnings in
> usb_ohci.c" and "ppc4xx: Fix strict-aliasing warnings in usb_ohci.c"
> patches?

powerpc BC3450
powerpc cm5200
powerpc EVAL5200
powerpc galaxy5200
powerpc galaxy5200_LOWBOOT
powerpc galaxy5200_LOWBOOT
powerpc inka4x0
powerpc mcc200_COM12
powerpc mcc200_COM12_highboot
powerpc mcc200_COM12_highboot_SDRAM
powerpc mcc200_COM12_SDRAM
powerpc mcc200_COM12_highboot
powerpc mcc200_COM12_highboot_SDRAM
powerpc mcc200_COM12_highboot_SDRAM
powerpc mcc200_COM12_SDRAM
powerpc mcc200
powerpc mcc200_COM12
powerpc mcc200_COM12_highboot
powerpc mcc200_COM12_highboot_SDRAM
powerpc mcc200_COM12_SDRAM
powerpc mcc200_highboot
powerpc mcc200_highboot_SDRAM
powerpc mcc200_SDRAM
powerpc prs200
powerpc prs200_DDR
powerpc prs200_highboot
powerpc prs200_highboot_DDR
powerpc mcc200_highboot
powerpc mcc200_highboot_SDRAM
powerpc mcc200_highboot_SDRAM
powerpc mcc200_SDRAM
powerpc PM520_DDR
powerpc PM520
powerpc PM520_DDR
powerpc PM520_ROMBOOT
powerpc PM520_ROMBOOT_DDR
powerpc PM520_ROMBOOT_DDR
powerpc PM520_ROMBOOT
powerpc PM520_ROMBOOT_DDR
powerpc prs200_DDR
powerpc prs200
powerpc prs200_DDR
powerpc prs200_highboot
powerpc prs200_highboot_DDR
powerpc prs200_highboot_DDR
powerpc prs200_highboot
powerpc prs200_highboot_DDR
powerpc TB5200_B
powerpc TB5200
powerpc TB5200_B
powerpc Total5200
powerpc Total5200_lowboot
powerpc Total5200_Rev2
powerpc Total5200_Rev2_lowboot
powerpc Total5200_lowboot
powerpc Total5200_Rev2
powerpc Total5200_Rev2_lowboot
powerpc Total5200_Rev2_lowboot
powerpc v38b

and

powerpc acadia
powerpc acadia_nand
powerpc acadia_nand
powerpc bamboo
powerpc bamboo_nand
powerpc bamboo_nand
powerpc korat
powerpc korat_perm
powerpc korat_perm
powerpc pcs440ep


>
> I wonder why I don't see any such warnings.  Which exact commit ID are
> you building?

I was building with this :

commit 9a420986cccc9bd2c37affd931d627b3c3e72952
Author: Rob Herring <rob.herring@calxeda.com>
Date:   Thu Dec 15 11:15:50 2011 +0000

    ARM: highbank: enable networking and pxe

(so before all the common.h problems).

Regards,
Simon

>
> Thanks.
>
> Best regards,
>
> Wolfgang Denk
>
> --
> 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@denx.de
> Make it right before you make it faster.
Wolfgang Denk Jan. 6, 2012, 11:37 p.m. UTC | #3
Dear Simon,

In message <CAPnjgZ1OxJJsSEodSM-fqTN791mW-UezqWjFLQBAS-4RbFHJkQ@mail.gmail.com> you wrote:
> 
> > Can you please tell me at least one board configuration that throws
> > this error (preferrably ppc, arm or mips) ?
> 
> I can't see one with those architectures. It does happen for others though:
...

Strange.  Both MIPS and PPC build without a single warning for me.

I cannot test avr32 or m68k here.

> > Also, at least one for the "mpc5xxx: Fix strict-aliasing warnings in
> > usb_ohci.c" and "ppc4xx: Fix strict-aliasing warnings in usb_ohci.c"
> > patches?

None here.

I am tempted to blame your tool chain for the problems.

Is anybody else seing these warnings? With which tool chain versions?

Best regards,

Wolfgang Denk
Simon Glass Jan. 8, 2012, 12:57 a.m. UTC | #4
Hi Wolfgang,

On Fri, Jan 6, 2012 at 3:37 PM, Wolfgang Denk <wd@denx.de> wrote:
> Dear Simon,
>
> In message <CAPnjgZ1OxJJsSEodSM-fqTN791mW-UezqWjFLQBAS-4RbFHJkQ@mail.gmail.com> you wrote:
>>
>> > Can you please tell me at least one board configuration that throws
>> > this error (preferrably ppc, arm or mips) ?
>>
>> I can't see one with those architectures. It does happen for others though:
> ...
>
> Strange.  Both MIPS and PPC build without a single warning for me.
>
> I cannot test avr32 or m68k here.
>
>> > Also, at least one for the "mpc5xxx: Fix strict-aliasing warnings in
>> > usb_ohci.c" and "ppc4xx: Fix strict-aliasing warnings in usb_ohci.c"
>> > patches?
>
> None here.
>
> I am tempted to blame your tool chain for the problems.

Could be - well you can download it for yourself if you want to try it.

http://dev.gentoo.org/~vapier/u-boot/

The warnings seems mostly reasonable (i.e. correct) to me, except for
the new USB alias one AFTER Marek's fix. That one I don't quite
understand.

>
> Is anybody else seing these warnings? With which tool chain versions?

Will wait to hear from people.

Regards,
Simon

>
> Best regards,
>
> Wolfgang Denk
>
> --
> 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@denx.de
> If you fail to plan, plan to fail.
Mike Frysinger Jan. 8, 2012, 9:27 a.m. UTC | #5
On Friday 06 January 2012 15:39:08 Simon Glass wrote:
> On Thu, Jan 5, 2012 at 10:48 PM, Wolfgang Denk wrote:
> > Simon Glass wrote:
> >> This fixes the following warnings in dlmalloc seen with my gcc 4.6.
> > 
> > Which exact version is this?
> > 
> >> 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
> > 
> > Can you please tell me at least one board configuration that throws
> > this error (preferrably ppc, arm or mips) ?
> 
> I can't see one with those architectures. It does happen for others though:

yes, there have been reports and patches posted in the past iirc.  first by 
Kumar i think.
-mike
Andreas Bießmann Aug. 13, 2012, 3:25 p.m. UTC | #6
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@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
Andreas Bießmann Sept. 4, 2012, 9:25 p.m. UTC | #7
Dear Simon Glas,

On 13.08.2012 17:25, Andreas Bießmann wrote:
> 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@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);
------------------^

Ouch ... isn't there something missing? Who increments the pointer? ;)

> your patch breaks avr32 boards at runtime:

Will send a new version which supersedes this one and 
http://patchwork.ozlabs.org/patch/176885/

Best regards

Andreas Bießmann
diff mbox

Patch

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);
 }
 #endif