public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
From: Ian Wienand <ianw@gelato.unsw.edu.au>
To: linux-ia64@vger.kernel.org
Subject: Unaligned access question
Date: Thu, 25 Sep 2003 01:34:11 +0000	[thread overview]
Message-ID: <marc-linux-ia64-106445366428887@msgid-missing> (raw)

Hi,

This isn't directly related to kernel development, but I am a bit
stumped as to why my test program below causes an unaligned access
when 'i' is 7 (that is, when it tries to access across a 64 bit
boundary of 'array').  It's counter intuitive to me, I would have
expected it either fault on all loads (for every value of 'i') or to
have not faulted at all.

(yes, this is abstracted from some code that is chopping up data
coming over the network, which seems to be a common cause of alignment
problems).

Thanks for any suggestions,

-i
ianw@gelato.unsw.edu.au
http://www.gelato.unsw.edu.au

--- little test program ---

#include <stdio.h>
 
typedef struct a_struct_t {
        unsigned char a[2];
} a_struct;
 
void print(const a_struct st) {
        printf("%p -> %c | %p -> %c\n", &st.a[0], st.a[0], &st.a[1], st.a[1]);
}
 
int main(void)
{                   
        unsigned char *array = "1234567812345678";
                                
        int i;
 
        for ( i = 1 ; i < 10 ; i+=2 ) {
                printf("array[%d] %p\n", i, &array[i]);
                print( *((a_struct*)&array[i]) );
        }
        return 0;
}


--- sample output ---

array[1] 0x4000000000000a79
0x60000fffffffbcf0 -> 2 | 0x60000fffffffbcf1 -> 3
array[3] 0x4000000000000a7b
0x60000fffffffbcf0 -> 4 | 0x60000fffffffbcf1 -> 5
array[5] 0x4000000000000a7d
0x60000fffffffbcf0 -> 6 | 0x60000fffffffbcf1 -> 7
array[7] 0x4000000000000a7f
align(20189): unaligned access to 0x4000000000000a7f, ip=0x4000000000000770
0x60000fffffffbcf0 -> 8 | 0x60000fffffffbcf1 -> 1
array[9] 0x4000000000000a81
0x60000fffffffbcf0 -> 2 | 0x60000fffffffbcf1 -> 3


             reply	other threads:[~2003-09-25  1:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-25  1:34 Ian Wienand [this message]
2003-09-25  2:04 ` Unaligned access question Peter Chubb
2003-09-25  2:23 ` Martin Pool
2003-09-25  8:32 ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=marc-linux-ia64-106445366428887@msgid-missing \
    --to=ianw@gelato.unsw.edu.au \
    --cc=linux-ia64@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox