Lazarus

Programming => Operating Systems => Embedded => Topic started by: electronickiwi on May 09, 2020, 06:39:55 am

Title: Problem linking for Xtensa (ESP32)
Post by: electronickiwi on May 09, 2020, 06:39:55 am
I've been following the instructions at https://wiki.lazarus.freepascal.org/Xtensa, and getting stuck at compiling a test program.

I've got the following error message coming up when I try and do the cross-compile for xtensa-freertos. (I'm running on Windows)

Code: Text  [Select][+][-]
  1. helloworld.pp(8,17) Error: Can't call the linker, switching to external linking
  2. helloworld.pp(8,17) Error: Error while linking
  3. helloworld.pp(8,17) Fatal: There were 2 errors compiling module, stopping
  4. Fatal: Compilation aborted
  5.  

I'm running the following command, adapted from the command in the wiki
Code: Text  [Select][+][-]
  1. C:\lazarus\fpc\fpc>compiler\ppcrossxtensa -Furtl\units\xtensa-freertos\ -Tfreertos -XPxtensa-esp32-elf- -O3 -Wpesp32 -FlC:\Users\Wes\esp\xtensa-esp32-elf-libs  -FlC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\ helloworld

I can run the command
Code: Text  [Select][+][-]
  1. C:\lazarus\fpc\fpc>xtensa-esp32-elf-ld
and I get
Code: Text  [Select][+][-]
  1. xtensa-esp32-elf-ld: no input files
, which I think means that the appropriate binutils are on my path.

Any ideas?

Wes
Title: Re: Problem linking for Xtensa (ESP32)
Post by: TRon on May 09, 2020, 07:23:20 am
Quote
helloworld.pp(8,17) Error: Can't call the linker, switching to external linking
That msg seems to suggest that you haven't setup your configuration for crosscompiling correctly

Quote
helloworld.pp(8,17) Error: Error while linking
That msg seems to suggest that fpc is unable to locate your linker. That is also configuration related.

edit: So, were is your fpc.cfg ?  ;D
Sorry, i overlooked the fact that you are invoking the crosscompiler directly  :-[ (2x fpc in there )

By default there is a define named NEEDCROSSBINUTILS, which adds a prefix to the name of the binutil it wants to invoke:
<redundancy removed>
Does the name then still match ?


You can add the option -vt to your parameters for compilation (which results in more output from the compiler) in order to see what linker FPC is looking for and if FPC is able to find it. The -vt option actually outputs information on every file FPC attempts to locate.

Furthermore you can use the option -FD (inside your configuration file as well) to add the path to your binutils , which makes it redundant to add this path to your path environment variable.
Title: Re: Problem linking for Xtensa (ESP32)
Post by: ccrause on May 09, 2020, 09:24:42 am
You can add the option -vt to your parameters for compilation (which results in more output from the compiler) in order to see what linker FPC is looking for and if FPC is able to find it. The -vt option actually outputs information on every file FPC attempts to locate.
+1.  Difficult to troubleshoot if you don't know exactly what the compiler was looking for and where.

Since you didn't specify the binutils prefix, the compiler may have assumed a different prefix (such as xtensa-freertos-). You can also set the prefix to the binutils explicitly with the -XP option. You can also use -XP to specify the path+prefix, I guess on your installation it will be something along the lines of:
Code: Text  [Select][+][-]
  1. -XPC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf/bin/xtensa-esp32-elf-
EDIT: probably qualifies for the WoMM (https://blog.codinghorror.com/the-works-on-my-machine-certification-program/) certification  :-[.

Quote
Furthermore you can use the option -FD (inside your configuration file as well) to add the path to your binutils , which makes it redundant to add this path to your path environment variable.
This option sets the path to compiler utils, not binutils.
EDIT: As others pointed out this is incorrect!
Title: Re: Problem linking for Xtensa (ESP32)
Post by: marcov on May 09, 2020, 10:04:04 am
XP is only for the prefix. Paths to binutils should be set with -FD
Title: Re: Problem linking for Xtensa (ESP32)
Post by: PascalDragon on May 09, 2020, 10:06:31 am
You can add the option -vt to your parameters for compilation (which results in more output from the compiler) in order to see what linker FPC is looking for and if FPC is able to find it. The -vt option actually outputs information on every file FPC attempts to locate.
+1.  Difficult to troubleshoot if you don't know exactly what the compiler was looking for and where.

Since you didn't specify the binutils prefix, the compiler may have assumed a different prefix (such as xtensa-freertos-). You can also set the prefix to the binutils explicitly with the -XP option. You can also use -XP to specify the path+prefix, I guess on your installation it will be something along the lines of:
Code: Text  [Select][+][-]
  1. -XPC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf/bin/xtensa-esp32-elf-

Quote
Furthermore you can use the option -FD (inside your configuration file as well) to add the path to your binutils , which makes it redundant to add this path to your path environment variable.
This option sets the path to compiler utils, not binutils.

You're wrong. -FD is the path to the binutils, while -XP is only the filename's prefix.
Title: Re: Problem linking for Xtensa (ESP32)
Post by: electronickiwi on May 09, 2020, 10:20:12 am
Thank you all for your input.  The -XP option was being used, but only the prefix, not the full path.  I've put in the full path to the bin utils, both as -XP and -FD and get the same error each time.

I'm now running this command:
Code: Text  [Select][+][-]
  1. C:\lazarus\fpc\fpc>compiler\ppcrossxtensa -vt -Furtl\units\xtensa-freertos\ -Tfreertos -XPC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf- -O3 -Wpesp32 -FlC:\Users\Wes\esp\xtensa-esp32-elf-libs  -FlC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\ helloworld

or this one:
Code: Text  [Select][+][-]
  1. compiler\ppcrossxtensa -vt -Furtl\units\xtensa-freertos\ -Tfreertos -FDC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf\bin\ -XPxtensa-esp32-elf- -O3 -Wpesp32 -FlC:\Users\Wes\esp\xtensa-esp32-elf-libs  -FlC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\ helloworld

and getting this result.  I can see it looks for and finds the assembler, but I don't see any messages about looking for the linker and not finding it, only that it can't call the (internal?) linker, and switches to the external linker, which has an error.

Code: Text  [Select][+][-]
  1. Configfile search: fpc.cfg
  2. Configfile search: C:\Users\Wes\fpc.cfg
  3. Configfile search: C:\ProgramData\fpc.cfg
  4. Configfile search: C:\lazarus\fpc\fpc\compiler\fpc.cfg
  5. Path ".\::=::\" not found
  6. Path ".\rtl\xtensa-freertos\" not found
  7. Compiler: C:\lazarus\fpc\fpc\compiler\ppcrossxtensa.exe
  8. Using executable path: C:\lazarus\fpc\fpc\compiler\
  9. Using unit path: .\rtl\units\xtensa-freertos\
  10. Using unit path: .\compiler\
  11. Using library path: C:\Users\Wes\esp\xtensa-esp32-elf-libs\
  12. Using library path: C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\
  13. Using library path: .\rtl\units\xtensa-freertos\
  14. Using library path: .\compiler\
  15. Using object path: .\rtl\units\xtensa-freertos\
  16. Using object path: .\compiler\
  17. Searching file helloworld.pp... found
  18. Unitsearch: system.ppu
  19. Unitsearch: system.pp
  20. Unitsearch: system.pas
  21. Unitsearch: .\rtl\units\xtensa-freertos\system.ppu
  22. PPU Loading .\rtl\units\xtensa-freertos\system.ppu
  23. Searching file helloworld.pp... found
  24. Searching file helloworld.pp... found
  25. Unitsearch: ESP32.ppu
  26. Unitsearch: ESP32.pp
  27. Unitsearch: ESP32.pas
  28. Unitsearch: .\rtl\units\xtensa-freertos\ESP32.ppu
  29. PPU Loading .\rtl\units\xtensa-freertos\esp32.ppu
  30. Unitsearch: consoleio.ppu
  31. Unitsearch: consoleio.pp
  32. Unitsearch: consoleio.pas
  33. Unitsearch: .\rtl\units\xtensa-freertos\consoleio.ppu
  34. PPU Loading .\rtl\units\xtensa-freertos\consoleio.ppu
  35. Unitsearch: heapmgr.ppu
  36. Unitsearch: heapmgr.pp
  37. Unitsearch: heapmgr.pas
  38. Unitsearch: .\rtl\units\xtensa-freertos\heapmgr.ppu
  39. PPU Loading .\rtl\units\xtensa-freertos\heapmgr.ppu
  40. Searching file helloworld.pp... found
  41. Searching file C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-as.exe... found
  42. Using assembler: C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-as.exe
  43. Searching file helloworld.o... found
  44. Searching file .\rtl\units\xtensa-freertos\system.o... found
  45. Searching file .\rtl\units\xtensa-freertos\esp32.o... found
  46. Searching file libesp32.a... not found
  47. Searching file libesp32.a... not found
  48. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp32.a... found
  49. Searching file libsoc.a... not found
  50. Searching file libsoc.a... not found
  51. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libsoc.a... found
  52. Searching file libdriver.a... not found
  53. Searching file libdriver.a... not found
  54. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libdriver.a... found
  55. Searching file libfreertos.a... not found
  56. Searching file libfreertos.a... not found
  57. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libfreertos.a... found
  58. Searching file liblog.a... not found
  59. Searching file liblog.a... not found
  60. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\liblog.a... found
  61. Searching file libesp_common.a... not found
  62. Searching file libesp_common.a... not found
  63. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_common.a... found
  64. Searching file libheap.a... not found
  65. Searching file libheap.a... not found
  66. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libheap.a... found
  67. Searching file libnewlib.a... not found
  68. Searching file libnewlib.a... not found
  69. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libnewlib.a... found
  70. Searching file libvfs.a... not found
  71. Searching file libvfs.a... not found
  72. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libvfs.a... found
  73. Searching file libesp_ringbuf.a... not found
  74. Searching file libesp_ringbuf.a... not found
  75. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_ringbuf.a... found
  76. Searching file libspi_flash.a... not found
  77. Searching file libspi_flash.a... not found
  78. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libspi_flash.a... found
  79. Searching file libapp_update.a... not found
  80. Searching file libapp_update.a... not found
  81. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libapp_update.a... found
  82. Searching file libxtensa.a... not found
  83. Searching file libxtensa.a... not found
  84. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libxtensa.a... found
  85. Searching file libbootloader_support.a... not found
  86. Searching file libbootloader_support.a... not found
  87. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libbootloader_support.a... found
  88. Searching file libpthread.a... not found
  89. Searching file libpthread.a... not found
  90. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libpthread.a... found
  91. Searching file libhal.a... not found
  92. Searching file libhal.a... not found
  93. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libhal.a... found
  94. Searching file libm.a... not found
  95. Searching file libm.a... not found
  96. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libm.a... found
  97. Searching file libg.a... not found
  98. Searching file libg.a... not found
  99. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libg.a... found
  100. Searching file libc.a... not found
  101. Searching file libc.a... not found
  102. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libc.a... found
  103. Searching file libesp_event.a... not found
  104. Searching file libesp_event.a... not found
  105. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_event.a... found
  106. Searching file .\rtl\units\xtensa-freertos\consoleio.o... found
  107. Searching file .\rtl\units\xtensa-freertos\heapmgr.o... found
  108. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp32.a... found
  109. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libsoc.a... found
  110. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libdriver.a... found
  111. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libfreertos.a... found
  112. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\liblog.a... found
  113. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_common.a... found
  114. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libheap.a... found
  115. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libnewlib.a... found
  116. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libvfs.a... found
  117. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_ringbuf.a... found
  118. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libspi_flash.a... found
  119. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libapp_update.a... found
  120. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libxtensa.a... found
  121. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libbootloader_support.a... found
  122. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libpthread.a... found
  123. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libhal.a... found
  124. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libm.a... found
  125. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libg.a... found
  126. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libc.a... found
  127. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_event.a... found
  128. helloworld.pp(3,24) Error: Can't call the linker, switching to external linking
  129. helloworld.pp(3,24) Error: Error while linking
  130. Searching file helloworld.o... found
  131. Searching file helloworld.o... found
  132. Searching file .\rtl\units\xtensa-freertos\system.o... found
  133. Searching file .\rtl\units\xtensa-freertos\system.o... found
  134. Searching file .\rtl\units\xtensa-freertos\esp32.o... found
  135. Searching file .\rtl\units\xtensa-freertos\esp32.o... found
  136. Searching file .\rtl\units\xtensa-freertos\consoleio.o... found
  137. Searching file .\rtl\units\xtensa-freertos\consoleio.o... found
  138. Searching file .\rtl\units\xtensa-freertos\heapmgr.o... found
  139. Searching file .\rtl\units\xtensa-freertos\heapmgr.o... found
  140. helloworld.pp(3,24) Fatal: There were 2 errors compiling module, stopping
  141. Fatal: Compilation aborted

Contents of helloworld.pp
Code: Pascal  [Select][+][-]
  1. program helloworld;
  2. begin
  3.   writeln('Hello World');
  4. end.

I've noticed a linkXXX.res file is created.  It's contents are:
Code: Text  [Select][+][-]
  1. SEARCH_DIR("C:\Users\Wes\esp\xtensa-esp32-elf-libs\")
  2. SEARCH_DIR("C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\")
  3. SEARCH_DIR(".\rtl\units\xtensa-freertos\")
  4. SEARCH_DIR(".\compiler\")
  5. INPUT (
  6. helloworld.o
  7. .\rtl\units\xtensa-freertos\system.o
  8. .\rtl\units\xtensa-freertos\esp32.o
  9. .\rtl\units\xtensa-freertos\consoleio.o
  10. .\rtl\units\xtensa-freertos\heapmgr.o
  11. )
  12. GROUP(
  13. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp32.a
  14. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libsoc.a
  15. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libdriver.a
  16. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libfreertos.a
  17. C:\Users\Wes\esp\xtensa-esp32-elf-libs\liblog.a
  18. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_common.a
  19. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libheap.a
  20. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libnewlib.a
  21. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libvfs.a
  22. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_ringbuf.a
  23. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libspi_flash.a
  24. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libapp_update.a
  25. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libxtensa.a
  26. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libbootloader_support.a
  27. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libpthread.a
  28. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libhal.a
  29. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libm.a
  30. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libg.a
  31. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libc.a
  32. C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_event.a
  33. )
  34. SECTIONS
  35. {
  36.   .data :
  37.   {
  38.     KEEP (*(.fpc .fpc.n_version .fpc.n_links))
  39.   }
  40. }
Title: Re: Problem linking for Xtensa (ESP32)
Post by: MiR on May 09, 2020, 10:24:52 am
One more thing to do is to add -sh parameter to build, this way a linker script will be generated and you see step by step what is happening (and going wrong) in the linker phase.

In the past (when I remember correctly) parts of the steps done to link were unix specific, perhaps some detail still needs to be fixed for running on windows.
Title: Re: Problem linking for Xtensa (ESP32)
Post by: marcov on May 09, 2020, 11:03:02 am
This option sets the path to compiler utils, not binutils.

Compiler utils are anything that the compiler calls. Binutils included.
Title: Re: Problem linking for Xtensa (ESP32)
Post by: TRon on May 09, 2020, 11:29:25 am
and getting this result.  I can see it looks for and finds the assembler,
Indeed it searhes for and finds the assembler correctly.

Quote
but I don't see any messages about looking for the linker and not finding it,
That is the part that is concerning. After the assembly, when it processed all required files to do so, it should invoke the linker

It does so in a similar fashion as the assembler. Searching for it, finding it, then invoking it.

That last part is indeed missing from your log.

Quote
only that it can't call the (internal?) linker, and switches to the external linker, which has an error.
That it tries the internal linker first should afaik not happen.

You could perhaps try to 'override' internal linking with providing the compiler option -Xe (Use external linker)

Another thing that might perhaps help is to try to avoid to optimize (so get rid of the option -O3).

Other than that i have no idea atm. I am unfamiliar with the target, so have no idea on particular ins and/or outs and with regards to my knowledge regarding the backend i'm out of idea's.

Oh, perhaps one thing (but as said i am unfamiliar with this particular toolchain) you could perhaps try and pass some (debug) options through to the linker (which ones those should be i have no idea. You could try to invoke the linker with --help or /help and see if there are any meaningful options you could perhaps pass along at linking stage.

I did read something with regards to this toolchain about setting environment variables ?

Title: Re: Problem linking for Xtensa (ESP32)
Post by: electronickiwi on May 09, 2020, 11:39:02 am
When I run with the -sh option it produces the ppas.bat script:
Code: Text  [Select][+][-]
  1. @echo off
  2. SET THEFILE=helloworld
  3. echo Assembling %THEFILE%
  4. C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-as.exe -o helloworld.o  helloworld.s --longcalls
  5. if errorlevel 1 goto asmend
  6. Del helloworld.s
  7. SET THEFILE=helloworld
  8. echo Linking %THEFILE%
  9. xtensa-esp32-elf-gcc -C -P -x c -E -o esp32_out.ld -I . C:\Users\Wes\esp\esp-idf/components/esp32/ld/esp32.ld
  10. if errorlevel 1 goto linkend
  11. SET THEFILE=helloworld
  12. echo Linking %THEFILE%
  13. C:\Users\Wes\esp\esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 elf2image --flash_mode dio --flash_freq 40m --flash_size 2MB --elf-sha256-offset 0xb0 -o helloworld.bin helloworld.elf
  14. if errorlevel 1 goto linkend
  15. goto end
  16. :asmend
  17. echo An error occurred while assembling %THEFILE%
  18. goto end
  19. :linkend
  20. echo An error occurred while linking %THEFILE%
  21. :end
  22.  

Running that script produces:
Code: Text  [Select][+][-]
  1. Assembling helloworld
  2. Linking helloworld
  3. Linking helloworld
  4. esptool.py v3.0-dev
  5. Traceback (most recent call last):
  6.   File "C:\Users\Wes\esp\esp-idf\components\esptool_py\esptool\esptool.py", line 3430, in <module>
  7.     _main()
  8.   File "C:\Users\Wes\esp\esp-idf\components\esptool_py\esptool\esptool.py", line 3423, in _main
  9.     main()
  10.   File "C:\Users\Wes\esp\esp-idf\components\esptool_py\esptool\esptool.py", line 3163, in main
  11.     operation_func(args)
  12.   File "C:\Users\Wes\esp\esp-idf\components\esptool_py\esptool\esptool.py", line 2633, in elf2image
  13.     e = ELFFile(args.input)
  14.   File "C:\Users\Wes\esp\esp-idf\components\esptool_py\esptool\esptool.py", line 2108, in __init__
  15.     with open(self.name, 'rb') as f:
  16. FileNotFoundError: [Errno 2] No such file or directory: 'helloworld.elf'
  17. An error occurred while linking helloworld

gcc is producing the expected esp32_out.ld file, but there is no helloworld.elf for esptool.py to produce the helloworld.bin from.


Title: Re: Problem linking for Xtensa (ESP32)
Post by: electronickiwi on May 09, 2020, 11:45:08 am
No change using the -Xe option and leaving out the -O3 option.
It still says "Can't call the linker, switching to external linker"

I'm assuming I only need to put -Xe and not include the path to the linker (as that is specified in -FD option)?
Title: Re: Problem linking for Xtensa (ESP32)
Post by: TRon on May 09, 2020, 11:54:39 am
No change using the -Xe option and leaving out the -O3 option.
Ok, thank for trying and reporting back.

I noticed that you posted pretty quick after my post, and the script more or less already explained that the issue is not related to optimising.

Quote
It still says "Can't call the linker, switching to external linker"
Sorry to hear that. I have to surrender here. Hopefully one of the more experienced developers or the maintainer of this particular target reads this and is able to help you out here.

Perhaps worth a report in the mantis bug-tracker to draw some more attention to it ?

Quote
I'm assuming I only need to put -Xe and not include the path to the linker (as that is specified in -FD option)?
That is correct.

You can try though. FPC will respectfully throw that back in your face with an error  :D
Title: Re: Problem linking for Xtensa (ESP32)
Post by: electronickiwi on May 09, 2020, 11:59:41 am
Thanks TRon.
Title: Re: Problem linking for Xtensa (ESP32)
Post by: TRon on May 09, 2020, 12:55:37 pm
EDIT: As others pointed out this is incorrect!
Nevertheless, your input is very much appreciated.

You are most probably correct in that i should not have named it literally "to add the path to your binutils", which perhaps suggested that the -FD option is meant only for pointing to binutils.

You are able to 'abuse' that option to add about every path that has at least some meaning for the toolchain, so that FPC is able to actually set things in such motion that an executable (or other kind of output) is constructed.

As pointed out by others (thank you others), binutils is a chain of tools (hence toolchain) that is/becomes part of the compiler utilities (although originating from external sources).

For most generic targets ld, as and others like strip are pretty common, but there are some pretty unorthodox targets out there (that are supported by FPC as well) and which require FPC to (indirectly) invoke a complete set of (exotic) tools in order to produce something useful.

Quote
...
Code: Text  [Select][+][-]
  1. -XPC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2020r1-8.2.0\xtensa-esp32-elf/bin/xtensa-esp32-elf-
EDIT: probably qualifies for the WoMM (https://blog.codinghorror.com/the-works-on-my-machine-certification-program/) certification  :-[.
... and that is perhaps one of such toolchains that installs itself (automatically) in such WoMM manner  ;)

Another example is for instance Android with it's .apk files (which is very convenient when the toolchain is able to produce that automatically for you).

On top of that, such (wonderful) options allows for a complete standalone (independent from OS) setup for FPC. You can just toss every native + cross compiler versions onto a (big) flash-drive and you never have to worry about installing things again (that is until the next release from FPC/Lazarus team of course .. those blimey releases  :D ).
Title: Re: Problem linking for Xtensa (ESP32)
Post by: marcov on May 09, 2020, 01:14:36 pm
.py's don't execute on Windows without being prefixed by the interpreter ?
Title: Re: Problem linking for Xtensa (ESP32)
Post by: MiR on May 09, 2020, 01:44:26 pm
Can you please replace your ppcrossxtensa with the file from here:

http://temp.michael-ring.org/ppcrossxtensa.exe

I have added logging for two important commands.

For me the command ldgen fails which as a consequence lets the linker fail.

Please try on your system and report back the output.

One more thing, I saw that you did not follow instructions because you are using latest esp-idf sdk (binutils from 4.0 have a path with 2019 in it), should not matter too much but it might create crazy issues later in the process when you jumped this first hurdle.


Code: [Select]
C:\Users\ring\devel\hello>ppcrossxtensa -Fuxtensa-freertos\rtl -Tfreertos -XPxtensa-esp32-elf- -O3 -Wpesp32 hello
C:\Users\ring\Desktop\esp-idf/tools/ldgen/ldgen.py
--config sdkconfig --fragments C:\Users\ring\Desktop\esp-idf/components/xtensa/linker.lf C:\Users\ring\Desktop\esp-idf/components/soc/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_event/linker.lf C:\Users\ring\Desktop\esp-idf/components/spi_flash/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_wifi/linker.lf C:\Users\ring\Desktop\esp-idf/components/lwip/linker.lf C:\Users\ring\Desktop\esp-idf/components/heap/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_ringbuf/linker.lf C:\Users\ring\Desktop\esp-idf/components/espcoredump/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp32/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp32/ld/esp32_fragments.lf C:\Users\ring\Desktop\esp-idf/components/freertos/linker.lf C:\Users\ring\Desktop\esp-idf/components/newlib/newlib.lf C:\Users\ring\Desktop\esp-idf/components/esp_gdbstub/linker.lf --input C:\Users\ring\Desktop\esp-idf/components/esp32/ld/esp32.project.ld.in --output ./esp32.project.ld --kconfig C:\Users\ring\Desktop\esp-idf/Kconfig --env-file config.env --libraries-file ldgen_libraries --objdump xtensa-esp32-elf-objdump
hello.pp(3,18) Error: Can't call the linker, switching to external linking
hello.pp(3,18) Error: Error while linking
C:\Users\ring\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-ld.exe
-g     --gc-sections   -L. -o hello.elf -T link9716.res -u call_user_start_cpu0 -u ld_include_panic_highint_hdl -u esp_app_desc -u vfs_include_syscalls_impl -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u newlib_include_locks_impl -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u app_main -u uxTopUsedPriority -L C:\Users\ring\Desktop\esp-idf/components/esp_rom/esp32/ld -T esp32.rom.ld -T esp32.rom.libgcc.ld -T esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T esp32.rom.newlib-funcs.ld -L . -T esp32_out.ld -T esp32.project.ld -L C:\Users\ring\Desktop\esp-idf/components/esp32/ld -T esp32.peripherals.ld
FALSE
hello.pp(3,18) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted

C:\Users\ring\devel\hello>C:\Users\ring\Desktop\esp-idf/tools/ldgen/ldgen.py --config sdkconfig --fragments C:\Users\ring\Desktop\esp-idf/components/xtensa/linker.lf C:\Users\ring\Desktop\esp-idf/components/soc/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_event/linker.lf C:\Users\ring\Desktop\esp-idf/components/spi_flash/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_wifi/linker.lf C:\Users\ring\Desktop\esp-idf/components/lwip/linker.lf C:\Users\ring\Desktop\esp-idf/components/heap/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_ringbuf/linker.lf C:\Users\ring\Desktop\esp-idf/components/espcoredump/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp32/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp32/ld/esp32_fragments.lf C:\Users\ring\Desktop\esp-idf/components/freertos/linker.lf C:\Users\ring\Desktop\esp-idf/components/newlib/newlib.lf C:\Users\ring\Desktop\esp-idf/components/esp_gdbstub/linker.lf --input C:\Users\ring\Desktop\esp-idf/components/esp32/ld/esp32.project.ld.in --output ./esp32.project.ld --kconfig C:\Users\ring\Desktop\esp-idf/Kconfig --env-file config.env --libraries-file ldgen_libraries --objdump xtensa-esp32-elf-objdump
Traceback (most recent call last):
  File "C:\Users\ring\Desktop\esp-idf\tools\ldgen\ldgen.py", line 150, in <module>
    main()
  File "C:\Users\ring\Desktop\esp-idf\tools\ldgen\ldgen.py", line 112, in main
    _update_environment(args)  # assign args.env and args.env_file to os.environ
  File "C:\Users\ring\Desktop\esp-idf\tools\ldgen\ldgen.py", line 41, in _update_environment
    env = json.load(args.env_file)
  File "C:\Users\ring\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\ring\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\ring\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\ring\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 6 column 20 (char 164)



Title: Re: Problem linking for Xtensa (ESP32)
Post by: MiR on May 09, 2020, 01:59:53 pm
Problem is likely in the env file generated from freepascal on windows

This:

    "IDF_PATH": "C:\Users\ring\Desktop\esp-idf",

is not working, this:

    "IDF_PATH": "C:/Users/ring/Desktop/esp-idf",

makes ldgen.py happy but it seems there is more hacking needed....

Here's what I changed for the logging, based on this and adding perhaps a little more logging here and there you should be able to fix the compiler or to at least write a good bugreport:

Code: Pascal  [Select][+][-]
  1. diff --git a/compiler/systems/t_freertos.pas b/compiler/systems/t_freertos.pas
  2. index 4efe4deb79..66a599e003 100644
  3. --- a/compiler/systems/t_freertos.pas
  4. +++ b/compiler/systems/t_freertos.pas
  5. @@ -1144,6 +1144,8 @@ begin
  6.          '--libraries-file ldgen_libraries --objdump xtensa-esp32-elf-objdump';
  7.        Replace(binstr,'$IDF_PATH',maybequoted(GetEnvironmentVariable('IDF_PATH')));
  8.        Replace(cmdstr,'$IDF_PATH',maybequoted(GetEnvironmentVariable('IDF_PATH')));
  9. +      writeln(binstr);
  10. +      writeln(cmdstr);
  11.        if success and not(cs_link_nolink in current_settings.globalswitches) then
  12.          success:=DoExec(binstr,cmdstr,true,false);
  13.      end;
  14. @@ -1186,6 +1188,10 @@ begin
  15.      Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  16.      Replace(cmdstr,'$DYNLINK',DynLinkStr);
  17.     end;
  18. +
  19. +  writeln(FindUtil(utilsprefix+BinStr));
  20. +  writeln(cmdstr);
  21. +  writeln(success);
  22.    if success and not(cs_link_nolink in current_settings.globalswitches) then
  23.      success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);


Title: Re: Problem linking for Xtensa (ESP32)
Post by: TRon on May 09, 2020, 02:08:34 pm
Ah, yes indeed marcov.

Unless resorting to WSL or similar solutions then we are still depending on file association (which is not independent from OS, afaik).

In that regards my statement is most certainly too bold. Good catch  :)

On certain platforms it is not always possible to target everything (or even anything due to hardware restrictions ). It is a continues process, adding and improving things etc. For instance i don't  particularly like the version scheme that FPC front-end uses to invoke the correct compiler version, therefor i wrote a front-end for the compiler front-end  %)

As last resort i'm working on bailing out, and invoke a remote compiler (again if possible). But that feature is in early stage and is still being researched. But i already saw another feature i wish to add, and that is that Lazarus seems to support compiler options to be provided from the (main program's) source-code. That could be a nice addition.
Title: Re: Problem linking for Xtensa (ESP32)
Post by: electronickiwi on May 10, 2020, 05:15:16 am
I've tried a few things with mixed results.

First I tried MiR's ppcrossxtensa.exe, and apart from some additional log output got a similar result, including after I changed the IDF_PATH to linux-style.

Yes, I was using esp-idfv4.2, this came after trying v4.0 without success.  (I note the wiki says to use v4.0.1 which isn't one of the labels used for esp-idf releases, but 4.0 is?).

I now changed back to esp-idfv4.0. I deleted everything and built fpc from source again.

Now using MiR compiler the results indicate that the compiler cannot find ".\rtl\xtensa-freertos" which isn't present but ".\rtl\xtensa" and ".\rtl\units\xtensa-freertos" are present, with the latter specified using -Fu

Code: Text  [Select][+][-]
  1. C:\source\fpc>compiler\ppcrossxtensa -vt -Furtl\units\xtensa-freertos\ -Tfreertos -FDC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin -XPxtensa-esp32-elf- -Wpesp32 -FlC:\Users\Wes\esp\xtensa-esp32-elf-libs\ -FlC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\ hello
  2. Configfile search: fpc.cfg
  3. Configfile search: C:\Users\Wes\fpc.cfg
  4. Configfile search: C:\ProgramData\fpc.cfg
  5. Configfile search: C:\source\fpc\compiler\fpc.cfg
  6. Path ".\::=::\" not found
  7. Path ".\rtl\xtensa-freertos\" not found
  8. Compiler: C:\source\fpc\compiler\ppcrossxtensa.exe
  9. Using executable path: C:\source\fpc\compiler\
  10. Using unit path: .\rtl\units\xtensa-freertos\
  11. Using unit path: .\compiler\
  12. Using library path: C:\Users\Wes\esp\xtensa-esp32-elf-libs\
  13. Using library path: C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\
  14. Using library path: .\rtl\units\xtensa-freertos\
  15. Using library path: .\compiler\
  16. Using object path: .\rtl\units\xtensa-freertos\
  17. Using object path: .\compiler\
  18. Searching file hello.pp... found
  19. Unitsearch: system.ppu
  20. Unitsearch: system.pp
  21. Unitsearch: system.pas
  22. Unitsearch: .\rtl\units\xtensa-freertos\system.ppu
  23. PPU Loading .\rtl\units\xtensa-freertos\system.ppu
  24. Searching file hello.pp... found
  25. Searching file hello.pp... found
  26. Unitsearch: ESP32.ppu
  27. Unitsearch: ESP32.pp
  28. Unitsearch: ESP32.pas
  29. Unitsearch: .\rtl\units\xtensa-freertos\ESP32.ppu
  30. PPU Loading .\rtl\units\xtensa-freertos\esp32.ppu
  31. Unitsearch: consoleio.ppu
  32. Unitsearch: consoleio.pp
  33. Unitsearch: consoleio.pas
  34. Unitsearch: .\rtl\units\xtensa-freertos\consoleio.ppu
  35. PPU Loading .\rtl\units\xtensa-freertos\consoleio.ppu
  36. Unitsearch: heapmgr.ppu
  37. Unitsearch: heapmgr.pp
  38. Unitsearch: heapmgr.pas
  39. Unitsearch: .\rtl\units\xtensa-freertos\heapmgr.ppu
  40. PPU Loading .\rtl\units\xtensa-freertos\heapmgr.ppu
  41. Searching file hello.pp... found
  42. Searching file C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-as.exe... found
  43. Using assembler: C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-as.exe
  44. Searching file hello.o... found
  45. Searching file .\rtl\units\xtensa-freertos\system.o... found
  46. Searching file .\rtl\units\xtensa-freertos\esp32.o... found
  47. Searching file libesp32.a... not found
  48. Searching file libesp32.a... not found
  49. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp32.a... found
  50. Searching file libsoc.a... not found
  51. Searching file libsoc.a... not found
  52. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libsoc.a... found
  53. Searching file libdriver.a... not found
  54. Searching file libdriver.a... not found
  55. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libdriver.a... found
  56. Searching file libfreertos.a... not found
  57. Searching file libfreertos.a... not found
  58. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libfreertos.a... found
  59. Searching file liblog.a... not found
  60. Searching file liblog.a... not found
  61. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\liblog.a... found
  62. Searching file libesp_common.a... not found
  63. Searching file libesp_common.a... not found
  64. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_common.a... found
  65. Searching file libheap.a... not found
  66. Searching file libheap.a... not found
  67. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libheap.a... found
  68. Searching file libnewlib.a... not found
  69. Searching file libnewlib.a... not found
  70. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libnewlib.a... found
  71. Searching file libvfs.a... not found
  72. Searching file libvfs.a... not found
  73. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libvfs.a... found
  74. Searching file libesp_ringbuf.a... not found
  75. Searching file libesp_ringbuf.a... not found
  76. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_ringbuf.a... found
  77. Searching file libspi_flash.a... not found
  78. Searching file libspi_flash.a... not found
  79. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libspi_flash.a... found
  80. Searching file libapp_update.a... not found
  81. Searching file libapp_update.a... not found
  82. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libapp_update.a... found
  83. Searching file libxtensa.a... not found
  84. Searching file libxtensa.a... not found
  85. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libxtensa.a... found
  86. Searching file libbootloader_support.a... not found
  87. Searching file libbootloader_support.a... not found
  88. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libbootloader_support.a... not found
  89. Searching file C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\libbootloader_support.a... not found
  90. Searching file .\rtl\units\xtensa-freertos\libbootloader_support.a... not found
  91. Searching file .\compiler\libbootloader_support.a... not found
  92. Searching file C:\source\fpc\compiler\libbootloader_support.a... not found
  93. Searching file libpthread.a... not found
  94. Searching file libpthread.a... not found
  95. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libpthread.a... found
  96. Searching file libhal.a... not found
  97. Searching file libhal.a... not found
  98. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libhal.a... found
  99. Searching file libm.a... not found
  100. Searching file libm.a... not found
  101. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libm.a... found
  102. Searching file libg.a... not found
  103. Searching file libg.a... not found
  104. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libg.a... found
  105. Searching file libc.a... not found
  106. Searching file libc.a... not found
  107. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libc.a... found
  108. Searching file libesp_event.a... not found
  109. Searching file libesp_event.a... not found
  110. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_event.a... found
  111. Searching file .\rtl\units\xtensa-freertos\consoleio.o... found
  112. Searching file .\rtl\units\xtensa-freertos\heapmgr.o... found
  113. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp32.a... found
  114. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libsoc.a... found
  115. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libdriver.a... found
  116. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libfreertos.a... found
  117. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\liblog.a... found
  118. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_common.a... found
  119. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libheap.a... found
  120. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libnewlib.a... found
  121. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libvfs.a... found
  122. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_ringbuf.a... found
  123. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libspi_flash.a... found
  124. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libapp_update.a... found
  125. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libxtensa.a... found
  126. Searching file libbootloader_support.a... not found
  127. Searching file libbootloader_support.a... not found
  128. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libbootloader_support.a... not found
  129. Searching file C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\libbootloader_support.a... not found
  130. Searching file .\rtl\units\xtensa-freertos\libbootloader_support.a... not found
  131. Searching file .\compiler\libbootloader_support.a... not found
  132. Searching file C:\source\fpc\compiler\libbootloader_support.a... not found
  133. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libpthread.a... found
  134. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libhal.a... found
  135. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libm.a... found
  136. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libg.a... found
  137. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libc.a... found
  138. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_event.a... found
  139. C:\Users\Wes\esp\esp-idf-4.0/tools/ldgen/ldgen.py
  140. --config sdkconfig --fragments C:\Users\Wes\esp\esp-idf-4.0/components/xtensa/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/soc/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp_event/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/spi_flash/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp_wifi/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/lwip/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/heap/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp_ringbuf/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/espcoredump/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp32/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp32/ld/esp32_fragments.lf C:\Users\Wes\esp\esp-idf-4.0/components/freertos/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/newlib/newlib.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp_gdbstub/linker.lf --input C:\Users\Wes\esp\esp-idf-4.0/components/esp32/ld/esp32.project.ld.in --output ./esp32.project.ld --kconfig C:\Users\Wes\esp\esp-idf-4.0/Kconfig --env-file config.env --libraries-file ldgen_libraries --objdump xtensa-esp32-elf-objdump
  141. hello.pp(19,27) Error: Can't call the linker, switching to external linking
  142. hello.pp(19,27) Error: Error while linking
  143. Searching file hello.o... found
  144. Searching file hello.o... found
  145. Searching file .\rtl\units\xtensa-freertos\system.o... found
  146. Searching file .\rtl\units\xtensa-freertos\system.o... found
  147. Searching file .\rtl\units\xtensa-freertos\esp32.o... found
  148. Searching file .\rtl\units\xtensa-freertos\esp32.o... found
  149. Searching file .\rtl\units\xtensa-freertos\consoleio.o... found
  150. Searching file .\rtl\units\xtensa-freertos\consoleio.o... found
  151. Searching file .\rtl\units\xtensa-freertos\heapmgr.o... found
  152. Searching file .\rtl\units\xtensa-freertos\heapmgr.o... found
  153. Searching file C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-ld.exe... found
  154. Using util C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-ld.exe
  155. C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-ld.exe
  156. -g     --gc-sections   -L. -o hello.elf -T link12040.res -u call_user_start_cpu0 -u ld_include_panic_highint_hdl -u esp_app_desc -u vfs_include_syscalls_impl -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u newlib_include_locks_impl -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u app_main -u uxTopUsedPriority -L C:\Users\Wes\esp\esp-idf-4.0/components/esp_rom/esp32/ld -T esp32.rom.ld -T esp32.rom.libgcc.ld -T esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T esp32.rom.newlib-funcs.ld -L . -T esp32_out.ld -T esp32.project.ld -L C:\Users\Wes\esp\esp-idf-4.0/components/esp32/ld -T esp32.peripherals.ld
  157. FALSE
  158. hello.pp(19,27) Fatal: There were 2 errors compiling module, stopping
  159. Fatal: Compilation aborted

Running with the -sh options produces the following ppas.bat (and the cmd window output is similar to above, but ends with TRUE):
Code: Text  [Select][+][-]
  1. @echo off
  2. SET THEFILE=hello
  3. echo Assembling %THEFILE%
  4. C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-as.exe -o hello.o  hello.s --longcalls
  5. if errorlevel 1 goto asmend
  6. Del hello.s
  7. SET THEFILE=hello
  8. echo Linking %THEFILE%
  9. xtensa-esp32-elf-gcc -C -P -x c -E -o esp32_out.ld -I . C:\Users\Wes\esp\esp-idf-4.0/components/esp32/ld/esp32.ld
  10. if errorlevel 1 goto linkend
  11. SET THEFILE=hello
  12. echo Linking %THEFILE%
  13. C:\Users\Wes\esp\esp-idf-4.0/components/esptool_py/esptool/esptool.py --chip esp32 elf2image --flash_mode dio --flash_freq 40m --flash_size 2MB --elf-sha256-offset 0xb0 -o hello.bin hello.elf
  14. if errorlevel 1 goto linkend
  15. goto end
  16. :asmend
  17. echo An error occurred while assembling %THEFILE%
  18. goto end
  19. :linkend
  20. echo An error occurred while linking %THEFILE%
  21. :end
  22.  

Running ppas.bat results in
Code: Text  [Select][+][-]
  1. FileNotFoundError: [Errno 2] No such file or directory: 'hello.elf'
(because it is not being made)

Noting that the wiki advises "So far Linux and Mac hosts only" I then decided to try it via WSL (Ubuntu 18.04) and started from scratch.  I've now been able to get helloworld to run on an ESP32 board (after reducing the flash baud rate) by running from Linux :D.

By the way, a couple of recommended changes for the wiki:
- find ~/esp/esp-idf/components -name "*.a" -exec cp {} ~/esp/xtensa-esp32-elf-libs \;
- for the ESP32:
     make FPC=fpc CPU_TARGET=xtensa OS_TARGET=freertos SUBARCH=lx6 "CROSSOPT=-Cplx6 -XPxtensa-esp32-elf- -Cfhard" all -j
Title: Re: Problem linking for Xtensa (ESP32)
Post by: MiR on May 10, 2020, 08:23:30 am
Seems you are ready for level two  8) , have a look here:

https://github.com/ccrause/fpc-esp-freertos

Michael
Title: Re: Problem linking for Xtensa (ESP32)
Post by: electronickiwi on May 10, 2020, 08:41:48 am
Already there!  ;)  Have successfully run your blink example.  Have updated esp-idf to release v4.1-beta to hopefully be on the same basis as you.

Looking at some of your other examples to get my pascal knowledge refreshed.  I ran into an issue with the compiler not recognising "result", but fixed that with {$mode objfpc}{$H+} added to the program.

Have currently got a problem compiling wifiscan and the other more involved examples that call the esp-idf functions - I think I just need to get all the right paths added to the includes in the command line.  Will let you know how I get on.
Title: Re: Problem linking for Xtensa (ESP32)
Post by: MiR on May 10, 2020, 08:46:54 am
fpc-esp-freertos is not my work, it is work of ccrause, I am mostly working on freertos for arm processors but I also have esp32 in mind when doing this.

This is my project:

https://github.com/michael-ring/mbf-freertos

Michael
Title: Re: Problem linking for Xtensa (ESP32)
Post by: electronickiwi on May 10, 2020, 09:38:20 am
Hi Michael

Sorry for the mix-up, and thanks for the link, and the earlier help.

Wes
Title: Re: Problem linking for Xtensa (ESP32)
Post by: PascalDragon on May 10, 2020, 04:38:42 pm
Quote
only that it can't call the (internal?) linker, and switches to the external linker, which has an error.
That it tries the internal linker first should afaik not happen.

That is in fact a misleading error message by the compiler, cause it prints this if any linker failed, no matter if it was the internal one or not :-[

.py's don't execute on Windows without being prefixed by the interpreter ?

Well, the link script posted by electronickiwi contained a direct call to esptool.py as well and executing it resulted in a call trace inside the Python call, so apparently that does worked correctly.
Title: Re: Problem linking for Xtensa (ESP32)
Post by: peter@jazenga.com on October 04, 2020, 01:36:02 pm
It would be very helpful if someone could share a working fpc.cfg file for xtensa (ESP32)
I have both Linux and Windows 10 but so far no success due to missing xtensa tools however they are on the system
I am unfamiliar with cross compilation for embedded & RTOS so I don't really know how to create the config or where to place the executable files
Title: Re: Problem linking for Xtensa (ESP32)
Post by: ccrause on October 04, 2020, 02:49:44 pm
It would be very helpful if someone could share a working fpc.cfg file for xtensa (ESP32)
I have both Linux and Windows 10 but so far no success due to missing xtensa tools however they are on the system
I am unfamiliar with cross compilation for embedded & RTOS so I don't really know how to create the config or where to place the executable files

Are you trying to compile for embedded or freertos target?  Embedded should be easier to set up, but then you have to write quite a bit of code to configure the cores, set up interrupt handlers, memory manager etc.  FreeRTOS target perform all the configuration of the processors, but linking to the SDK is a little bit more tricky (but the required steps are documented in the wiki (https://wiki.freepascal.org/Xtensa#ESP32)).

Post the specific compiler errors you encountered.
How are you creating the cross compiler? Using make, or install with fpcupdeluxe? If using make, please show the full command line you used.
Are the cross tools (e.g. xtensa-esp32-elf-ld on Linux) in the path or not? If not pass the location to these utilities to the compiler using the -FD option.
TinyPortal © 2005-2018