Helpful ReplyHot!PIC24FJ64 - Link Error: Could not allocate data memory

Author
matt_amp
Starting Member
  • Total Posts : 58
  • Reward points : 0
  • Joined: 2007/07/23 16:21:18
  • Location: 0
  • Status: offline
2008/06/06 08:37:15 (permalink)
0

PIC24FJ64 - Link Error: Could not allocate data memory

I've got a program written up that is using a large percentage of the processor's data memory (75%), and I need to add a couple of new variables.  When I try to add even one int variable, I get the following link error:

xlitob.o: Link Error: Could not allocate section .ndata, size = 34 bytes, attributes = data near
xprintf.io: Link Error: Could not allocate section .ndata, size = 18 bytes, attributes = data near
 Link Error: Could not allocate data memory
Link step failed.
BUILD FAILED: Fri Jun 06 08:22:14 2008

Here are the memory details when it does compile (without the additional variable):

Program Memory Usage

section                    address   length (PC units)   length (bytes) (dec)
-------                    -------   -----------------   --------------------
.reset                           0                 0x4             0x6  (6)
.ivt                           0x4                0xfc           0x17a  (378)
.aivt                        0x104                0xfc           0x17a  (378)
.text                        0x200              0x2762          0x3b13  (15123)
.const                      0x2962                0xbe           0x11d  (285)
.dinit                      0x2a20                0x8e            0xd5  (213)
.isr                        0x2aae                 0x2             0x3  (3)
__CONFIG2                   0xabfc                 0x2             0x3  (3)
__CONFIG1                   0xabfe                 0x2             0x3  (3)

                     Total program memory used (bytes):         0x4008  (16392) 24%


Data Memory Usage

section                    address      alignment gaps    total length  (dec)
-------                    -------      --------------    -------------------
.nbss                        0x800                   0          0x177a  (6010)
.ndata                      0x1f7a                   0            0x4a  (74)
.ndata                      0x1fc4                   0            0x22  (34)
.ndata                      0x1fe6                   0            0x12  (18)
.ndata                      0x1ff8                   0             0x4  (4)
.ndata                      0x1ffc                   0             0x2  (2)
.dconst                     0x1ffe                   0             0x8  (8)

                        Total data memory used (bytes):         0x1806  (6150) 75%


Dynamic Memory Usage

region                     address                      maximum length  (dec)
------                     -------                      ---------------------
heap                        0x2006                               0x5dc  (1500)
stack                       0x25e2                               0x21e  (542)

                        Maximum dynamic memory (bytes):          0x7fa  (2042)

Is there something that I am overlooking here?  I only need another 45 bytes of data memory...   Any suggestions would be appreciated.

Thanks,
Matt
#1
bosco
Super Member
  • Total Posts : 2119
  • Reward points : 0
  • Joined: 2004/07/24 10:17:53
  • Location: Idaho
  • Status: offline
RE: PIC24FJ64 - Link Error: Could not allocate data memory 2008/06/06 11:22:17 (permalink)
0
change the project build options data memory model.
#2
matt_amp
Starting Member
  • Total Posts : 58
  • Reward points : 0
  • Joined: 2007/07/23 16:21:18
  • Location: 0
  • Status: offline
RE: PIC24FJ64 - Link Error: Could not allocate data memory 2008/06/06 11:25:40 (permalink)
0
Thank you bosco, are you referring to the Heap and Stack sizes?  I've modified both of these up and down with no success.
#3
guymc
Administrator
  • Total Posts : 769
  • Reward points : 0
  • Joined: 2004/06/08 07:14:37
  • Status: offline
RE: PIC24FJ64 - Link Error: Could not allocate data memory 2008/06/06 11:30:43 (permalink)
4.5 (2)
The problem is that you have run out of near data memory. By default, the compiler places all variables into near memory for the most efficient code generation. Only 6K of RAM (6144 bytes) falls into the near space.

Probably you have some arrays allocated in near space that really don't need to be. You could mark each one with __attribute__((far)), or select the following combination of memory models in Build Options:MPLAB C30:Memory Models:

Large data, Small scalar

Cheers!

#4
matt_amp
Starting Member
  • Total Posts : 58
  • Reward points : 0
  • Joined: 2007/07/23 16:21:18
  • Location: 0
  • Status: offline
RE: PIC24FJ64 - Link Error: Could not allocate data memory 2008/06/06 11:33:15 (permalink)
0
Awesome, thank you!
#5
milena
Starting Member
  • Total Posts : 39
  • Reward points : 0
  • Joined: 2006/12/01 07:28:46
  • Location: 0
  • Status: offline
RE: PIC24FJ64 - Link Error: Could not allocate data memory 2009/09/07 09:11:53 (permalink)
0
hi,

I have the same problem. I get error "GlobalVariables.o: Link Error: Could not allocate section .ndata, size = 9654 bytes, attributes = data near
 Link Error: Could not allocate data memory"
, but when I change the build options, I still have error "GlobalVariables.o: Link Error: Could not allocate section .data, size = 9644 bytes, attributes = data
 Link Error: Could not allocate data memory
"

Can anyone help me?

#6
MBedder
Circuit breaker
  • Total Posts : 6316
  • Reward points : 0
  • Joined: 2008/05/30 11:24:01
  • Location: Zelenograd, Russia
  • Status: offline
RE: PIC24FJ64 - Link Error: Could not allocate data memory 2009/09/07 11:57:11 (permalink)
3 (1)
ORIGINAL: milena

I have the same problem

You also have the same answer.
#7
milena
Starting Member
  • Total Posts : 39
  • Reward points : 0
  • Joined: 2006/12/01 07:28:46
  • Location: 0
  • Status: offline
RE: PIC24FJ64 - Link Error: Could not allocate data memory 2009/09/10 03:52:09 (permalink)
0
no, I have other source of the problem :) But now all is ok
#8
bidk
New Member
  • Total Posts : 11
  • Reward points : 0
  • Joined: 2010/10/19 04:58:12
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ64 - Link Error: Could not allocate data memory 2010/10/27 05:08:37 (permalink)
0
Hello,
well I have a similar problem :

main.o: Link Error: Could not allocate section .bss, size = 512 bytes, attributes = bss
 Link Error: Could not allocate data memory

Thing is, that i have to store a big array...
int crcTable[256];
I tried changing the build options and mark it with __attribute__((far)), but with no sucess.
tnx for any ideas !


#9
casein_1984
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2012/05/23 03:37:42
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ64 - Link Error: Could not allocate data memory 2012/05/23 03:43:48 (permalink)
0
Hi,
 
I have similar problem.
I am using DSPIC33EP512MU810 (ROM= 512Kbyte, RAM = 53Kbyte)
I declare two array buffer:-
unsigned char lcd_disp_out[16][240][5] __attribute__((far)); //19200bytes
unsigned char lcd_disp_buf[160][120]__attribute__((far));    //19200bytes
 
I had try as well:-
Large data, Small scalar
 
when I compile, show below message:-
led.o: Link Error: Could not allocate section .bss, size = 38402 bytes, attributes = bss
 Link Error: Could not allocate data memory.
 
Please advice. Thanks :)
 
#10
User.06
Super Member
  • Total Posts : 283
  • Reward points : 0
  • Joined: 2011/11/16 12:27:18
  • Status: offline
Re: RE: PIC24FJ64 - Link Error: Could not allocate data memory 2013/03/13 10:30:29 (permalink)
0
How did you get those usage maps ?
I just get  lines of text telling me the names of the files that are used for the given project.
#11
bigili
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2013/03/20 04:23:44
  • Location: 0
  • Status: offline
Re: RE: PIC24FJ64 - Link Error: Could not allocate data memory 2013/03/20 04:30:09 (permalink)
0
Hi,
 
I have a similar kind of problem, in building the program i have the following statements in the output window
 
 
Debug build of project `D:\march20 13.mcp' started.Language tool versions: pic30-as.exe v3.31, pic30-gcc.exe v3.31, pic30-ld.exe v3.31, pic30-ar.exe v3.31Preprocessor symbol `__DEBUG' is defined.Wed Mar 20 16:52:44 2013----------------------------------------------------------------------Clean: Deleting intermediary and output files.Clean: Done.Executing: "C:\Program Files (x86)\Microchip\mplabc30\v3.31\bin\pic30-gcc.exe" -mcpu=24FJ64GB002 -x c -c   "C:\Program Files (x86)\Microchip\mplabc30\v3.31\include\main.c" -o"main.o" -D__DEBUG -g -Wall -mlarge-code -mconst-in-codeExecuting: "C:\Program Files (x86)\Microchip\mplabc30\v3.31\bin\pic30-gcc.exe" -mcpu=24FJ64GB002 -x c -c   "C:\Program Files (x86)\Microchip\mplabc30\v3.31\include\usb_config.c" -o"usb_config.o" -D__DEBUG -g -Wall -mlarge-code -mconst-in-codeExecuting: "C:\Program Files (x86)\Microchip\mplabc30\v3.31\bin\pic30-gcc.exe" -mcpu=24FJ64GB002 -x c -c   "C:\Program Files (x86)\Microchip\mplabc30\v3.31\include\FSIO.c" -o"FSIO.o" -D__DEBUG -g -Wall -mlarge-code -mconst-in-codeExecuting: "C:\Program Files (x86)\Microchip\mplabc30\v3.31\bin\pic30-gcc.exe" -mcpu=24FJ64GB002 -x c -c   "C:\Program Files (x86)\Microchip\mplabc30\v3.31\include\usb_host.c" -o"usb_host.o" -D__DEBUG -g -Wall -msmall-codeExecuting: "C:\Program Files (x86)\Microchip\mplabc30\v3.31\bin\pic30-gcc.exe" -mcpu=24FJ64GB002 -x c -c   "C:\Program Files (x86)\Microchip\mplabc30\v3.31\include\usb_host_msd.c" -o"usb_host_msd.o" -D__DEBUG -g -Wall -mlarge-code -mconst-in-codeExecuting: "C:\Program Files (x86)\Microchip\mplabc30\v3.31\bin\pic30-gcc.exe" -mcpu=24FJ64GB002 -x c -c   "C:\Program Files (x86)\Microchip\mplabc30\v3.31\include\usb_host_msd_scsi.c" -o"usb_host_msd_scsi.o" -D__DEBUG -g -Wall -mlarge-code -mconst-in-codeExecuting: "C:\Program Files (x86)\Microchip\mplabc30\v3.31\bin\pic30-gcc.exe" -mcpu=24FJ64GB002 "main.o" "usb_config.o" "FSIO.o" "usb_host.o" "usb_host_msd.o" "usb_host_msd_scsi.o" -o"march20 13.cof" -Wl,-Tp24FJ64GB002.gld,--defsym=__MPLAB_BUILD=1,--defsym=__MPLAB_DEBUG=1,-Map="march20 13.map",--report-mem
 
"usb_host.o: Error: Could not allocate section .text, size = 10218 PC units, attributes = code
 usb_host_msd.o: Link Error: Could not allocate section .text, size = 5826 PC units, attributes = code "
 Link Error: Could not allocate program memoryLink step failed.
 
BUILD FAILED
 
please help me in solving this .
THANKS IN ADVANCE!!!!
post edited by bigili - 2013/03/20 04:34:40
#12
gaubuali
Starting Member
  • Total Posts : 21
  • Reward points : 0
  • Joined: 2008/10/18 09:34:27
  • Location: 0
  • Status: offline
Re: PIC24FJ64 - Link Error: Could not allocate data memory 2014/08/15 08:20:44 (permalink)
4 (2)
matt_amp
I've got a program written up that is using a large percentage of the processor's data memory (75%), and I need to add a couple of new variables.  When I try to add even one int variable, I get the following link error:

xlitob.o: Link Error: Could not allocate section .ndata, size = 34 bytes, attributes = data near
xprintf.io: Link Error: Could not allocate section .ndata, size = 18 bytes, attributes = data near
Link Error: Could not allocate data memory
Link step failed.
BUILD FAILED: Fri Jun 06 08:22:14 2008

Here are the memory details when it does compile (without the additional variable):

Program Memory Usage

section                    address   length (PC units)   length (bytes) (dec)
-------                    -------   -----------------   --------------------
.reset                           0                 0x4             0x6  (6)
.ivt                           0x4                0xfc           0x17a  (378)
.aivt                        0x104                0xfc           0x17a  (378)
.text                        0x200              0x2762          0x3b13  (15123)
.const                      0x2962                0xbe           0x11d  (285)
.dinit                      0x2a20                0x8e            0xd5  (213)
.isr                        0x2aae                 0x2             0x3  (3)
__CONFIG2                   0xabfc                 0x2             0x3  (3)
__CONFIG1                   0xabfe                 0x2             0x3  (3)

                    Total program memory used (bytes):         0x4008  (16392) 24%


Data Memory Usage

section                    address      alignment gaps    total length  (dec)
-------                    -------      --------------    -------------------
.nbss                        0x800                   0          0x177a  (6010)
.ndata                      0x1f7a                   0            0x4a  (74)
.ndata                      0x1fc4                   0            0x22  (34)
.ndata                      0x1fe6                   0            0x12  (18)
.ndata                      0x1ff8                   0             0x4  (4)
.ndata                      0x1ffc                   0             0x2  (2)
.dconst                     0x1ffe                   0             0x8  (8)

                       Total data memory used (bytes):         0x1806  (6150) 75%


Dynamic Memory Usage

region                     address                      maximum length  (dec)
------                     -------                      ---------------------
heap                        0x2006                               0x5dc  (1500)
stack                       0x25e2                               0x21e  (542)

                       Maximum dynamic memory (bytes):          0x7fa  (2042)

Is there something that I am overlooking here?  I only need another 45 bytes of data memory...   Any suggestions would be appreciated.

Thanks,
Matt



If you use MPLAB X, XC16, you can set to large Data model at:
Project properties -> xc16-gcc -> Memory model.
#13
pgibbons
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2014/08/02 18:00:45
  • Location: 0
  • Status: offline
Re: PIC24FJ64 - Link Error: Could not allocate data memory 2014/12/05 11:50:34 (permalink) ☄ Helpfulby danielb 2017/04/30 03:40:26
0
I had the same issue and thank you guymc, you have solved my problem.
 
__attribute__((far)) static char uart_buffer[800];
 
 
post edited by pgibbons - 2014/12/05 11:51:50
#14
TurbojohnyS
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2014/07/10 05:40:57
  • Location: 0
  • Status: offline
Re: PIC24FJ64 - Link Error: Could not allocate data memory 2018/01/13 02:34:02 (permalink)
0
Hi for anyone having this problem.
I had a same issue with the PIC33FJ using X16 1.32.
Small scalar,large data, still getting this error (.bss = 1024 etc.etc.)
The solution? Make the buffer in software one time very small (my case I did want 2 buffs of 512 ints (2KB) in DMA, which should fit). So I make both arrays 64 byte, compiling -> succesfully.
Then slowly making the arrays larger and at 512bytes, still succesfully :)
So, you should change to large data model, but in case still getting the location error, just make the buffs one time very small, compile it and thén make it big again... @Microchip.. why?
 
Best regards, John
post edited by TurbojohnyS - 2018/01/13 05:16:05
#15
RISC
Super Member
  • Total Posts : 4996
  • Reward points : 0
  • Status: offline
Re: PIC24FJ64 - Link Error: Could not allocate data memory 2018/01/13 04:13:38 (permalink)
0
Hi,
Please start a new thread. Your issue is related to XC32, not XC16.
Regards
 
#16
TurbojohnyS
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2014/07/10 05:40:57
  • Location: 0
  • Status: offline
Re: PIC24FJ64 - Link Error: Could not allocate data memory 2018/01/13 05:16:59 (permalink)
0
@RISC, its a typo, It's about 33FJ, so it's for XC16 though:)
And its not a problem, just helping.
#17
Jump to:
© 2018 APG vNext Commercial Version 4.5