How to tell the linker to place the particular function at the specified address?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to tell the linker to place the particular function at the specified address?

Tomek Lorek
Hi,
I'm struggling to find out how can I tell the GNU linker (using
msp430-gcc frontend to msp430-ld with -Xlinker option) to place the
particular function at the specified address.

Suppose I have a __interrupt void Timer0_A0_alter(void) function that
I'd like to have exactly at 0xC400. Could you give me any hint?

Best Regards,
Tomek

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: How to tell the linker to place the particular function at the specified address?

DJ Delorie

In general (i.e. untested ;) you'd add a linker script snippet like
this:

section_TAO 0xC400 : {
  *(.myfuncsec_TAO)
}

Then tag your function with a section attribute:

static void __interrupt __attribute__((section(".myfuncsec_TAO")))
Timer0_A0_alter(void)
{
}


The key here is that you can change the section a function (or
anything, like data or tables) is in, and the linker knows how to put
specific sections at specific addresses.

Note that this only works if *other* output sections in the link do
not overlap.  I typically avoid the examples above, and instead use
memory regions, that way I know they won't overlap or overflow.

MEMORY {
        MYFUNCSEC (r) : ORIGIN = 0x0c400, LENGTH = 0x00400
}

section_TAO : {
  *(.myfuncsec_TAO)
} > MYFUNCSEC


Note that you can also do per-file placement, by replacing the '*' wildcard
with the file name you want:

section_TAO {
  int_a0.o(.text)
} > MYFUNCSEC

but if there are other .text things in that object that you're not
aware of, that won't guarantee that the specific handler is at the
address you want.

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users