Raspberry Pi Pico dynamic allocation link error

With the following test program written for the RP2040 microcontroller:

procedure test_new is

  type Thing is record
    x : Integer;
    y : Integer;
  end record;

  type ThingAccess is access Thing;

  T : ThingAccess;

begin
  T := new Thing'(1, 2);
end test_new;

I get the following link errors:

/home/pmunts/.local/share/alire/toolchains/gnat_arm_elf_15.2.1_a5e9cfb1/bin/../lib/gcc/arm-eabi/15.2.0/../../../../arm-eabi/bin/ld: /home/pmunts/.local/share/alire/builds/light_tasking_rp2040_15.2.0_8e0bd80e/24231be1c545c807cb2fe471458694876552a82aa399c1eb37d1daa261d6f92e/adalib/libgnat.a(s-memory.o): in function `__gnat_malloc':
s-memory.adb:(.text.__gnat_malloc+0x30): undefined reference to `__atomic_compare_exchange_4'
/home/pmunts/.local/share/alire/toolchains/gnat_arm_elf_15.2.1_a5e9cfb1/bin/../lib/gcc/arm-eabi/15.2.0/../../../../arm-eabi/bin/ld: (__atomic_compare_exchange_4): Unknown destination type (ARM/Thumb) in /home/pmunts/.local/share/alire/builds/light_tasking_rp2040_15.2.0_8e0bd80e/24231be1c545c807cb2fe471458694876552a82aa399c1eb37d1daa261d6f92e/adalib/libgnat.a(s-memory.o)
s-memory.adb:(.text.__gnat_malloc+0x30): dangerous relocation: unsupported relocation
collect2: error: ld returned 1 exit status
gprbuild: link of test_new.adb failed

I’m using light_tasking_rp2040 and rp2040_hal:

authors = [
"Philip Munts",
]
description = "Phil's RP2040 Light Tasking Firmware Template"
executables = [
"test_new",
]
licenses = "BSD-1-Clause"
maintainers = [
"Philip Munts <phil@munts.net>",
]
maintainers-logins = [
"pmunts",
]
name = "test_new"
tags = [
"embedded",
"gpio",
"microcontroller",
"rp2040",
]
version = "2.24798.1"
[configuration]
auto_gpr_with = true
disabled = false
generate_ada = true
generate_c = true
generate_gpr = true
output_dir = "config"
[configuration.values]
[configuration.values.light_tasking_rp2040]
Board = "generic_board"
Max_CPUs = 2
[configuration.values.rp2040_hal]
Interrupts = "bb_runtimes"
Use_Startup = false
[[actions]]
command = [
"sh",
"-c",
"./postbuild.sh",
]
directory = "."
type = "post-build"
[[depends-on]]
light_tasking_rp2040 = "*"
rp2040_hal = "^2"

Is dynamic allocation supposed to be supported on the RP2040?

After rereading the profile notes, I switched from light_tasking to embedded to fix this. For some reason, I had thought that embedded had the least functionality and light_tasking the most.

I would have expected the same to be honest!

embedded has the most functionality, but all runtime profiles (light, light-tasking, and embedded) support dynamic memory allocation.

Note that Unchecked_Deallocation is only supported on the embedded profile (deallocation is a no-op on light and light-tasking); this allows the heap allocator to be super simple and deterministic on light and light-tasking.

In any case, you shouldn’t be getting that linker error. It looks like there’s a missing synchronisation primitive that the runtime needs to provide. I will investigate.

Thanks. I don’t need deallocation and it would be nice to switch back to light_tasking.

1 Like

I’ve been able to reproduce it and I’m pushing through a fix now in this PR: community-bb-runtimes#23.

I’ll try to get a new release out with the fix in the next few days so that you can switch back to light_tasking.

2 Likes