Unaligned pointer as function parameter
Hi,
i am currently porting software to the arm architecture using the gnu arm embedded toolchain. I have some problems with unaligned pointers as function parameters. Unaligned access itself is working as intended but when a pointer to an unaligned structure is passed to a function i get an abort exception.
Consider the following code:
typedef struct secondstruct
{
int dummy1;
int dummy2;
int dummy3;
int dummy4;
}secondstruct;
typedef struct __attribute__ ((packed)) firststruct
{
char a;
secondstruct b;
}firststruct;
int global;
void callingFunction
{
firststruct firstStruct;
secondstruct secondStruct;
secondStruct.
secondStruct.
secondStruct.
secondStruct.
firstStruct.b = secondStruct; <- unaligned acces but still working since compiler is aware of it
myFunction(
}
void myFunction(
{
secondstruct secondStruct;
secondStruct = *testPointer; <- Exception since ldm / stm on unaligned pointer
global = secondStruct.dummy1 + secondStruct.
}
In myFunction the unaligned pointer is used to fill the local variable. The compiler does not know that the pointer is unaligned and tries to fill the local variable with ldm and stm instructions. Since the pointer is unaligned these instructions are not allowed and result in an abort expcetion.
Is this a bug in the compiler or do i have to be aware of every unalinged pointer as function parameter and handle it manually?
Question information
- Language:
- English Edit question
- Status:
- Answered
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask adaub for more information if necessary.