Discussion:
arm-eabi toolchain memcpy using hard float causing unaligned access
Yupeng Chang
2017-11-10 08:04:55 UTC
Permalink
Hi Linaro Team,
I'm currently using toolchain
gcc-linaro-7.1.1-2017.08-x86_64_arm-eabi.tar.xz
<https://releases.linaro.org/components/toolchain/binaries/latest/arm-eabi/gcc-linaro-7.1.1-2017.08-x86_64_arm-eabi.tar.xz>
to
develop my bera-metal programs.
My compile option is "-marm -march=armv7-a -mtune=cortex-a9 -mlittle-endian
-mfloat-abi=hard -mfpu=neon"

I found an issue, when I use memcpy, and if the DEST or SOURCE address is
not 4 bytes aligned, the system hangs.
It seems that this toolchain doesn't support using hard float and NEON ?

My question is does this toolchain support hard float and NEON in the
newlib C library?
If I want to use hard float and NEON, how can I do that?

Your reply is more appreciated!!
Yupeng Chang
2017-11-10 08:56:51 UTC
Permalink
The test code for this issue is as below:
int main(int argc, char *argv[])
{
uint8_t abc[40] = {0};
uint8_t def[40] = {1};
for (uint32_t i = 0; i < sizeof(abc); ++ i) {
printf("Copying %u bytes, Dest Address: %p, Source Address: %p\n",
sizeof(def) - i, &abc[i], &def[i]);
memcpy(&abc[i], &def[i], sizeof(def) - i);
}
}

If &abc[i] or &def[i] is not 4 bytes aligned, the whole system hangs.
Post by Yupeng Chang
Hi Linaro Team,
I'm currently using toolchain
gcc-linaro-7.1.1-2017.08-x86_64_arm-eabi.tar.xz
<https://releases.linaro.org/components/toolchain/binaries/latest/arm-eabi/gcc-linaro-7.1.1-2017.08-x86_64_arm-eabi.tar.xz> to
develop my bera-metal programs.
My compile option is "-marm -march=armv7-a -mtune=cortex-a9
-mlittle-endian -mfloat-abi=hard -mfpu=neon"
I found an issue, when I use memcpy, and if the DEST or SOURCE address is
not 4 bytes aligned, the system hangs.
It seems that this toolchain doesn't support using hard float and NEON ?
My question is does this toolchain support hard float and NEON in the
newlib C library?
If I want to use hard float and NEON, how can I do that?
Your reply is more appreciated!!
Maxim Kuvyrkov
2017-11-15 13:04:29 UTC
Permalink
Post by Yupeng Chang
Hi Linaro Team,
I'm currently using toolchain
gcc-linaro-7.1.1-2017.08-x86_64_arm-eabi.tar.xz
<https://releases.linaro.org/components/toolchain/binaries/latest/arm-eabi/gcc-linaro-7.1.1-2017.08-x86_64_arm-eabi.tar.xz>
to
develop my bera-metal programs.
My compile option is "-marm -march=armv7-a -mtune=cortex-a9 -mlittle-endian
-mfloat-abi=hard -mfpu=neon"
Hi Yupeng,

Linaro's arm-eabi toolchain provides libraries only for -mfloat-abi=softfp. I'm surprised your baremetal application compiled with -mfloat-abi=hard linked against provided newlib. Can there be another library installed that the tools picked up?
Post by Yupeng Chang
I found an issue, when I use memcpy, and if the DEST or SOURCE address is
not 4 bytes aligned, the system hangs.
It seems that this toolchain doesn't support using hard float and NEON ?
My question is does this toolchain support hard float and NEON in the
newlib C library?
If I want to use hard float and NEON, how can I do that?
Your reply is more appreciated!!
--
Maxim Kuvyrkov
www.linaro.org
Yupeng Chang
2017-11-16 02:39:54 UTC
Permalink
Hi Maxim,
Linaro's arm-eabi toolchain is compiled with option --enable-multilib
In the libc folder, you can find all other different libraries.

I have found the reason causing my problem.
Newlib implementation of memcpy-armv7a.S uses NEON and it requires
"unaligned access" is enabled by the CPU.
Which means, if you compile newlib with default GCC cflags, this code will
be used, and LDR STR instruction may access unaligned address.
My system has disabled CPU unaligned access by setting SCTRL.A to 1, this
setting will enable unaligned address checking, once unaligned address is
accessed by LDR STR instruction, CPU enters DATA ABORT mode.

I have re-compiled this toolchain according to my requirements by adding
-mno-unalinged-access to CFLAGS of newlib.
This option makes newlib use C version of memcpy, which is a little slower
than the NEON version, but it generates code without any unaligned access.
Post by Yupeng Chang
Post by Yupeng Chang
Hi Linaro Team,
I'm currently using toolchain
gcc-linaro-7.1.1-2017.08-x86_64_arm-eabi.tar.xz
<
https://releases.linaro.org/components/toolchain/binaries/latest/arm-eabi/gcc-linaro-7.1.1-2017.08-x86_64_arm-eabi.tar.xz
Post by Yupeng Chang
to
develop my bera-metal programs.
My compile option is "-marm -march=armv7-a -mtune=cortex-a9
-mlittle-endian
Post by Yupeng Chang
-mfloat-abi=hard -mfpu=neon"
Hi Yupeng,
Linaro's arm-eabi toolchain provides libraries only for
-mfloat-abi=softfp. I'm surprised your baremetal application compiled with
-mfloat-abi=hard linked against provided newlib. Can there be another
library installed that the tools picked up?
Post by Yupeng Chang
I found an issue, when I use memcpy, and if the DEST or SOURCE address is
not 4 bytes aligned, the system hangs.
It seems that this toolchain doesn't support using hard float and NEON ?
My question is does this toolchain support hard float and NEON in the
newlib C library?
If I want to use hard float and NEON, how can I do that?
Your reply is more appreciated!!
--
Maxim Kuvyrkov
www.linaro.org
Loading...