Post Go back to editing

How does the "freertos.specs" link file work?

The users's guide that ADI has provided for FreeRTOS says to use this file in a linker directive when linking FreeRTOS projects.  The claim is that it prevents default driver libraries from being linked.

I'm trying to figure out how it does that.  The file itself contains no comments, and the documentation about this "specs" format is quite complex.  Here's the first part.

%{!nostdlib: \
  %{!mno-adi-sys-libs: \
    %{mproc=ADSP-SC570: apt-sc570.o%s} \
    %{mproc=ADSP-SC571: apt-sc571.o%s} \
    %{mproc=ADSP-SC572: apt-sc572.o%s} \
    %{mproc=ADSP-SC573: apt-sc573.o%s} \
    %{mproc=ADSP-SC582: apt-sc582.o%s} \
    %{mproc=ADSP-SC583: apt-sc583.o%s} \
    %{mproc=ADSP-SC584: apt-sc584.o%s} \
    %{mproc=ADSP-SC587: apt-sc587.o%s} \
    %{mproc=ADSP-SC589: apt-sc589.o%s} \
    %{mproc=ADSP-SC58*: -lfftacc} \
    %{mproc=ADSP*: -lssl -losal -lrtadi} \
    %{mproc=AD*: -lm} \
  } -lc \
}

I think what it is saying is that "IF the -nostdlib flag IS NOT SET *AND* the -no-adi-sys-libs flag IS NOT SET, THEN use these default mmu tables (apt*.o) and use these default libraries".

If I have that right, then there is a problem, because in all these demo projects, neither of these flags are set (nor are we advised to set them), thus the default libraries are getting loaded anyway.  Yes, I verified this by looking at a map dump, there is a lot of device code being loaded from libssl, even though I specified all my devices with add-in in the System Configuration Overview.

But maybe it doesn't matter, because the source to the FreeRTOS libraries are effectively linked-in via virtual directory links, and this code will get linked before the linker starts opening libraries.  That explains why some of the Demo projects that don't have use the freertos.specs file in their linker settings work just fine.

  • Okay, I figured it out.  The point is to avoid linking any code from the Device Driver library, libdrv.  If you run

    arm-none-eabi-gcc -dumpspecs >c:\temp\out.txt

    you'll find the default specs file is almost the same as the above code, except it has this line which also includes libdrv.

    -ldrv -lssl -losal -lrtadi

    So the above specs file overrides the default and avoids loading the pre-built driver library, thus preventing you from accidentally using any of that code instead of code built by your project.

    This still worries me though because libssl is still being used, even though the documentation warns against using it.  But I'll ask about that in another question.