Pages: [1]   Go Down
Author Topic: Relocatable code  (Read 651 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8472
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does anyone know if the GCC compiler we all know and love produces relocatable code? By that I guess I mean all jumps have to be relative etc. and if so is there a limit to the distance a jump/call can go?

Why? I'm thinking of adding plug-in modules to a system and maybe it would be nice to have them plug-n-play in the sense that the driver code for each module is held on the module itself and loaded into internal or external RAM by the SAM processor. As the load address would not be known until the time the loading is done the code needs to be relocatable.

There would be a lot of details to work out and I'm not even convinced it's a good idea, but I'd like to know if it's at least possible before I spend any real time on it.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you mean position-independent code? 'Relocatable' code means code with absolutes and relocation tables and is what GCC generates already. Position-independent code is code with all relative jumps and PC-offset/register-offset addressing and has no or minimal relocation tables. The relevant GCC option is -fpic. ARM code is highly position-independent anyway and there is little or no restriction on branch distance.
Logged


nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8472
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do you mean position-independent code?
Yes I guess I do.

Quote
The relevant GCC option is -fpic.
So I can generate such code should I decide this is a worthwhile feature.

I would expect ARM code to lend itself to this but wasn't sure if the compiler would support it.

So I could grab a binary from an EEPROM on a module, load it into RAM somewhere, set some pointers and call functions in that block of code, presumably through a table at a fixed location.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: