Linker section attributes

cancel
Showing results for 
Search instead for 
Did you mean: 

Linker section attributes

628 Views
Senior Contributor I

I did have a previous question that was answered on how to control the linker section attributes, and I have been able to define a "fake" memory region into which things can be located into an external serial EEPROM.  Now I have more questions along that line.  I'm porting CodeWarrior code that previously used #pragma to "switch on" a section attribute for a region until the next #pragma could flip it to the next section.  Having to add the __attribute__((section("section("name")) to every declaration is a bit painful.  Is there a way to change the section attributes on a per-file basis?  There's some mention in the GCC documentation of using the linker facilities to do this for a large region, but I can't seem to find anything describing this.

 

Another question, is there any documentation on what the default section names are that GCC uses?  I've been able to identify .rodata, .data, .bss, and .text, but are there others?

Labels (1)
0 Kudos
3 Replies

9 Views
Senior Contributor I

Another related question to this, is there a way to separate strings from rodata?  Codewarrior had a section called "strings" that could be linked separately.  I can make constant definitions of strings and use the __attribute__ tag to force them into their own section, but it's a little painful. 

0 Kudos

9 Views
NXP Employee
NXP Employee

Hello David:

Sorry for the time with no responses.

- About changing the attributes on a per file basis, I do not think that is possible. But a similar way would be to force the contents of the entire file (separated by sections) into custom memory segments. Something like:

.custom_text :

{

          *MyFile.o (.text*)

          . = ALIGN(4);

} > my_text_section

.custom_data :

{

          *MyFile.o (.data*)

          . = ALIGN(4);

} > my_data_section

This worked with the GCC toolchain used by CodeWarrior. In case this does not apply to GCC in KDS, colleague Erich Styger just published a good tutorial:

Putting Code of Files into Special Section with the GNU Linker | MCU on Eclipse

- Right now I don't know of a specific place to search for information about section names. But surely you can find something in the web as GCC is widely used.

- You are right, strings could be linked separately in CodeWarrior. I am afraid that this is not supported by GCC linker.


Regards!,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

9 Views
Senior Contributor I

Thanks Jorge, I think I came to that same conclusion that GCC did not make strings a separate section that could be relocated, it just makes it part of .rodata.  I ended up having to declare all strings as constants and putting the section attribute in each declaration. 

0 Kudos