- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
how do i put a function or a code file in a specific memory section?
other than .text... tnx...Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Add (IIRC) __attribute__((section("section_name"))) to the definition,
either at the end of a declaration, or (I think) before the function name itself.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The attribute directive must be added after the function declaration.
For example you declare: int myFunction (void) __attribute__ ((section (".onchip_mem_code"))); Then the function definition without any attribute: int myFunction (void) { // function body } Similarly for data, except here you must specify attribute when you define the variable, not when you declare it: int myVariable __attribute__ ((section (".onchip_mem_data"))); For external referencing the variable, don't use any attribute: extern int myVariable;- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can also put the section attribute before the function name, eg:
static __attribute__((section(".text.foo"))) int
foo(void)
{
/* function body */
}
(It can go either side of the return type, not sure which is preferred.) For non-static functions this rather depends on whether you want the section info in the .c file or the .h one. For data, the section in an 'extern' is used to determine whether to use 'small data' (%gp relative) addressing (.sdata or .sbss). The location of the data itself depends on the actual definition.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page