Posix GCC demo not running on Ubuntu server 24.04 Arm64

Hi All,

I’m new to FreeRTOS and I’m just trying to run the Posix GCC demo on my Ubuntu ARM64 server VM which is hosted on a MAC M1 silicon.
The compilation works just fine, but as soon as I try to run “posix_demo” I immediatly get a segmentation fault.
Here’s the gdb trace:

Trace started.
The trace will be dumped to disk if a call to configASSERT() fails.
Starting full demo

Thread 1 "posix_demo" received signal SIGSEGV, Segmentation fault.
pxPortInitialiseStack (pxTopOfStack=pxTopOfStack@entry=0xaab2aac19838, pxEndOfStack=0xaaaaaac19840, 
    pxCode=pxCode@entry=0xaaaaaaaa2e50 <prvCheckTask>, pvParameters=pvParameters@entry=0x0)
    at /home/develop/FreeRTOS/FreeRTOS/Source/portable/ThirdParty/GCC/Posix/port.c:166
166         pxTopOfStack = ( StackType_t * ) thread - 1;

Do you have any idea on why this happens?

Here’s my GCC configuration:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-linux-gnu/13/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.2.0-23ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-offload-targets=nvptx-none=/build/gcc-13-dIwDw0/gcc-13-13.2.0/debian/tmp-nvptx/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Ubuntu 13.2.0-23ubuntu4) 

Many thanks in advance for the help

Hi, just quickly looked at your gdb trace:
pxTopOfStack = 0xaab2aac19838
pxEndOfStack = 0xaaaaaac19840

This translates to a 32G stack size. The default stack size used by the demo is 16K. Have you made changes to use a big stack size?

Without making any changes to the demo, I am getting this when I break at the same function call:

Breakpoint 1, pxPortInitialiseStack (pxTopOfStack=pxTopOfStack@entry=0x555555665a78 <stackTzCtrl+131064>, pxEndOfStack=0x555555645a80 <stackTzCtrl>, pxCode=pxCode@entry=0x555555574600 <TzCtrl>, pvParameters=pvParameters@entry=0x0) at /code/FreeRTOS/FreeRTOS/Source/portable/ThirdParty/GCC/Posix/port.c:154
154	{

Which FreeRTOS version are you using? Can you try the latest main branch - GitHub - FreeRTOS/FreeRTOS: 'Classic' FreeRTOS distribution. Started as Git clone of FreeRTOS SourceForge SVN repo. Submodules the kernel..

OK I’ve tried to clone the main branch from Here as you suggested. I’ve used the following command:

git clone https://github.com/FreeRTOS/FreeRTOS.git --recurse-submodules

Posix_GCC demo compiles but it fails with the very same segfault

Then I tried to get the code from a different branch with the following command:

git clone https://github.com/FreeRTOS/FreeRTOS.git --recurse-submodules --branch=V10.4.1

During the compilation of the Posix_GCC demo I’ve got an error as libpcap-dev was not installed on my system. I’ve installed it, recompiled and it works fine.

My gut feeling is that there is something messed up in the main branch that does reflect in missing #define in FreeRtos.h config file of the demo which set the stack to 32G (which I assume is the maximum value).

Anyhow thanks for the suggestions.

This PR fixes the issue - Fix crash on Ubuntu 24.04 ARM64 by aggarg · Pull Request #1253 · FreeRTOS/FreeRTOS · GitHub. Please give it a try and let me know if you are able to run with these changes.

Thank you for reporting this.

2 Likes

Awesome! Tested on main branch without unsigned short in PTHREAD_STACK_MIN and it works like a charm.

Many thanks for the effort.