Make template generate in same section as caller

Viewed 42

The section attribute of GCC/Clang can be used to put functions/data into specific sections. However, when a template is used from such a function, it is instantiated in the default text section (unless, of course, it too is marked with a section attribute). In the case of using a third-party template library, is there a way to make template instantiations occur in the same section of the function that calls them without needing to modify the templates? I've tried using the flatten attribute, but that doesn't always work (even if it did, it'd also cause needless bloat if said templates were big, depended on other templates, and/or were used in other places).

For context, I am developing for an embedded platform where there are multiple banks of RAM memory-mapped into a linear address space. Each of the banks has a different latency and bus size, so it matters where hot/cold code goes.

1 Answers

you can a Linker Definition File (LD) to the linker,
and instruct to throw any modules, functions or sections you want to any section you like at any position you wish for.

bit tedious, but gives the most control.

Related