From mboxrd@z Thu Jan 1 00:00:00 1970 From: Detlev Zundel Date: Tue, 05 Oct 2010 13:43:01 +0200 Subject: [U-Boot] packed attribute problem In-Reply-To: <4CA9CC04.5020800@emk-elektronik.de> (Reinhard Meyer's message of "Mon, 04 Oct 2010 14:43:48 +0200") References: <4CA9A095.9000900@st.com> <20101004101714.A19931539A0@gemini.denx.de> <4CA9ACAA.2020001@st.com> <20101004104443.09AE41539A0@gemini.denx.de> <4CA9B2DA.6030407@emk-elektronik.de> <4CA9B3EF.7000704@st.com> <4CA9BE94.6000401@emk-elektronik.de> <20101004122900.A090B1539A0@gemini.denx.de> <4CA9CC04.5020800@emk-elektronik.de> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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. status_reg is initialized as a pointer to a member of this unaligned pointer and is thus also considered unaligned. Seems perfectly fine to me. Cheers Detlev -- BUGS: It is not yet possible to change operating system by writing to /proc/sys/kernel/ostype. -- Linux sysctl(2) man page -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de