w*s 发帖数: 7227 | 1 Q:
Alignment issue in Arm is like this, correct me if i'm wrong,
if i have
char a[40];
int *b = a;
later on b could cause crash
From web,
For example, on ARM-based systems you cannot address a 32-bit word that
is not aligned to a 4-byte boundary. Doing so will result in an access
violation exception. On x86 you can access such non-aligned data, though the
performance suffers a little since two words have to fetched from memory
instead of just one.
So how to fix this easier, any compile options ? |
G*****h 发帖数: 33134 | 2 compiler should already handle it.
and *(int *)(&a[0]) should be fine
*(int *)(&a[1]) will crash for sure.
that
the
【在 w*s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Q: : Alignment issue in Arm is like this, correct me if i'm wrong, : : if i have : char a[40]; : int *b = a; : later on b could cause crash : : From web, : For example, on ARM-based systems you cannot address a 32-bit word that
|
w*s 发帖数: 7227 | 3 well, we're porting code from CE to linux,
so we do have the
*(int *)(&a[1])
in CE which works fine, guess CE compiler is better.
any quick solution for us ?
【在 G*****h 的大作中提到】![](/moin_static193/solenoid/img/up.png) : compiler should already handle it. : and *(int *)(&a[0]) should be fine : *(int *)(&a[1]) will crash for sure. : : that : the
|
G*****h 发帖数: 33134 | 4 easy
rewrite the code wherever crashes.
though ARM usually has config register that you can enable byte boundary
access
【在 w*s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : well, we're porting code from CE to linux, : so we do have the : *(int *)(&a[1]) : in CE which works fine, guess CE compiler is better. : any quick solution for us ?
|
w*s 发帖数: 7227 | 5 rewrite code will take time. i'm looking for some compiler options.
【在 G*****h 的大作中提到】![](/moin_static193/solenoid/img/up.png) : easy : rewrite the code wherever crashes. : though ARM usually has config register that you can enable byte boundary : access
|
G*****h 发帖数: 33134 | 6 there is CPU option
Compiler cannot stop you using *(int *)(&a[1])
【在 w*s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : rewrite code will take time. i'm looking for some compiler options.
|
w*s 发帖数: 7227 | 7 curious how winCE made it work, still the same ARM cpu ...
【在 G*****h 的大作中提到】![](/moin_static193/solenoid/img/up.png) : there is CPU option : Compiler cannot stop you using *(int *)(&a[1])
|
w*s 发帖数: 7227 | 8 sorry more questions on byte boundary access,
http://www.atmel.com/Images/doc6438.pdf
9.4.4 Memory Access
The ARM9EJ-S core supports byte (8-bit), half-word (16-bit) and word (32-bit
) access. Words
must be aligned to four-byte boundaries, half-words must be aligned to two-
byte boundaries and
bytes can be placed on any byte boundary.
so for the case of (int *)(&array[1]),
it's still treated as int, which must be aligned to four-byte boundaries.
does this conflict to what you are saying on "ARM usually has config
register that you can enable byte boundary access" ?
【在 G*****h 的大作中提到】![](/moin_static193/solenoid/img/up.png) : easy : rewrite the code wherever crashes. : though ARM usually has config register that you can enable byte boundary : access
|
h****d 发帖数: 1305 | 9 is it the limitation of gcc?
that
the
【在 w*s 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Q: : Alignment issue in Arm is like this, correct me if i'm wrong, : : if i have : char a[40]; : int *b = a; : later on b could cause crash : : From web, : For example, on ARM-based systems you cannot address a 32-bit word that
|