Including interface functions in local .xc file or library

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
aclassifier
Respected Member
Posts: 507
Joined: Wed Apr 25, 2012 8:52 pm

Including interface functions in local .xc file or library

Post by aclassifier »

I have an found out that interface functions in local .xc files are always included by the linker, even if they are not used.

Opposite with libraries: unused interface functions will not take up code space.

If this is so, why?
--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Hi,
If you add "-save-temps" to your build flags and look at the .s files that are created, all functions etc should be surrounded by a 'cc_top' 'cc_bottom' pair (braces).
The linker will then eliminate all blocks it does not need.
If a block is not being eliminated either:
- there is a symbol that it thinks it needs (wrongly) and pulls it in... and often everything else with it!
- the cc_top/cc_bottom is missing

Without an example it is hard to know what is happening in your situation.
robert
User avatar
aclassifier
Respected Member
Posts: 507
Joined: Wed Apr 25, 2012 8:52 pm

Post by aclassifier »

Thanks, Robert! However, I have used "-save-temps" since I don't know when. And I could not find out about the other info you gave. I found the "top" and "bottom" labels, but not the braces, and I didn't know what to do with what I found.

Disclaimer: I have inferred by the code sizes I get that setFrequencyHz and getFrequencyHz are also included when they should not. If this is not correct then there must be another reason for the fact that the code does not decrease when those two functions are not used. I have been used to "older" type link map files and seem to be less familiar with the XMOS files than I'd like to admit.

However, I have made the code available at [1] (for those who are really curious and have the time). It contains two built versions of the RFM69 radio code and the modified version of the XMOS [lib_spi] library, so you could try to build it yourself. But this should not be necessary if all you need to do is study the map and .s files (plus the sources). The code is a port (better, a rewrite), partly from the RFM69 library by LowPowerLabs by Felix Rusu [2] and partly the RadioHead library by Mike McCauley [3]. I am blogging about this at [4].

The code zip unpacks to:
  • One version is compiled with RADIO_IF_FULL 1 (“Radio interface full”). The two interface functions setFrequencyHz and getFrequencyHz are never used (code size is 16460). In this case the linker should not have included them
  • The other version compiled with RADIO_IF_FULL 0. It simply removes the code for those two functions. It is smaller (code size 16124) as expected. This is the code size I would have expected above as well. Search for "ROBERTXMOS" in the code (one hit)
  • My modified version of XMOS lib_spi, in case you want to compile it yourself
If you want to compile with setFrequencyHz and getFrequencyHz called then have RADIO_IF_FULL 1 and SEMANTICS_DEBUG_CALC_RF_FRF_REGISTERS 1.

Robert, if this turns out to be a linker issue you are of course free to upload the code to the XMOS Issue Servers.

[1] the code (13.6 MB) This is not a "release" candidate, take it as it as a snapshot. Try "Yucca11" if you are asked
[2] https://lowpowerlab.com/
[3] http://www.airspayce.com/mikem/arduino/RadioHead/
[4] My aquarium’s data radioed through the shelf (Standard disclaimer)
--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/