This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

__builtin_alloca issues

Hi,

I am porting the opus library from smart remote project into our system. The chip is nrf52832.

When I encoding the pcm data, I got error. After tracing into code, I found a problem of allocating memory. 

In opus library, it will execute the following code

f = __builtin_alloca(sizeof(kiss_fft_scalar)*960);
f2 = __builtin_alloca(sizeof(kiss_fft_cpx)*480);

*f is 0x2000c578. This memory address in valid

*f2 is 0x2000b678. This memory address in invalid.

.bss.m_audio_buffer_pool_nrf_balloc_pool_stack
                0x000000002000afe4        0x3 Output/Obj/mic.o
 *fill*         0x000000002000afe7        0x1 
 .bss.m_audio_buffer_pool_nrf_balloc_pool_mem
                0x000000002000afe8      0x780 Output/Obj/mic.o
 .bss.m_audio_buffer_pool_nrf_balloc_cb
                0x000000002000b768        0x8 Output/Obj/mic.o
 .bss.g_bg_scheduler_queue_nrf_queue_buffer
                0x000000002000b770       0x20 Output/Obj/mic.o
 .bss.g_bg_scheduler_queue_nrf_queue_cb
                0x000000002000b790        0xc Output/Obj/mic.o
 .bss.m_rtt_data1Buffer
                0x000000002000b79c        0xa Output/Obj/mic.o
 *fill*         0x000000002000b7a6        0x2 
 .bss.m_dump_buffer_ptr
                0x000000002000b7a8        0x4 Output/Obj/mic.o
 .bss.m_lock    0x000000002000b7ac        0x1 Output/Obj/mic.o
 *fill*         0x000000002000b7ad        0x3 
 .bss.m_audio_frame_pool_nrf_balloc_pool_stack
                0x000000002000b7b0        0x3 Output/Obj/m_audio_frame.o
 *fill*         0x000000002000b7b3        0x1 
 .bss.m_audio_frame_pool_nrf_balloc_pool_mem
                0x000000002000b7b4      0x144 Output/Obj/m_audio_frame.o
 .bss.m_audio_frame_pool_nrf_balloc_cb
                0x000000002000b8f8        0x8 Output/Obj/m_audio_frame.o
 .bss.libc.__user_format_extender
                0x000000002000b900        0x4 /Applications/SEGGER Embedded Studio for ARM 4.18/lib/libc_v7em_fpv4_sp_d16_hard_t_le_eabi.a(libc2.o)
                0x000000002000b900                __user_format_extender
 *(COMMON)
                0x000000002000b904                __bss_end__ = (__bss_start__ + SIZEOF (.bss))
                0x0000000000008b0c                __bss_size__ = SIZEOF (.bss)
                0x000000002000b904                __bss_load_end__ = __bss_end__
                0x0000000000000001                . = ASSERT (((__bss_start__ == __bss_end__) || ((__bss_end__ - __RAM_segment_start__) <= __RAM_segment_size__)), error: .bss is too large to fit in RAM memory segment)
                0x000000002000b904                __tbss_load_start__ = ALIGN (__bss_end__, 0x4)

.tbss           0x000000002000b904        0x0
                0x000000002000b904                __tbss_start__ = .
 *(.tbss .tbss.*)
                0x000000002000b904                __tbss_end__ = (__tbss_start__ + SIZEOF (.tbss))
                0x0000000000000000                __tbss_size__ = SIZEOF (.tbss)
                0x000000002000b904                __tbss_load_end__ = __tbss_end__
                0x0000000000000001                . = ASSERT (((__tbss_start__ == __tbss_end__) || ((__tbss_end__ - __RAM_segment_start__) <= __RAM_segment_size__)), error: .tbss is too large to fit in RAM memory segment)
                0x000000002000b904                __non_init_load_start__ = ALIGN (__tbss_end__, 0x4)

.non_init       0x000000002000b904        0x0
                0x000000002000b904                __non_init_start__ = .
 *(.non_init .non_init.*)
                0x000000002000b904                __non_init_end__ = (__non_init_start__ + SIZEOF (.non_init))
                0x0000000000000000                __non_init_size__ = SIZEOF (.non_init)
                0x000000002000b904                __non_init_load_end__ = __non_init_end__
                0x0000000000000001                . = ASSERT (((__non_init_start__ == __non_init_end__) || ((__non_init_end__ - __RAM_segment_start__) <= __RAM_segment_size__)), error: .non_init is too large to fit in RAM memory segment)
                0x000000002000b904                __heap_load_start__ = ALIGN (__non_init_end__, 0x4)

.heap           0x000000002000b904     0x3400
                0x000000002000b904                __heap_start__ = .
 *(.heap .heap.*)
                0x000000002000ed04                . = ALIGN (MAX ((__heap_start__ + __HEAPSIZE__), .), 0x4)
 *fill*         0x000000002000b904     0x3400 
                0x000000002000ed04                __heap_end__ = (__heap_start__ + SIZEOF (.heap))
                0x0000000000003400                __heap_size__ = SIZEOF (.heap)
                0x000000002000ed04                __heap_load_end__ = __heap_end__
                0x0000000000000001                . = ASSERT (((__heap_start__ == __heap_end__) || ((__heap_end__ - __RAM_segment_start__) <= __RAM_segment_size__)), error: .heap is too large to fit in RAM memory segment)
                0x000000002000f800                __stack_load_start__ = (__RAM_segment_start__ + (__RAM_segment_size__ - 0x800))

.stack          0x000000002000f800      0x800
                0x000000002000f800                __stack_start__ = .
                0x000000002000f800                __StackLimit = __stack_start__
 *(.stack .stack.*)
                0x0000000020010000                . = ALIGN (MAX ((__stack_start__ + __STACKSIZE__), .), 0x8)
 *fill*         0x000000002000f800      0x800 
                0x0000000020010000                __stack_end__ = (__stack_start__ + SIZEOF (.stack))
                0x0000000000000800                __stack_size__ = SIZEOF (.stack)
                0x0000000020010000                __StackTop = __stack_end__
                0x0000000020010000                __stack_load_end__ = __stack_end__
                0x0000000000000001                . = ASSERT (((__stack_start__ == __stack_end__) || ((__stack_end__ - __RAM_segment_start__) <= __RAM_segment_size__)), error: .stack is too large to fit in RAM memory segment)
                0x0000000000000001                . = ASSERT ((__heap_end__ <= __stack_start__), error: section .heap overlaps absolute placed section .stack)
                0x0000000020010000                __stack_process_load_start__ = ALIGN (__stack_end__, 0x8)

.stack_process  0x0000000020010000        0x0
                0x0000000020010000                __stack_process_start__ = .
 *(.stack_process .stack_process.*)
                0x0000000020010000                . = ALIGN (MAX ((__stack_process_start__ + __STACKSIZE_PROCESS__), .), 0x8)
                0x0000000020010000                __stack_process_end__ = (__stack_process_start__ + SIZEOF (.stack_process))
                0x0000000000000000                __stack_process_size__ = SIZEOF (.stack_process)
                0x0000000020010000                __stack_process_load_end__ = __stack_process_end__
                0x0000000020010000                __RAM_segment_used_end__ = (ALIGN (__stack_end__, 0x8) + SIZEOF (.stack_process))
                0x0000000000010000                __RAM_segment_used_size__ = (__RAM_segment_used_end__ - __RAM_segment_start__)
                0x0000000000000001                . = ASSERT (((__stack_process_start__ == __stack_process_end__) || ((__stack_process_end__ - __RAM_segment_start__) <= __RAM_segment_size__)), error: .stack_process is too large to fit in RAM memory segment)

The address,0x2000b678 is in the range of .bss.m_audio_buffer_pool_nrf_balloc_pool_mem. I expect it will be allocated in .heap.

Any idea for fixing this issue?

Related