Retrieving function addresses in an object file

Fredric M <px_seven@yahoo.se>
Tue, 6 Apr 2010 06:58:37 -0700 (PDT)

          From comp.compilers

Related articles
Retrieving function addresses in an object file px_seven@yahoo.se (Fredric M) (2010-04-06)
Re: Retrieving function addresses in an object file cr88192@hotmail.com (BGB / cr88192) (2010-04-10)
Retrieving function addresses in an object file chakaram@auth.gr (Chariton Karamitas) (2010-04-12)
| List of all articles for this month |

From: Fredric M <px_seven@yahoo.se>
Newsgroups: comp.compilers
Date: Tue, 6 Apr 2010 06:58:37 -0700 (PDT)
Organization: Compilers Central
Keywords: linker, question
Posted-Date: 07 Apr 2010 01:51:38 EDT

Hello All,


I am in the process of creating a simple, custom object file format
(with position independent code) using ld and gcc, with the following
principal layout:


obj_file_header
function_1_header
function_2_header
...
function_n_header
function_1
function_2
...
function_n


function_x is the actual start of the entire function_x code. It
should be possible to jump to any of the functions directly by using
the function header information (function_x_header).


function_x_header could look like the following:


typedef uint32_t function_start; //Holds the start address of the
function


The aim is to have a very simple loader which takes as input the
function to run, e.g. function_2 and then parses the object file to
locate function_2_header. The loader should then be able to read the
value of function_start and use that information to begin to execute
function_2.


The question is how to accomplish this with ld and gcc? It would be
very convenient if one could do something like the following in the
source code:


/*pseudo code*/
function_start function_2 = "offset from start of object file to start
of function_2"


The loader could then easily use this information to simply jump to
the given offset from the start of the object file to begin to execute
function_2.


Is it possible to achieve something like this?


Thanks for any help,
Fredric


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.