AnsweredAssumed Answered

Avoiding HCS08 linker dead stripping for constants

Question asked by SCOTT MILLER on Jul 2, 2016
Latest reply on Jul 19, 2016 by SCOTT MILLER


I'm trying to implement on HCS08 a technique that I use on ColdFire and Kinetis, but I'm hitting a snag with the linker - I need a way to avoid dead stripping of unreferenced constants when the exact object names are not known in advance.

 

To give a little background, the mechanism I'm implementing is an auto-start list.  I have projects with numerous peripheral drivers (typically sensors) and each has an init function that checks for the presence of the associated device and registers callbacks with the main application as needed.

 

I have an AUTO_START() macro that's called from each driver and creates a struct with a function pointer, priority, and any other required settings, and stores it as a const in a special section. This lets me add and remove peripheral support from multiple projects without changing any of the application code or having to add includes - the main application simply reads through the list in memory and calls each init function in turn.

 

Creating and placing the const struct is no problem with CW10.6, but the HCS08 linker doesn't seem to have any way to avoid automatic dead stripping short of disabling smart linking entirely, which is a really bad idea with the ANSI C libraries.

 

On Kinetis KEEP (*(.auto_start)) is sufficient to retain everything in that section.  With the ColdFire linker I use REF_INCLUDE {.auto_start}.  I don't see any way to do that sort of wildcard with the HCS08 linker.  All it provides is the ENTRIES list, and exact names are needed for each object to be retained.  The AUTO_START() macro creates each entry with a unique name using token pasting and having to enter each name into ENTRIES would entirely defeat the purpose.

 

ENTRIES, INIT, and VECTOR seem to be the only starting points for the linker's transitive closure.  None of those do me any good.  Placing a const at a specified address using @address avoids dead stripping, but that doesn't do me any good when I'm trying to automatically construct a list with more than one item.  The @"section" specifier does not prevent dead stripping.

 

Any ideas?

 

Scott

Outcomes