[U-Boot] [PATCH] dlmalloc: remove manual reloc alias warning

Wolfgang Denk wd at denx.de
Sat Sep 1 12:10:31 CEST 2012


Dear =?UTF-8?q?Andreas=20Bie=C3=9Fmann?=,

In message <1344848523-20359-1-git-send-email-andreas.devel at googlemail.com> you wrote:
> 
> This patch fixes following warning:
> ---8<---
> 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
...
> +typedef unsigned long __attribute__((__may_alias__)) ulong_aliased;
>  void malloc_bin_reloc (void)
>  {
> -	unsigned long *p = (unsigned long *)(&av_[2]);
> +	ulong_aliased *p = (ulong_aliased *)(&av_[2]);

I dislike this typedef, especially as it's used only a single time.
But even so - why cannot we avoid the __may_alias__ thing alltogether?

You wrote in http://article.gmane.org/gmane.comp.boot-loaders.u-boot/137770
that Simon's patch breaks avr32 boards at runtime.

The implementation is indeed broken.  I wonder if it ever worked:

	mbinptr *p = &av_[2];
	int i;

	for (i = 2; i < ARRAY_SIZE(av_); ++i)
		*p = (mbinptr)((ulong)*p + gd->reloc_off);

i. e. this has the offset 2 added twice, so it is missing the first
two real entries, env writing beyond the end of the array.

Can you please test this code instead:

	mbinptr *p = &av_;
	int i;

	for (i = 2; i < ARRAY_SIZE(av_); ++i)
		*p = (mbinptr)((ulong)*p + gd->reloc_off);


?

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 at denx.de
"Don't try to outweird me, three-eyes. I get stranger things than you
free with my breakfast cereal."
           - Zaphod Beeblebrox in  "Hitchhiker's Guide to the Galaxy"


More information about the U-Boot mailing list