From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 9440 invoked from network); 5 Dec 1998 16:41:03 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 5 Dec 1998 16:41:03 -0000 Received: from hazel.buici.com (root@hazel.buici.com [207.108.197.197]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id LAA05571 for ; Sat, 5 Dec 1998 11:36:35 -0500 Received: by buici.com via sendmail from stdin id (Debian Smail3.2.0.102) for axp-list@redhat.com; Sat, 5 Dec 1998 08:37:17 -0800 (PST) Date: Sat, 5 Dec 1998 08:37:17 -0800 From: Oscar Levi To: axp-list@redhat.com Subject: Re: How do I find/fix unaligned accesses? Message-ID: <19981205083716.A1438@hazel.buici.com> References: <36685594.38C3976A@adam.cheshire.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.94.17i In-Reply-To: ; from Tom Linden on Fri, Dec 04, 1998 at 06:29:24PM -0800 On Fri, Dec 04, 1998 at 06:29:24PM -0800, Tom Linden wrote: > This is generally the right approach, but having done this many times > there is a bit more to do. Once you have breakpointed, you need to > determine which variable is offending, and this generally means examing > the assembler statements with gdb and relating it to the source. Once > identified you need to find the declaration of the variable whether > static or automatic, and by looking at the declaration trying to figure > out how it got allocated on the inappropriate boundary. If it is this > simple then padding by dummy allocations of the appropriate size will fix > it. If however, this is the result of aliasing, this may require more > difficult source code changes. use of 'nm' helps a lot. good luck. AFAIK, the primary source of these aligned accesses are pointer tricks. Writing structures and using malloc should not cause unaligned acceses. Instead, these tend occur when authors cast pointers of one type to another. For example, allocating untyped memory and coercing the pointer into pointer pointer. void* pv; pv = malloc (CB_DATA); char** ppch = (char**)((char*) pv + 1); *ppch = "Hello"; Whoops! Please correct me if I have gone astray. I don't believe it is possible to generate unaligned accesses without performing pointer arithmetic with casted pointers. Why is this interesting? It can you help find the source of problems when you know where the culprit hides. Cheers.