1

I'm trying to use malloc on an embedded system, specifically a nordic cortex m0. I'm using gcc 4.6.3. If I compile with uVision, the call works, if I compile with gcc it doesn't. I'm at the end of my rope. I've whittled my main file down to the following (I can only interact with the board over serial, hence the uart commands). I don't think it's a library inclusion problem, but I've included the .map file as well. I did notice one odd thing if I log &malloc and then look at the map, the address seems to be off by one. Is that normal? If malloc is in the map at say 0x200 and I log &malloc I get 0x201. Any help would be greatly appreciated.

EDIT: The code compiles in both compilers. The malloc call completes successfully when I compile with uVision, but when I compile with gcc, the call to malloc never returns.

#include <stdlib.h>
#include "boards.h"
#include "simple_uart.h"

void logSt(const char *str){
    simple_uart_putstring((const uint8_t *) str);
    simple_uart_putstring((const uint8_t *) "\r\n");
}

void logCh(const char ch){
    simple_uart_put(ch);
}


int main(void)
{

    simple_uart_config(
        RTS_PIN_NUMBER, 
        TX_PIN_NUMBER, 
        CTS_PIN_NUMBER, 
        RX_PIN_NUMBER, HWFC);

    logSt(" ----- System Started -------");

    logSt("before malloc");

    void *p = malloc(sizeof(int));
    /* NEVER GETS HERE */
    logSt("after malloc"); 
    int *i = (int *)p;
    logSt("after malloc");
    *i = 3;
    logCh((char)(*i));

    return(0);

}

.map file (library paths have been shortened, and I removed the debug sections so I could fit it all, that's where the ... are.)

Archive member included because of file (symbol)

lib/armv6-m/libc.a(lib_a-malloc.o)
                              build/hw-debug/main.o (malloc)
lib/armv6-m/libc.a(lib_a-mallocr.o)
                              lib/armv6-m/libc.a(lib_a-malloc.o) (_malloc_r)
lib/armv6-m/libc.a(lib_a-mlock.o)
                              lib/armv6-m/libc.a(lib_a-mallocr.o) (__malloc_lock)
lib/armv6-m/libc.a(lib_a-sbrkr.o)
                              lib/armv6-m/libc.a(lib_a-mallocr.o) (_sbrk_r)
lib/armv6-m/libc.a(lib_a-freer.o)
                              lib/armv6-m/libc.a(lib_a-malloc.o) (_free_r)
lib/armv6-m/libc.a(lib_a-impure.o)
                              lib/armv6-m/libc.a(lib_a-malloc.o) (_impure_ptr)
lib/armv6-m/libc.a(lib_a-reent.o)
                              lib/armv6-m/libc.a(lib_a-sbrkr.o) (errno)
lib/armv6-m/libcs3.a(start_c.o)
                              (__cs3_start_c)
lib/armv6-m/libcs3unhosted.a(unhosted-sbrk.o)
                              lib/armv6-m/libc.a(lib_a-sbrkr.o) (_sbrk)
lib/armv6-m/libcs3unhosted.a(unhosted-start.o)
                              (_start)
lib/armv6-m/libc.a(lib_a-errno.o)
                              lib/armv6-m/libcs3unhosted.a(unhosted-sbrk.o) (__errno)
lib/armv6-m/libc.a(lib_a-init.o)
                              lib/armv6-m/libcs3.a(start_c.o) (__libc_init_array)
lib/armv6-m/libcs3.a(heap.o)
                              lib/armv6-m/libcs3unhosted.a(unhosted-sbrk.o) (__cs3_heap_limit)

Allocating common symbols
Common symbol       size              file

errno               0x4               lib/armv6-m/libc.a(lib_a-reent.o)

Memory Configuration

Name             Origin             Length             Attributes
rom              0x0000000000014000 0x000000000002c000 xr
ram              0x0000000020002000 0x0000000000002000 xrw
*default*        0x0000000000000000 0xffffffffffffffff

Linker script and memory map

LOAD lib/gcc/arm-none-eabi/4.6.3/armv6-m/crti.o
LOAD lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtbegin.o
LOAD build/hw-debug/system_nrf51.o
LOAD build/hw-debug/main.o
LOAD build/hw-debug/simple_uart.o
LOAD build/hw-debug/gcc_startup_nrf51.o
START GROUP
LOAD lib/gcc/arm-none-eabi/4.6.3/armv6-m/libgcc.a
LOAD lib/armv6-m/libc.a
LOAD lib/armv6-m/libcs3.a
LOAD lib/armv6-m/libcs3unhosted.a
LOAD lib/armv6-m/libm.a
LOAD lib/armv6-m/libstdc++.a
END GROUP
START GROUP
LOAD lib/gcc/arm-none-eabi/4.6.3/armv6-m/libgcc.a
LOAD lib/armv6-m/libc.a
END GROUP
LOAD lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtend.o
LOAD lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtn.o
START GROUP
LOAD lib/gcc/arm-none-eabi/4.6.3/armv6-m/libgcc.a
LOAD lib/armv6-m/libc.a
LOAD lib/armv6-m/libcs3.a
LOAD lib/armv6-m/libcs3unhosted.a
END GROUP
                0x00000000200028b0                PROVIDE (__cs3_heap_start, _end)
                0x0000000020004000                PROVIDE (__cs3_heap_end, (__cs3_region_start_ram + __cs3_region_size_ram))
                0x0000000000000001                PROVIDE (__cs3_region_num, ((__cs3_regions_end - __cs3_regions) / 0x14))
                0x0000000020004000                PROVIDE (__cs3_stack, (__cs3_region_start_ram + __cs3_region_size_ram))

.text           0x0000000000014000      0xe84
 CREATE_OBJECT_SYMBOLS
                0x0000000000014000                __cs3_region_start_rom = .
 *(.cs3.region-head.rom)
                0x0000000000000001                ASSERT ((. == __cs3_region_start_rom), .cs3.region-head.rom not permitted)
                0x0000000000014000                __cs3_interrupt_vector = __cs3_interrupt_vector_cortex_m
 *(.cs3.interrupt_vector)
 .cs3.interrupt_vector
                0x0000000000014000       0xc0 build/hw-debug/gcc_startup_nrf51.o
                0x0000000000014000                __cs3_interrupt_vector_cortex_m
                0x0000000000000001                ASSERT ((. != __cs3_interrupt_vector_cortex_m), No interrupt vector)
                0x00000000000140c0                PROVIDE (__cs3_reset, __cs3_reset_cortex_m)
 *(.cs3.reset)
 .cs3.reset     0x00000000000140c0       0x20 build/hw-debug/gcc_startup_nrf51.o
                0x00000000000140c0                __cs3_reset_cortex_m
                0x0000000000014128                PROVIDE (__cs3_start_asm, _start)
 *(.text.cs3.init)
 .text.cs3.init
                0x00000000000140e0       0x48 lib/armv6-m/libcs3.a(start_c.o)
                0x00000000000140e0                __cs3_start_c
 .text.cs3.init
                0x0000000000014128       0x10 lib/armv6-m/libcs3unhosted.a(unhosted-start.o)
                0x0000000000014128                _start
 *(.text .text.* .gnu.linkonce.t.*)
 .text          0x0000000000014138        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crti.o
 .text          0x0000000000014138       0x60 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtbegin.o
 .text          0x0000000000014198        0x0 build/hw-debug/system_nrf51.o
 .text.SystemInit
                0x0000000000014198       0x34 build/hw-debug/system_nrf51.o
                0x0000000000014198                SystemInit
 .text.SystemCoreClockUpdate
                0x00000000000141cc       0x10 build/hw-debug/system_nrf51.o
                0x00000000000141cc                SystemCoreClockUpdate
 .text          0x00000000000141dc        0x0 build/hw-debug/main.o
 .text.logSt    0x00000000000141dc       0x20 build/hw-debug/main.o
                0x00000000000141dc                logSt
 .text.logCh    0x00000000000141fc       0x20 build/hw-debug/main.o
                0x00000000000141fc                logCh
 .text.main     0x000000000001421c       0x68 build/hw-debug/main.o
                0x000000000001421c                main
 .text          0x0000000000014284        0x0 build/hw-debug/simple_uart.o
 .text.nrf_delay_us
                0x0000000000014284       0x3c build/hw-debug/simple_uart.o
 .text.nrf_gpio_cfg_output
                0x00000000000142c0       0x18 build/hw-debug/simple_uart.o
 .text.nrf_gpio_cfg_input
                0x00000000000142d8       0x2c build/hw-debug/simple_uart.o
 .text.simple_uart_get
                0x0000000000014304       0x2c build/hw-debug/simple_uart.o
                0x0000000000014304                simple_uart_get
 .text.simple_uart_get_with_timeout
                0x0000000000014330       0x78 build/hw-debug/simple_uart.o
                0x0000000000014330                simple_uart_get_with_timeout
 .text.simple_uart_put
                0x00000000000143a8       0x40 build/hw-debug/simple_uart.o
                0x00000000000143a8                simple_uart_put
 .text.simple_uart_putstring
                0x00000000000143e8       0x50 build/hw-debug/simple_uart.o
                0x00000000000143e8                simple_uart_putstring
 .text.simple_uart_config
                0x0000000000014438       0xdc build/hw-debug/simple_uart.o
                0x0000000000014438                simple_uart_config
 .text          0x0000000000014514        0xc build/hw-debug/gcc_startup_nrf51.o
                0x0000000000014514                NMI_Handler
                0x0000000000014516                HardFault_Handler
                0x0000000000014518                SVC_Handler
                0x000000000001451a                PendSV_Handler
                0x000000000001451c                SysTick_Handler
                0x000000000001451e                RADIO_IRQHandler
                0x000000000001451e                SWI4_IRQHandler
                0x000000000001451e                TEMP_IRQHandler
                0x000000000001451e                QDEC_IRQHandler
                0x000000000001451e                UART0_IRQHandler
                0x000000000001451e                SWI5_IRQHandler
                0x000000000001451e                WUCOMP_COMP_IRQHandler
                0x000000000001451e                TIMER0_IRQHandler
                0x000000000001451e                SWI0_IRQHandler
                0x000000000001451e                TIMER1_IRQHandler
                0x000000000001451e                ECB_IRQHandler
                0x000000000001451e                Default_Handler
                0x000000000001451e                ADC_IRQHandler
                0x000000000001451e                SWI3_IRQHandler
                0x000000000001451e                CCM_AAR_IRQHandler
                0x000000000001451e                WDT_IRQHandler
                0x000000000001451e                SWI2_IRQHandler
                0x000000000001451e                RNG_IRQHandler
                0x000000000001451e                SPI1_TWI1_IRQHandler
                0x000000000001451e                RTC1_IRQHandler
                0x000000000001451e                TIMER2_IRQHandler
                0x000000000001451e                SWI1_IRQHandler
                0x000000000001451e                SPI0_TWI0_IRQHandler
                0x000000000001451e                RTC0_IRQHandler
                0x000000000001451e                GPIOTE_IRQHandler
                0x000000000001451e                POWER_CLOCK_IRQHandler
 .text          0x0000000000014520       0x28 lib/armv6-m/libc.a(lib_a-malloc.o)
                0x0000000000014520                malloc
                0x0000000000014534                free
 .text          0x0000000000014548      0x510 lib/armv6-m/libc.a(lib_a-mallocr.o)
                0x0000000000014548                _malloc_r
 .text          0x0000000000014a58        0x8 lib/armv6-m/libc.a(lib_a-mlock.o)
                0x0000000000014a58                __malloc_lock
                0x0000000000014a5c                __malloc_unlock
 .text          0x0000000000014a60       0x24 lib/armv6-m/libc.a(lib_a-sbrkr.o)
                0x0000000000014a60                _sbrk_r
 .text          0x0000000000014a84      0x240 lib/armv6-m/libc.a(lib_a-freer.o)
                0x0000000000014a84                _malloc_trim_r
                0x0000000000014b2c                _free_r
 .text          0x0000000000014cc4        0x0 lib/armv6-m/libc.a(lib_a-impure.o)
 .text          0x0000000000014cc4      0x100 lib/armv6-m/libc.a(lib_a-reent.o)
                0x0000000000014cc4                cleanup_glue
                0x0000000000014ce0                _reclaim_reent
                0x0000000000014d80                _wrapup_reent
 .text          0x0000000000014dc4       0x34 lib/armv6-m/libcs3.a(start_c.o)
                0x0000000000014dc4                __cs3_premain
 .text          0x0000000000014df8       0x3c lib/armv6-m/libcs3unhosted.a(unhosted-sbrk.o)
                0x0000000000014df8                _sbrk
 .text          0x0000000000014e34        0x0 lib/armv6-m/libcs3unhosted.a(unhosted-start.o)
 .text          0x0000000000014e34        0xc lib/armv6-m/libc.a(lib_a-errno.o)
                0x0000000000014e34                __errno
 .text          0x0000000000014e40       0x44 lib/armv6-m/libc.a(lib_a-init.o)
                0x0000000000014e40                __libc_init_array
 .text          0x0000000000014e84        0x0 lib/armv6-m/libcs3.a(heap.o)
 .text          0x0000000000014e84        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtend.o
 .text          0x0000000000014e84        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtn.o
 *(.plt)
 *(.gnu.warning)
 *(.glue_7t)
 .glue_7t       0x0000000000000000        0x0 linker stubs
 *(.glue_7)
 .glue_7        0x0000000000000000        0x0 linker stubs
 *(.vfp11_veneer)
 .vfp11_veneer  0x0000000000000000        0x0 linker stubs
 *(.ARM.extab* .gnu.linkonce.armextab.*)
 .ARM.extab.cs3.reset
                0x0000000000014e84        0x0 build/hw-debug/gcc_startup_nrf51.o
 *(.gcc_except_table)

.v4_bx          0x0000000000014e84        0x0
 .v4_bx         0x0000000000000000        0x0 linker stubs

.iplt           0x0000000000014e84        0x0
 .iplt          0x0000000000000000        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crti.o

.eh_frame_hdr
 *(.eh_frame_hdr)

.eh_frame       0x0000000000014e84        0x4
 *(.eh_frame)
 .eh_frame      0x0000000000014e84        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtbegin.o
 .eh_frame      0x0000000000014e84        0x4 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtend.o
                0x0000000000014e88                PROVIDE (__exidx_start, .)

.ARM.exidx      0x0000000000014e88        0x8
 *(.ARM.exidx* .gnu.linkonce.armexidx.*)
 .ARM.exidx.cs3.reset
                0x0000000000014e88        0x8 build/hw-debug/gcc_startup_nrf51.o
                0x0000000000014e90                PROVIDE (__exidx_end, .)

.rel.dyn        0x0000000000014e90        0x0
 .rel.iplt      0x0000000000000000        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crti.o

.rodata         0x0000000000014e90       0x80
 *(.rodata .rodata.* .gnu.linkonce.r.*)
 .rodata        0x0000000000014e90       0x44 build/hw-debug/main.o
 .rodata        0x0000000000014ed4        0x4 lib/armv6-m/libc.a(lib_a-impure.o)
                0x0000000000014ed4                _global_impure_ptr
 .rodata.str1.4
                0x0000000000014ed8        0x4 lib/armv6-m/libc.a(lib_a-impure.o)
                0x0000000000014edc                . = ALIGN (0x4)
 *(.init)
 .init          0x0000000000014edc        0x4 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crti.o
                0x0000000000014edc                _init
 .init          0x0000000000014ee0        0x8 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtn.o
                0x0000000000014ee8                . = ALIGN (0x4)
                0x0000000000014ee8                __preinit_array_start = .
 *(.preinit_array)
                0x0000000000014ee8                __preinit_array_end = .
                0x0000000000014ee8                . = ALIGN (0x4)
                0x0000000000014ee8                __init_array_start = .
 *(SORT(.init_array.*))
 *(.init_array)
 .init_array    0x0000000000014ee8        0x4 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtbegin.o
                0x0000000000014eec                __init_array_end = .
                0x0000000000014eec                . = ALIGN (0x4)
 *(.fini)
 .fini          0x0000000000014eec        0x4 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crti.o
                0x0000000000014eec                _fini
 .fini          0x0000000000014ef0        0x8 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtn.o
                0x0000000000014ef8                . = ALIGN (0x4)
                0x0000000000014ef8                __fini_array_start = .
 *(.fini_array)
 .fini_array    0x0000000000014ef8        0x4 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtbegin.o
 *(SORT(.fini_array.*))
                0x0000000000014efc                __fini_array_end = .
                0x0000000000014efc                . = ALIGN (0x4)
 *crtbegin.o(.ctors)
 *(EXCLUDE_FILE(*crtend.o) .ctors)
 *(SORT(.ctors.*))
 *crtend.o(.ctors)
                0x0000000000014efc                . = ALIGN (0x4)
 *crtbegin.o(.dtors)
 *(EXCLUDE_FILE(*crtend.o) .dtors)
 *(SORT(.dtors.*))
 *crtend.o(.dtors)
                0x0000000000014efc                . = ALIGN (0x4)
                0x0000000000014efc                __cs3_regions = .
                0x0000000000014efc        0x4 LONG 0x0
                0x0000000000014f00        0x4 LONG 0x14f10 __cs3_region_init_ram
                0x0000000000014f04        0x4 LONG 0x20002000 __cs3_region_start_ram
                0x0000000000014f08        0x4 LONG 0x858 __cs3_region_init_size_ram
                0x0000000000014f0c        0x4 LONG 0x58 __cs3_region_zero_size_ram
                0x0000000000014f10                __cs3_regions_end = .
                0x0000000000014f10                . = ALIGN (0x8)
 *(.rom)
 *(.rom.b .bss.rom)
                0x0000000000014f10                _etext = .
                0x0000000000040000                __cs3_region_end_rom = (__cs3_region_start_rom + 0x2c000)
                0x000000000002c000                __cs3_region_size_rom = 0x2c000

.data           0x0000000020002000      0x858 load address 0x0000000000014f10
                0x0000000020002000                __cs3_region_start_ram = .
 *(.cs3.region-head.ram)
 *(.jcr)
 .jcr           0x0000000020002000        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtbegin.o
 .jcr           0x0000000020002000        0x4 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtend.o
 *(.got.plt)
 *(.got)
 *(.shdata)
 *(.data .data.* .gnu.linkonce.d.*)
 .data          0x0000000020002004        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crti.o
 .data          0x0000000020002004        0x4 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtbegin.o
                0x0000000020002004                __dso_handle
 .data          0x0000000020002008        0x0 build/hw-debug/system_nrf51.o
 .data.SystemCoreClock
                0x0000000020002008        0x4 build/hw-debug/system_nrf51.o
                0x0000000020002008                SystemCoreClock
 .data          0x000000002000200c        0x0 build/hw-debug/main.o
 .data          0x000000002000200c        0x0 build/hw-debug/simple_uart.o
 .data          0x000000002000200c        0x0 build/hw-debug/gcc_startup_nrf51.o
 .data          0x000000002000200c        0x0 lib/armv6-m/libc.a(lib_a-malloc.o)
 .data          0x000000002000200c      0x410 lib/armv6-m/libc.a(lib_a-mallocr.o)
                0x000000002000200c                __malloc_av_
                0x0000000020002414                __malloc_sbrk_base
                0x0000000020002418                __malloc_trim_threshold
 .data          0x000000002000241c        0x0 lib/armv6-m/libc.a(lib_a-mlock.o)
 .data          0x000000002000241c        0x0 lib/armv6-m/libc.a(lib_a-sbrkr.o)
 .data          0x000000002000241c        0x0 lib/armv6-m/libc.a(lib_a-freer.o)
 *fill*         0x000000002000241c        0x4 00
 .data          0x0000000020002420      0x430 lib/armv6-m/libc.a(lib_a-impure.o)
                0x0000000020002420                _impure_ptr
 .data          0x0000000020002850        0x0 lib/armv6-m/libc.a(lib_a-reent.o)
 .data          0x0000000020002850        0x0 lib/armv6-m/libcs3.a(start_c.o)
 .data          0x0000000020002850        0x4 lib/armv6-m/libcs3unhosted.a(unhosted-sbrk.o)
 .data          0x0000000020002854        0x0 lib/armv6-m/libcs3unhosted.a(unhosted-start.o)
 .data          0x0000000020002854        0x0 lib/armv6-m/libc.a(lib_a-errno.o)
 .data          0x0000000020002854        0x0 lib/armv6-m/libc.a(lib_a-init.o)
 .data          0x0000000020002854        0x4 lib/armv6-m/libcs3.a(heap.o)
                0x0000000020002854                __cs3_heap_limit
 .data          0x0000000020002858        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtend.o
 .data          0x0000000020002858        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtn.o
                0x0000000020002858                . = ALIGN (0x8)
 *(.ram)
                0x0000000020002858                _edata = .

.igot.plt       0x0000000020002858        0x0 load address 0x0000000000015768
 .igot.plt      0x0000000000000000        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crti.o

.bss            0x0000000020002858       0x58 load address 0x0000000000015768
 *(.shbss)
 *(.bss .bss.* .gnu.linkonce.b.*)
 .bss           0x0000000020002858        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crti.o
 .bss           0x0000000020002858       0x1c lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtbegin.o
 .bss           0x0000000020002874        0x0 build/hw-debug/system_nrf51.o
 .bss           0x0000000020002874        0x0 build/hw-debug/main.o
 .bss           0x0000000020002874        0x0 build/hw-debug/simple_uart.o
 .bss           0x0000000020002874        0x0 build/hw-debug/gcc_startup_nrf51.o
 .bss           0x0000000020002874        0x0 lib/armv6-m/libc.a(lib_a-malloc.o)
 .bss           0x0000000020002874       0x34 lib/armv6-m/libc.a(lib_a-mallocr.o)
                0x0000000020002874                __malloc_top_pad
                0x0000000020002878                __malloc_current_mallinfo
                0x00000000200028a0                __malloc_max_sbrked_mem
                0x00000000200028a4                __malloc_max_total_mem
 .bss           0x00000000200028a8        0x0 lib/armv6-m/libc.a(lib_a-mlock.o)
 .bss           0x00000000200028a8        0x0 lib/armv6-m/libc.a(lib_a-sbrkr.o)
 .bss           0x00000000200028a8        0x0 lib/armv6-m/libc.a(lib_a-freer.o)
 .bss           0x00000000200028a8        0x0 lib/armv6-m/libc.a(lib_a-impure.o)
 .bss           0x00000000200028a8        0x0 lib/armv6-m/libc.a(lib_a-reent.o)
 .bss           0x00000000200028a8        0x0 lib/armv6-m/libcs3.a(start_c.o)
 .bss           0x00000000200028a8        0x0 lib/armv6-m/libcs3unhosted.a(unhosted-sbrk.o)
 .bss           0x00000000200028a8        0x0 lib/armv6-m/libcs3unhosted.a(unhosted-start.o)
 .bss           0x00000000200028a8        0x0 lib/armv6-m/libc.a(lib_a-errno.o)
 .bss           0x00000000200028a8        0x0 lib/armv6-m/libc.a(lib_a-init.o)
 .bss           0x00000000200028a8        0x0 lib/armv6-m/libcs3.a(heap.o)
 .bss           0x00000000200028a8        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtend.o
 .bss           0x00000000200028a8        0x0 lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtn.o
 *(COMMON)
 COMMON         0x00000000200028a8        0x4 lib/armv6-m/libc.a(lib_a-reent.o)
                0x00000000200028a8                errno
                0x00000000200028b0                . = ALIGN (0x8)
 *fill*         0x00000000200028ac        0x4 00
 *(.ram.b .bss.ram)
                0x00000000200028b0                _end = .
                0x00000000200028b0                __end = .
                0x0000000020004000                __cs3_region_end_ram = (__cs3_region_start_ram + 0x2000)
                0x0000000000002000                __cs3_region_size_ram = 0x2000
                0x0000000000014f10                __cs3_region_init_ram = LOADADDR (.data)
                0x0000000000000858                __cs3_region_init_size_ram = (_edata - ADDR (.data))
                0x0000000000000058                __cs3_region_zero_size_ram = (_end - _edata)

 ...

.comment        0x0000000000000000       0x3d
 .comment       0x0000000000000000       0x3d lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtbegin.o
                                         0x3e (size before relaxing)
 .comment       0x0000000000000000       0x3e build/hw-debug/system_nrf51.o
 .comment       0x0000000000000000       0x3e build/hw-debug/main.o
 .comment       0x0000000000000000       0x3e build/hw-debug/simple_uart.o
 .comment       0x0000000000000000       0x3e lib/armv6-m/libc.a(lib_a-malloc.o)
 .comment       0x0000000000000000       0x3e lib/armv6-m/libc.a(lib_a-mallocr.o)
 .comment       0x0000000000000000       0x3e lib/armv6-m/libc.a(lib_a-mlock.o)
 .comment       0x0000000000000000       0x3e lib/armv6-m/libc.a(lib_a-sbrkr.o)
 .comment       0x0000000000000000       0x3e lib/armv6-m/libc.a(lib_a-freer.o)
 .comment       0x0000000000000000       0x3e lib/armv6-m/libc.a(lib_a-impure.o)
 .comment       0x0000000000000000       0x3e lib/armv6-m/libc.a(lib_a-reent.o)
 .comment       0x0000000000000000       0x3e lib/armv6-m/libc.a(lib_a-errno.o)
 .comment       0x0000000000000000       0x3e lib/armv6-m/libc.a(lib_a-init.o)
 .comment       0x0000000000000000       0x3e lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtend.o

.stack          0x0000000000000000      0x800
 .stack         0x0000000000000000      0x800 build/hw-debug/gcc_startup_nrf51.o
                0x0000000000000000                __cs3_stack_mem

.heap           0x0000000000000000      0x800
 .heap          0x0000000000000000      0x800 build/hw-debug/gcc_startup_nrf51.o
                0x0000000000000000                __cs3_heap_start
                0x0000000000000800                __cs3_heap_end

 ...

.ARM.attributes
                0x0000000000000000       0x2f
 *(.ARM.attributes)
 .ARM.attributes
                0x0000000000000000       0x1f lib/gcc/arm-none-eabi/4.6.3/armv6-m/crti.o
 .ARM.attributes
                0x000000000000001f       0x2d lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtbegin.o
 .ARM.attributes
                0x000000000000004c       0x33 build/hw-debug/system_nrf51.o
 .ARM.attributes
                0x000000000000007f       0x33 build/hw-debug/main.o
 .ARM.attributes
                0x00000000000000b2       0x33 build/hw-debug/simple_uart.o
 .ARM.attributes
                0x00000000000000e5       0x23 build/hw-debug/gcc_startup_nrf51.o
 .ARM.attributes
                0x0000000000000108       0x2d lib/armv6-m/libc.a(lib_a-malloc.o)
 .ARM.attributes
                0x0000000000000135       0x2d lib/armv6-m/libc.a(lib_a-mallocr.o)
 .ARM.attributes
                0x0000000000000162       0x2d lib/armv6-m/libc.a(lib_a-mlock.o)
 .ARM.attributes
                0x000000000000018f       0x2d lib/armv6-m/libc.a(lib_a-sbrkr.o)
 .ARM.attributes
                0x00000000000001bc       0x2d lib/armv6-m/libc.a(lib_a-freer.o)
 .ARM.attributes
                0x00000000000001e9       0x2d lib/armv6-m/libc.a(lib_a-impure.o)
 .ARM.attributes
                0x0000000000000216       0x2d lib/armv6-m/libc.a(lib_a-reent.o)
 .ARM.attributes
                0x0000000000000243       0x2d lib/armv6-m/libcs3.a(start_c.o)
 .ARM.attributes
                0x0000000000000270       0x2d lib/armv6-m/libcs3unhosted.a(unhosted-sbrk.o)
 .ARM.attributes
                0x000000000000029d       0x1d lib/armv6-m/libcs3unhosted.a(unhosted-start.o)
 .ARM.attributes
                0x00000000000002ba       0x2d lib/armv6-m/libc.a(lib_a-errno.o)
 .ARM.attributes
                0x00000000000002e7       0x2d lib/armv6-m/libc.a(lib_a-init.o)
 .ARM.attributes
                0x0000000000000314       0x2d lib/armv6-m/libcs3.a(heap.o)
 .ARM.attributes
                0x0000000000000341       0x2d lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtend.o
 .ARM.attributes
                0x000000000000036e       0x1f lib/gcc/arm-none-eabi/4.6.3/armv6-m/crtn.o
4

2 回答 2

3

地址的关闭 1 是 ARM 事物(Cortex)。它表明所讨论的函数是一个 Thumb 函数。CPU 在跳转时剥离低位,并在到达时将 CPU 设置为 Thumb。

您描述的 malloc 失败可能是由于代码中其他地方的错误内存写入破坏了堆管理系统。它出现在 GCC 中的原因是内存的组织方式不同,并且错误的写入是用 GCC 和其他一些随机的 RAM 用 uVision 撞击堆管理器(如果它是运行时错误。)

现在你的 malloc 问题到底是什么?无限循环?记不清?还是编译/链接时错误?如果是这样,那么它可能是库、死区,甚至没有编译您的项目,并且启用了交互工作的类型问题(因为 malloc 是一个 Thumb 函数,而您的其他代码不是。)

请提供更多信息以获得更完整的答案。

于 2013-04-17T16:46:07.427 回答
1

对我来说,问题似乎出在您为堆分配内存的启动文件中。您可以仔细检查用于 gcc 编译器的启动文件中的堆开始和堆结束位置是否正确并且没有超出为堆分配的边界。如果可能,请发布您分配堆内存的启动文件部分。

于 2013-04-19T14:02:21.187 回答