On Tue, 5 Oct 2010 13:43:01 +0200 Detlev Zundel <d...@denx.de> wrote:
> Hi Reinhard, > > [...] > > >> Note that this is with GCC 4.2.2. Even GCC 4.0.0 behaves the same, so > >> this is *not* an issue with very recent tool chains. > > > > OK, for directly adressing elements inside a packed struct; > > but the original post said: > > > > "struct xyz { > > int x; > > int y; > > int z[CONST]; > > } __attribute__ ((packed)); > > > > struct xyz *abc; > > u32 * status_reg = (u32 *)&abc->z[0]; > > > > writel(status, status_reg);" > > > > So the "status_reg" pointer is in a completely unrelated (to the packed > > struct) > > "u32 *" and still the access is done like it was packed. If the > > compiler silently drags that attribute along into the "u32 *" > > THAT is really sick! > > I cannot follow why you think this is sick - actually I think this is > clever. GCC "knows" that abc points to a packed struct and it has no > clue on actual values, so it _has to assume_ it is not aligned. So instead of the code breaking in the obvious situation where the unaligned address is assigned to a pointer type that implies alignment, it breaks when sufficient barriers to optimization are added that the compiler can no longer keep track of where the value came from? Seems like the right thing is for GCC to warn about the assignment to a plain "u32 *", and allow a warningless assignment to something like "u32 __attribute__((packed)) *". -Scott _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot