We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi
is there a way to force constant strings to be aligned on 4 byte boundary?
For example: createTask("Taskname");
I tried the linker option "OVERALIGN", but it just generates a warning.
Cheers
Hi Bastian,
Do you just need to use __attribute__((aligned(4))) when you declare the string?
https://developer.arm.com/docs/dui0774/j/compiler-specific-function-variable-and-type-attributes/__attribute__aligned-type-attribute
(better documented in later versions)https://developer.arm.com/docs/101754/0614/armclang-reference/compiler-specific-function-variable-and-type-attributes/__attribute__aligned-variable-attributeRegardsRonan
But does this work with constant string like in the example? I tried, but it did not work in the first attempt:
create("name" __attribute__((aligned(4))) );
Edit:I tried: __attribute__((align(4))) "default" and "default" __attribute__((align(4)))
None works.
Hi BastianDeclaring like this worked for me.
char __attribute__((aligned(4))) string1[] = "abcde";
Could you share a larger snippet of your code?
Yes this works for me as well. This is actually my workaround:
/* Workaround */ void func() { char name[12]; /* automatic aligned to 4 bytes as it is on stack*/ strcpy(name, "process"); create(name); } void func2() { create("process"); /* constant string might be placed on any boundary */ }
func2() would show the original code.
create() (assembly function) would read the name 32bit wise. This works fine on architecture > Armv6-M, but not for Armv6-M.
The workaround is ok and I can live with it, but it is a pity there is no way to force alignment.