C30 link works but XC16 link fails (Could not allocate secti

This forum handles questions and discussions concerning Microchip’s 16-bit compilers, assemblers, linkers and related tools.

C30 link works but XC16 link fails (Could not allocate secti

Postby tolf » Sun Mar 07, 2021 10:18 pm

Hi PicForum - found it impossible to post this at Microchip ... hopefully more success here ...

Having serious problems linking and existing C30 project using XC16.

Environment being used is MPLAB-X v5.45, C30 toolchain (v3.31), XC16 toolchain (v1.61) - device PIC24EP512GU810

Project builds without issues using C30 compiler (original dev environment) - migrating to XC16 has thrown up a large list of errors indicating flash sections cannot be allocated (.const, .text) - no errors for other RAM data sections.

build/default/production/T1.o: Link Error: Could not allocate section .const, size = 20480 PC units, attributes = psv page
build/default/production/T1UI.o: Link Error: Could not allocate section .text, size = 20068 PC units, attributes = code
build/default/production/usb_host_custom_for_T1.o: Link Error: Could not allocate section .text, size = 11022 PC units, attributes = code
build/default/production/T1Display.o: Link Error: Could not allocate section .text, size = 7414 PC units, attributes = code
build/default/production/T1SQ.o: Link Error: Could not allocate section .text, size = 7136 PC units, attributes = code
build/default/production/_ext/1726182412/usb_host_msd.o: Link Error: Could not allocate section .text, size = 5374 PC units, attributes = code



..... continues in similar vein for every project file and library function ...



This would suggest that (flash) memory limit is exceeded BUT the code compiles and runs (both production and debug) when built with C30. The only XC16 conditional directives used are as follows (directives in USB library source files are always C30 || XC16 so should have no impact)



#ifdef XC16
#include <xc.h>
#include <generic.h>
#else
#include "p24ep512gu810.h"
#include "GenericTypeDefs.h"
#endif

so nothing much different in the XC16 includes.



C30 map shows flash allocation as



Program Memory [Origin = 0x200, Length = 0x55600]

section address length (PC units) length (bytes) (dec)
------- ------- ----------------- --------------------
.text 0x200 0x1b38 0x28d4 (10452)
.text 0x1d38 0x60aa 0x90ff (37119)
.text 0x7de2 0x200 0x300 (768)
.text 0x7fe2 0xa 0xf (15)
.const 0x8000 0x7fd2 0xbfbb (49083)
.text 0xffd2 0x7942 0xb5e3 (46563)
.text 0x17914 0x1608a 0x210cf (135375)
.icon 0x2d99e 0xafc 0x107a (4218)
.text 0x2e49a 0x39f0 0x56e8 (22248)
.text 0x31e8a 0x1d6 0x2c1 (705)ch
.dinit 0x32060 0x186 0x249 (585)
.text 0x321e6 0x25e 0x38d (909)

Total program memory used (bytes): 0x4b348 (308040) 58%




XC16 obviously doesn't produce a complete map but the list of files / libraries included looks similar apart from a couple of extra search directories (PIC24E seems to make sense given the part)



-LC:/Program Files/Microchip/MPLABX/v5.45/packs/Microchip/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/bin/../support/PIC24E/gld \
-LC:/Program Files/Microchip/MPLABX/v5.45/packs/Microchip/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16/bin/../support/dsPIC33E/gld \


XC16 link command line is (I've removed the list of object files for legibility)



"C:\Program Files\Microchip\xc16\v1.61\bin\xc16-gcc.exe" -o (OBJECT FILE LIST REMOVED) -mcpu=24EP512GU810 -omf=coff -DXPRJ_default=default -legacy-libc -I"." -I"../../Microchip/Include" -I"../../Microchip/MDD File System" -I"../../Microchip/USB" -Wl,--local-stack,,--defsym=__MPLAB_BUILD=1,,--script=p24EP512GU810.gld,--heap=1000,--stack=16,--check-sections,--data-init,--no-pack-data,--no-handles,--isr,--no-gc-sections,--fill-upper=0,--stackguard=16,--no-force-link,--smart-io,-Map="dist/default/production/Firmware.production.map",--report-mem,--memorysummary,dist/default/production/memoryfile.xml -mdfp="C:/Program Files/Microchip/MPLABX/v5.45/packs/Microchip/dsPIC33E-GM-GP-MC-GU-MU_DFP/1.3.85/xc16"

C30 link command line (again object file list removed for legibility)



"C:\Program Files (x86)\Microchip\MPLAB C30\bin\pic30-gcc.exe" -omf=coff -mcpu=24EP512GU810 -o (OBJECT FILE LIST REMOVED) -legacy-libc -Wl,--defsym=__MPLAB_BUILD=1,--heap=1000,-Map="dist/PIC30/production/Firmware.production.map",-Tp24EP512GU810.gld



so nothing particularly odd as far as I can see. I'm using a modestly sized buffer in EDS (9600 bytes) which has worked fine under C30 (and I can't see why there'd be any conflict between that and program / constant sections anyway - data memory usage is about 67% and should be entirely separate). All source files compile fine and memory model is large (code / data), scalar model is default, location of constants is code space ... anyone ever run into this before ? I've spent a lot of time trying to sort this out with no success so far ... any input greatly appreciated.



Cheers



tolf
tolf
 
Posts: 2
Joined: Sun Mar 07, 2021 10:05 pm
PIC experience: Professional 5+ years with MCHP products

Re: C30 link works but XC16 link fails (Could not allocate s

Postby AussieSusan » Tue Mar 09, 2021 2:58 am

Wild guess - do C30 and XC16 have the same defaults for variable sizes. I know that C30 defaults 'double' to the same size as 'float' - not sure what XC16 does - but that would double the size of the memory required for floating point variables.
Also check default section alignment and the like.
Susan
AussieSusan
Verified identity
 
Posts: 147
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: C30 link works but XC16 link fails (Could not allocate s

Postby tolf » Tue Mar 09, 2021 6:15 pm

Thaks Susan ... useful suggestions but the constants that seem to be causing the problems are all char / char* / int (I don't use any non-auto doubles or floats and have only a minimal number in the project (5 in total)) - looking at the documentation for both compilers they do apparently occupy the same amounts of space (pretty fundamental really but by this stage everything is worth checking).

I can't see aything odd about the sections - I have a single specifically named data section which should have no effect (and in fact if I take that section attribute out it has no effect - it's more of an organisational reminder than a neccesity) and everything else is simply linker defaults which don't seem to be particularly outlandish.

But as I say, at this stage, any and all input appreciated

Cheers

Dave
tolf
 
Posts: 2
Joined: Sun Mar 07, 2021 10:05 pm
PIC experience: Professional 5+ years with MCHP products


Return to MPLAB XC16

Who is online

Users browsing this forum: No registered users and 1 guest