Another .fpc* section problem for AVR
## Summary After commit 8f7e61ee the .fpc data is not loaded into the binary image, however the linker still adds the .fpc data size to the .data section total, giving an error if the total .data + .fpc size exceed the controller memory limit, even if the actual .data size fits. ## System Information - **Operating system:** Embedded - **Processor architecture:** AVR - **Compiler version:** 3.3.1 - **Device:** Microcontroller ## Example Project ``` program test; var buf: array[0..2047] of byte; begin buf[0] := 1; end. ``` ## What is the current bug behavior? Compile example program for atmega328p: ``` $ ~/fpc/gitlab/compiler/avr/pp -n @~/fpc/gitlab/fpc.cfg -Wpatmega328p test.pp Free Pascal Compiler version 3.3.1 [2023/02/20] for avr Copyright (c) 1993-2023 by Florian Klaempfl and others Target OS: Embedded Compiling test.pp test.pp(4,3) Note: Local variable "buf" is assigned but never used Assembling test Linking test /usr/bin/avr-ld: test.elf section `.fpc' will not fit in region `data' test.pp(10) Error: Error while linking test.pp(10) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted ``` It appears that the linker counts the .fpc section as part of the .data section because it is marked as ALLOC. ## What is the expected (correct) behavior? The _buf_ variable should fit inside the RAM of an atmega328p controller, which has 2048 bytes of RAM. ## Possible fixes Mapping the .fpc section to a custom memory region avoids the linker counting the .fpc information as part of .data: ``` diff --git a/compiler/systems/t_embed.pas b/compiler/systems/t_embed.pas index 79e87f61d7..983fad794a 100644 --- a/compiler/systems/t_embed.pas +++ b/compiler/systems/t_embed.pas @@ -974,6 +974,7 @@ procedure TlinkerEmbedded.SetDefaultInfo; Add(' fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K'); Add(' lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K'); Add(' signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K'); + Add(' fpcinfo : ORIGIN = 0xFF0000, LENGTH = 1K'); Add('}'); Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';'); end; @@ -1197,7 +1198,8 @@ procedure TlinkerEmbedded.SetDefaultInfo; Add(' /* DWARF Extension. */'); Add(' .debug_macro 0 : { *(.debug_macro) }'); Add(' .debug_addr 0 : { *(.debug_addr) }'); - Add(' .fpc (NOLOAD) : { KEEP (*(.fpc .fpc.n_version .fpc.n_links)) }'); + Add(' .fpc (NOLOAD) : { KEEP (*(.fpc .fpc.n_version .fpc.n_links)) } > fpcinfo'); Add('}'); end; {$endif AVR} ```
issue