This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Placing .obj-files in specific segments

Hi,

 

I am trying to place a number of procedures in a specific section in flash memory. I know this can be done using #pragma CODE_SECTION(), and this works well in my context, but I'd have to specify this for quite a large number of procedures, all of them located in the same .obj-file. Moreover, the code in question is provided by a third party and might be updated in the future, so I'd rather not change anything in the sourcecode at all since I'd have to apply those changes with every possible update.

So I tried to specify the location of the .obj-file in the linker command file like this:

.my_section:

{

my_obj.obj

} > MY_SECTION

 

But this actually causes the linker to link everything contained in the obj into .my_section, including non-constant global variables that are (obviously) supposed to be allocated in RAM memory.

So long story short, is there a way of telling the linker to link all code of the .obj-file into .my_section without affecting the placement of non-constant variables?

 

  • Florian,

    To place just the code(.text) sections of a specific object file into .my_section, you can do the following:

    .my_section:

    {

    my_obj.obj(.text)

    } > MY_SECTION

    The syntax for this and various other allocations supported by the linker are documented in the Assembly Language Tools Users Guide. Please refer to the Users Guide for the device family you are using. In addition, information on which sections are generated by default by the compiler, and what they contain, is documented in the C/C++ Compiler Users Guide.

  • Many thanks Aarti, works perfect!