View Issue Details

IDProjectCategoryView StatusLast Update
0038789FPCCompilerpublic2021-04-27 12:38
ReporterChristo Crause Assigned ToFlorian  
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038789: Xtensa [patch] Libraries passed via the command line not included in linker script for xtensa-freertos
DescriptionThe basic libraries statically linked via the controller units do not list all dependencies for older versions of the SDK (specifically ESP8266_RTOS_SDK version 3.3). Passing the needed libraries using the -k option is ignored when generating the ldgen_libraries and link.res files.

The attached patch moves libraries specified with the -k option into the StaticLibFiles list, fixing this problem.
TagsNo tags attached.
Fixed in Revision49267
Attached Files


Christo Crause

2021-04-22 21:16


xtensa-libs.patch (961 bytes)   
Index: systems/t_freertos.pas
--- systems/t_freertos.pas	(revision 49246)
+++ systems/t_freertos.pas	(working copy)
@@ -955,6 +955,8 @@
   t: Text;
   hp: TCmdStrListItem;
   filepath: TCmdStr;
+  i,j: integer;
+  lib: AnsiString;
 {$endif XTENSA}
 {$ifdef XTENSA}
@@ -1139,6 +1141,20 @@
   if ioresult<>0 then
+  { extract libraries from linker options and add to static libraries list }
+  Info.ExtraOptions:=trim(Info.ExtraOptions);
+  i := pos('-l', Info.ExtraOptions);
+  while i > 0 do
+   begin
+     j:=pos(' ',Info.ExtraOptions);
+     if j=0 then
+       j:=length(Info.ExtraOptions)+1;
+     lib:=copy(Info.ExtraOptions,i+2,j-i-2);
+     AddStaticCLibrary(lib);
+     delete(Info.ExtraOptions,i,j);
+     trim(Info.ExtraOptions);
+     i := pos('-l', Info.ExtraOptions);
+   end;
   while assigned(hp) do
xtensa-libs.patch (961 bytes)   


2021-04-23 20:33

administrator   ~0130551

Do you have any example when this is useful? I do not like to parse arbitrarily parameters passed to the linker.

Christo Crause

2021-04-23 22:53

reporter   ~0130553

I'm linking against ESP8266_RTOS_SDK_V3_3 libraries, which have slightly different library dependencies than listed in esp8266.pp in trunk. For instance trying to link a simple hello world example fails with this message:
/home/christo/xtensa/ESP8266_RTOS_SDK_V3_3/libs/libnvs_flash.a(nvs_page.o):(.literal._ZN3nvs4Page6Header14calculateCrc32Ev+0x0): undefined reference to `crc32_le'

The crc32_le reference is declared in libutil.a and the linklib statement for this was removed in r46526. To link against an older version of the SDK thus require specifying additional libraries that must be statically linked. Using the compiler's -k option to pass libraries to be linked to the linker seems like a reasonable approach, but the problem with xtensa-freertos is that the compiler call SDK scripts to call the linker indirectly, hence the normal way of passing options to the linker is missing.

Another work-around is to specify these extra linklib dependencies in some other unit, which is what I currently do.

Christo Crause

2021-04-24 23:28

reporter   ~0130569

I realised the compiler didn't write the linker command when using the -s option. Normally the linker command is executed and the linker parameters passed in with -k is copied as parameters correctly.

This means that the original patch shouldn't be required. The next patch just fixes writing the linker command to the linker script when using the -s option.
xtensa-freertos.patch (630 bytes)   
Index: systems/t_freertos.pas
--- systems/t_freertos.pas	(revision 49246)
+++ systems/t_freertos.pas	(working copy)
@@ -1256,8 +1256,7 @@
-  if success and not(cs_link_nolink in current_settings.globalswitches) then
-    success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
+   success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
 { Remove ReponseFile }
   if success and not(cs_link_nolink in current_settings.globalswitches) then
xtensa-freertos.patch (630 bytes)   


2021-04-26 22:52

administrator   ~0130599

Thanks, applied.

Christo Crause

2021-04-27 12:38

reporter   ~0130612


Issue History

Date Modified Username Field Change
2021-04-22 21:16 Christo Crause New Issue
2021-04-22 21:16 Christo Crause File Added: xtensa-libs.patch
2021-04-23 20:33 Florian Note Added: 0130551
2021-04-23 22:53 Christo Crause Note Added: 0130553
2021-04-24 23:28 Christo Crause Note Added: 0130569
2021-04-24 23:28 Christo Crause File Added: xtensa-freertos.patch
2021-04-26 22:52 Florian Assigned To => Florian
2021-04-26 22:52 Florian Status new => resolved
2021-04-26 22:52 Florian Resolution open => fixed
2021-04-26 22:52 Florian Fixed in Version => 3.3.1
2021-04-26 22:52 Florian Fixed in Revision => 49267
2021-04-26 22:52 Florian FPCTarget => -
2021-04-26 22:52 Florian Note Added: 0130599
2021-04-27 12:38 Christo Crause Status resolved => closed
2021-04-27 12:38 Christo Crause Note Added: 0130612