Recent

Author Topic: [CLOSED] Fatal: No memory left  (Read 1310 times)

julkas

  • Hero Member
  • *****
  • Posts: 523
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
[CLOSED] Fatal: No memory left
« on: December 05, 2019, 01:12:25 pm »
Crosscompiling for Arduino UNO with option -O2 fails with message -
Code: Text  [Select]
  1.  Error: Compilation raised exception internally
  2. Fatal: No memory left
  3.  
Crosscompiling without option -O2 is OK. Any idea ? Thx.
Output from ppcrossavr.exe -i
Code: Text  [Select]
  1. $  ppcrossavr.exe -i
  2. Free Pascal Compiler version 3.3.1
  3.  
  4. Compiler date      : 2019/09/22
  5. Compiler CPU target: avr
  6.  
  7. Supported targets (targets marked with '{*}' are under development):
  8.   embedded: Embedded
  9.  
  10. Supported CPU instruction sets:
  11.   AVR1,AVR2,AVR25,AVR3,AVR31,AVR35,AVR4,AVR5,AVR51,AVR6
  12.  
  13. Supported FPU instruction sets:
  14.   NONE,SOFT,LIBGCC
  15.  
  16. Supported inline assembler modes:
  17.   STANDARD
  18.   GAS
  19.  
  20. Recognized compiler and RTL features:
  21.   HEAP,INITFINAL,RTTI,CLASSES,EXCEPTIONS,EXITCODE,ANSISTRINGS,WIDESTRINGS
  22.   TEXTIO,CONSOLEIO,FILEIO,RANDOM,VARIANTS,OBJECTS,DYNARRAYS,THREADING
  23.   COMMANDARGS,PROCESSES,STACKCHECK,DYNLIBS,SOFTFPU,OBJECTIVEC1,RESOURCES
  24.   UNICODESTRINGS
  25.  
  26. Supported ABI targets:
  27.   DEFAULT
  28.  
  29. Supported Optimizations:
  30.   REGVAR
  31.   STACKFRAME
  32.   PEEPHOLE
  33.   LOOPUNROLL
  34.   TAILREC
  35.   CSE
  36.   DFA
  37.   ORDERFIELDS
  38.   FASTMATH
  39.   REMOVEEMPTYPROCS
  40.   CONSTPROP
  41.   USELOADMODIFYSTORE
  42.  
  43. Supported Whole Program Optimizations:
  44.   All
  45.   DEVIRTCALLS
  46.   OPTVMTS
  47.   SYMBOLLIVENESS
  48.  
  49. Supported Microcontroller types:
  50.   AVRSIM,ATMEGA645,ATMEGA165A,ATTINY44A,ATMEGA649A,ATMEGA32U4,ATTINY26
  51.   AT90USB1287,AT90PWM161,ATTINY48,ATMEGA168P,ATTINY10,ATTINY84A,AT90USB82
  52.   ATTINY2313,ATTINY461,ATMEGA3250PA,ATMEGA3290A,ATMEGA165P,ATTINY43U
  53.   AT90USB162,ATMEGA16U4,ATTINY24A,ATMEGA88P,ATTINY88,ATMEGA6490P,ATTINY40
  54.   ATMEGA324P,ATTINY167,ATMEGA328,ATTINY861,ATTINY85,ATMEGA64M1,ATMEGA645P
  55.   ATMEGA8U2,ATMEGA329A,ATMEGA8A,ATMEGA324PA,ATMEGA32HVB,AT90PWM316
  56.   AT90PWM3B,AT90USB646,ATTINY20,ATMEGA16,ATMEGA48A,ATTINY24,ATMEGA644
  57.   ATMEGA1284,ATA6285,AT90CAN64,ATMEGA48,AT90CAN32,ATTINY9,ATTINY87
  58.   ATMEGA1281,AT90PWM216,ATMEGA3250A,ATMEGA88A,ATMEGA128RFA1,ATMEGA3290PA
  59.   AT90PWM81,ATMEGA325P,ATTINY84,ATMEGA328P,ATTINY13A,ATMEGA8,ATMEGA1284P
  60.   ATMEGA16U2,ATTINY45,ATMEGA3250,ATMEGA329,ATMEGA32A,ATTINY5,AT90CAN128
  61.   ATMEGA6490,ATMEGA8515,ATMEGA88PA,ATMEGA168A,ATMEGA128,AT90USB1286
  62.   ATMEGA164PA,ATTINY828,ATMEGA88,ATMEGA645A,ATMEGA3290P,ATMEGA644P
  63.   ATMEGA164A,ATTINY4313,ATMEGA162,ATMEGA32C1,ATMEGA128A,ATMEGA324A
  64.   ATTINY13,ATMEGA2561,ATMEGA169A,ATTINY261,ATMEGA644A,ATMEGA3290
  65.   ATMEGA64A,ATMEGA169P,ATMEGA2560,ATMEGA32,ATTINY861A,ATTINY28,ATMEGA48P
  66.   ATMEGA8535,ATMEGA168PA,ATMEGA16M1,ATMEGA16HVB,ATMEGA164P,ATMEGA325A
  67.   ATMEGA640,ATMEGA6450,ATMEGA329P,ATA6286,AT90USB647,ATMEGA168
  68.   ATMEGA6490A,ATMEGA32M1,ATMEGA64C1,ATMEGA32U2,ATTINY4,ATMEGA644PA
  69.   AT90PWM1,ATTINY44,ATMEGA325PA,ATMEGA6450A,ATTINY2313A,ATMEGA329PA
  70.   ATTINY461A,ATMEGA6450P,ATMEGA64,ATMEGA165PA,ATMEGA16A,ATMEGA649
  71.   ATMEGA1280,AT90PWM2B,ATMEGA649P,ATMEGA3250P,ATMEGA48PA,ATTINY1634
  72.   ATMEGA325,ATMEGA169PA,ATTINY261A,ATTINY25
  73.  
  74. This program comes under the GNU General Public Licence
  75. For more information read COPYING.v2
  76.  
  77. Please report bugs in our bug tracker on:
  78.                  http://bugs.freepascal.org
  79.  
  80. More information may be found on our WWW pages (including directions
  81. for mailing lists useful for asking questions or discussing potential
  82. new features, etc.):
  83.                  http://www.freepascal.org
« Last Edit: January 19, 2020, 07:25:52 pm by julkas »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

ccrause

  • Full Member
  • ***
  • Posts: 226
Re: Fatal: No memory left
« Reply #1 on: December 05, 2019, 05:10:21 pm »
Is the error generated while cross compiling the compiler, the avr rtl or a user program?

I have tested building the cross compiler for avr5 using the the latest trunk version and don't see an error with default options (-O2) on Linux.

Laksen

  • Hero Member
  • *****
  • Posts: 637
    • J-Software
Re: Fatal: No memory left
« Reply #2 on: December 05, 2019, 05:30:19 pm »
I would advice trying a newer version preferably newest trunk. And if you still see the problem please try to narrow down the issue and share the code that triggers this

julkas

  • Hero Member
  • *****
  • Posts: 523
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: Fatal: No memory left
« Reply #3 on: December 05, 2019, 07:28:13 pm »
Is the error generated while cross compiling the compiler, the avr rtl or a user program?
Error generated while cross compiling my own code (unit). Code works on Raspi and Windows.
I tried remove some features from my code and it cross compiles with optimization switch.
Ma be restrictions on code and data size?
But why compiler is happy without -O2 switch?
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

Laksen

  • Hero Member
  • *****
  • Posts: 637
    • J-Software
Re: Fatal: No memory left
« Reply #4 on: December 05, 2019, 07:57:40 pm »
It could be an optimizer problem causing a stack overrun

julkas

  • Hero Member
  • *****
  • Posts: 523
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: Fatal: No memory left
« Reply #5 on: December 05, 2019, 08:27:46 pm »
It could be an optimizer problem causing a stack overrun
Please, explain.
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

ccrause

  • Full Member
  • ***
  • Posts: 226
Re: Fatal: No memory left
« Reply #6 on: December 06, 2019, 06:35:46 am »
Ma be restrictions on code and data size?
No.  The linker will report an error if the generated code or data doesn't fit on the target controller.

Quote
But why compiler is happy without -O2 switch?
Depending on optimization settings different code paths are followed in the compiler, and also different code gets generated.

My guess (since you haven't showed code that causes this problem) is that it could be a problem in the register allocator (https://bugs.freepascal.org/view.php?id=36242).

julkas

  • Hero Member
  • *****
  • Posts: 523
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: Fatal: No memory left
« Reply #7 on: December 06, 2019, 11:24:38 am »
Ma be restrictions on code and data size?
No.  The linker will report an error if the generated code or data doesn't fit on the target controller.

Quote
But why compiler is happy without -O2 switch?
Depending on optimization settings different code paths are followed in the compiler, and also different code gets generated.

My guess (since you haven't showed code that causes this problem) is that it could be a problem in the register allocator (https://bugs.freepascal.org/view.php?id=36242).

Thanks, Christo.
I think black hole is here -
Code: Pascal  [Select]
  1. cs := byte((fs.fptr div 512) and (fs.csize - 1));

if I change it to
Code: Pascal  [Select]
  1. cs := byte((fs.fptr div 512) and (fs.csize));
or
Code: Pascal  [Select]
  1. cs := byte((fs.fptr div 512) and byte(fs.csize - 1));
I can compile with -O2 / -O3 options.

But if I change it to
Code: Pascal  [Select]
  1. cs := byte((fs.fptr div 512) and (fs.csize - 0));
compiler gives -
Code: Text  [Select]
  1.  Fatal: Internal error 200309041.

May be my compiler is outdated.
I will update to latest trunk.

« Last Edit: December 06, 2019, 11:27:35 am by julkas »
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

julkas

  • Hero Member
  • *****
  • Posts: 523
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: Fatal: No memory left
« Reply #8 on: December 06, 2019, 07:27:26 pm »
Great. (X) and (X-0) - different fruits!
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

ccrause

  • Full Member
  • ***
  • Posts: 226
Re: Fatal: No memory left
« Reply #9 on: December 06, 2019, 07:59:17 pm »
Quote
Fatal: Internal error 200309041.
This error originates from do_register_allocation.

Great. (X) and (X-0) - different fruits!
That bit of code is not enough to duplicate your problem.  Please provide code for a simple project that demonstrates your problem, with all the options passed to the compiler.

julkas

  • Hero Member
  • *****
  • Posts: 523
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: Fatal: No memory left
« Reply #10 on: December 06, 2019, 08:43:54 pm »
Christo, I will give you link to the project.
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

julkas

  • Hero Member
  • *****
  • Posts: 523
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: Fatal: No memory left
« Reply #11 on: December 07, 2019, 12:06:05 pm »
Christo, you can download project from https://github.com/JulStrat/pff/tree/master/source/fpc

Try compile pff.pas unit with AVR crosscompiler (my target Arduino UNO R3) . Options -
-Tembedded -Cpavr5 -Wpatmega328p -va
Must be OK.

Next, add option -O2.
My output -
Code: Text  [Select]
  1. [10.592] pff.pas(1528,1) Error: Compilation raised exception internally
  2. [10.592] pff.pas(1528,1)  ENDIF PF_USE_WRITE found
  3. [10.608] Fatal: No memory left
  4.  

Now, change line 1478 in pff.pas to
Code: Pascal  [Select]
  1. cs := byte((fs.fptr div 512) and (fs.csize - 0));
My output -
Code: Text  [Select]
  1. [0.156] pff.pas(1528,1) Fatal: Internal error 200309041
  2. [0.156] pff.pas(1528,1)  ENDIF PF_USE_WRITE found
  3. [0.156] Fatal: Compilation aborted
  4.  

Next, change same line to
Code: Pascal  [Select]
  1.       cs := byte((fs.fptr div 512) and byte(fs.csize - 1));

My output -
Code: Text  [Select]
  1. [0.281] (PFF)      Finished compiling unit PFF
  2. [0.281] 1609 lines compiled, 0.3 sec
  3. [0.281] 1 warning(s) issued
  4. [0.281] 4 hint(s) issued
  5.  

P.S. I have tested my crosscompiler with sample Arduino projects (Blink, UART).
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

ccrause

  • Full Member
  • ***
  • Posts: 226
Re: Fatal: No memory left
« Reply #12 on: December 07, 2019, 06:04:32 pm »
Christo, you can download project from https://github.com/JulStrat/pff/tree/master/source/fpc

Error confirmed:
Code: Text  [Select]
  1. ~/fpc/3.3.1/compiler/ppcrossavr -g -l -vwn -n @~/fpc/3.3.1/fpc.cfg  -Wpatmega328p tmpl.pas -O2
  2. Free Pascal Compiler version 3.3.1 [2019/12/05] for avr
  3. Copyright (c) 1993-2019 by Florian Klaempfl and others
  4. Target OS: Embedded
  5. Compiling tmpl.pas
  6. Compiling pff.pas
  7. User defined: ASCII upper case character only
  8. User defined: ENDIAN_LITTLE
  9. pff.pas(1270,12) Warning: Local variable "sp" does not seem to be initialized
  10. pff.pas(1528,1) Fatal: Internal error 200309041
  11. Fatal: Compilation aborted

I'll add a reference to this discussion in the existing bug report.

julkas

  • Hero Member
  • *****
  • Posts: 523
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: Fatal: No memory left
« Reply #13 on: December 08, 2019, 08:21:28 pm »
Christo, thanks. I will try -sr with -a... also.
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;

julkas

  • Hero Member
  • *****
  • Posts: 523
  • KISS principle / Lazarus 2.0.6 / FPC 3.0.4
Re: Fatal: No memory left
« Reply #14 on: January 06, 2020, 11:37:51 am »
Any changes, updates on https://bugs.freepascal.org/view.php?id=36242 ?
Code: Text  [Select]
  1. Fatal: Internal error 200309041
procedure mulu64(a, b: QWORD; out clo, chi: QWORD); assembler;
asm
  mov rax, a
  mov rdx, b
  mul rdx
  mov [clo], rax
  mov [chi], rdx
end;