• AVR Freaks

Hot!Link Error: Could not allocate section .text

Author
funbotix
Starting Member
  • Total Posts : 57
  • Reward points : 0
  • Joined: 2010/02/18 14:53:57
  • Location: San Antonio, Texas
  • Status: offline
2010/05/03 11:47:52 (permalink)
0

Link Error: Could not allocate section .text

Hi,

I'm doing a project with a PIC24HJ128GP510.  When I do a build, the build window shows that I've used about 70% of the code space and about 50% of the RAM.  However, I also get a few of these error messages:

Link Error: Could not allocate section .text, size = 2 PC units, attributes = code

I've seen another post on this forum where the suggestion was to not use STDIO, printf, etc.  I'm not yet ready to write my own printf equivalent to format floating point values, or atof to convert them back to floating point.  I have lots of ASCII data that goes in/out a serial port to an external device; and I use STDIO functions like these a lot.

Is there some way to tell what the cause of this error is, other than commenting out modules or functions till it goes away?  I've found that I can comment out different modules, any one of which will make the above error go away.  So, I don't think it's one module in particular that's causing the problem.

I also tried splitting a few large modules into smaller ones, but that did not seem to have any effect at all.

Any suggestions...?

Thanks,
Dave
#1

15 Replies Related Threads

    MBedder
    Circuit breaker
    • Total Posts : 6841
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 11:55:47 (permalink)
    0
    Switch your compiler's Code Memory Model to Large.
    #2
    funbotix
    Starting Member
    • Total Posts : 57
    • Reward points : 0
    • Joined: 2010/02/18 14:53:57
    • Location: San Antonio, Texas
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 12:10:16 (permalink)
    0
    Thanks.  I tried that, but it had no effect.

    Any other suggestions?
    #3
    MBedder
    Circuit breaker
    • Total Posts : 6841
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 12:16:45 (permalink)
    0
    Which C30 and MPLAB versions are you using? Do you use a custom linker script or just a default one?
    #4
    funbotix
    Starting Member
    • Total Posts : 57
    • Reward points : 0
    • Joined: 2010/02/18 14:53:57
    • Location: San Antonio, Texas
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 12:24:44 (permalink)
    0
    MBLAB IDE v8.43
    MPLAB C30 v3.23
    default linker script
    WinXP Pro with service pack 2
    #5
    cawilkie
    Administrator
    • Total Posts : 1996
    • Reward points : 0
    • Joined: 2003/11/07 12:49:11
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 13:30:15 (permalink)
    0
    That error message doesn't seem to be to do with anything about memory models, just plain ran out of space. Have you tried investigating the MAP file?
    Another tip is to try a larger part (for the link) and see what the memory allocation seems to be on the link... it might give you some clues. If you want to upload your map file and your .gld file, I'm sure that would help....

    Regards
    Calum
    #6
    MBedder
    Circuit breaker
    • Total Posts : 6841
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 13:56:24 (permalink)
    0
    70% of code memory used do not point to lack of code memory.
    #7
    funbotix
    Starting Member
    • Total Posts : 57
    • Reward points : 0
    • Joined: 2010/02/18 14:53:57
    • Location: San Antonio, Texas
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 14:19:56 (permalink)
    0
    Okay... here's the map file after I did a build with the linker errors.

    There is no linker script specified for my project (the "Linker Script" folder in the project tree view is empty).  I've never modified any since installing MPLAB.  Here's the one from Microchip's PIC24H folder.

    Dave
    #8
    aschen0866
    Super Member
    • Total Posts : 4546
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 14:37:45 (permalink)
    0

    ORIGINAL: MBedder

    70% of code memory used do not point to lack of code memory.

    If the linker fails, I doubt the Memory Usage Gauge is any useful at that point.

    ORIGINAL: funbotix

    Okay... here's the map file after I did a build with the linker errors.

    There is no linker script specified for my project (the "Linker Script" folder in the project tree view is empty).  I've never modified any since installing MPLAB.  Here's the one from Microchip's PIC24H folder.

    Dave

    Try to enable Optimization (-Os) setting and see if the problem goes away. Your .map file is incomplete because of the linker error. If you can get the project to build successfully, at least you can see which module takes the most code space. Just a thought.
    #9
    funbotix
    Starting Member
    • Total Posts : 57
    • Reward points : 0
    • Joined: 2010/02/18 14:53:57
    • Location: San Antonio, Texas
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 14:45:48 (permalink)
    0
    I already had the -Os setting for the optimizer.

    Here's a map file after commenting out enough stuff to get a successful build.

    Thanks for all the suggestions and help!

    Dave
    #10
    aschen0866
    Super Member
    • Total Posts : 4546
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 15:05:53 (permalink)
    0

    CodeGuard FLASH Memory:
    boot 0x200 to 0x3ffe
    secure (none)
    general 0x4000 to 0x157fe


    Do you really need such a big boot segment?
    #11
    funbotix
    Starting Member
    • Total Posts : 57
    • Reward points : 0
    • Joined: 2010/02/18 14:53:57
    • Location: San Antonio, Texas
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 15:20:43 (permalink)
    0
    Well, no, not for any reason that I know of.  I've never knowingly modified a linker script file.  Perhaps that can be done somehow via the IDE as a side effect of doing something else?  Perhaps that's done in the default linker script file from Microchip?

    Since there are several linker script files that have the same name as the one I uploaded in an earlier post (taken from the C:\Program Files\Microchip\MPLAB C30\support\PIC24H\gld folder), how do I know which one to look at?  Is that were this big boot segment is probably specified?

    Sorry for all the newbie questions.  This is my 1st PIC24 project.

    #12
    aschen0866
    Super Member
    • Total Posts : 4546
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 15:27:15 (permalink)
    0

    ORIGINAL: funbotix

    Well, no, not for any reason that I know of.  I've never knowingly modified a linker script file.  Perhaps that can be done somehow via the IDE as a side effect of doing something else?  ...

    Yes. Under MPLAB Project --> Build Options --> MPLAB LINK 30, on the Categories pull-down menu, choose Code Guard.
    #13
    funbotix
    Starting Member
    • Total Posts : 57
    • Reward points : 0
    • Joined: 2010/02/18 14:53:57
    • Location: San Antonio, Texas
    • Status: offline
    RE: Link Error: Could not allocate section .text 2010/05/03 18:54:08 (permalink)
    0
    Thanks!

    After looking at the code protect options in the project's linker options and seeing that it was set to off, I did a little web searching and found a document that talked about code guard (which I had never heard of and didn't know anything about).  That led me to the fuse settings at the top of my main.c file.  I changed this line

    _FBS(BWRP_WRPROTECT_OFF & BSS_LARGE_FLASH_STD & RBS_MEDIUM_RAM)

    to this

    _FBS(BWRP_WRPROTECT_OFF & BSS_NO_BOOT_CODE & RBS_NO_BOOT_RAM)

    and my project finally links with all my modules and functions in it!  And, the memory guage jumped up to 86% of the ROM is now being used.  Good thing I've got just a little bit more development to do (and there's lot of debug code I can cut out if I have to).

    Thanks again!!!  There's no telling how long it would've taken me on my own to find out about the code guard feature.
    post edited by funbotix - 2010/05/03 18:59:07
    #14
    sakshi
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2019/11/27 00:14:10
    • Location: 0
    • Status: offline
    Re: RE: Link Error: Could not allocate section .text 2020/03/25 09:31:13 (permalink)
    0
    I was facing the same issue, after several trials of various things, I changed the optimisation to 1 (project properties=> select the compiler (left side) => option categories=> optimisation). It worked for me!!
     
    Thanks!
    #15
    ric
    Super Member
    • Total Posts : 26159
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: RE: Link Error: Could not allocate section .text 2020/03/25 12:39:36 (permalink)
    0
    Note this thread is ten years old.
    Are you really still using C30? That was replaced by XC16 years ago.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #16
    Jump to:
    © 2020 APG vNext Commercial Version 4.5