Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 01-27-2006, 07:11 PM   #1
LQ Newbie
Registered: Oct 2005
Posts: 8

Rep: Reputation: 0
Question Loading object code into RAM and running it

Linux 2.4.20, x86 for testing, ARM target

What I want to do is this:

1. compile a .o file, save to disk (on command line).
This .o has a statically initialized function table pointing to the public functions in the .o file

------- from file1.c -----------
typedef int MY_ADD(int, int);
int my_add(int left, int right) { return left + right; }

struct ftable { MY_ADD *ft_add; };

static struct ftable my_table = { my_add };

2. The rest happens in a C program which is not linked to file1.o, but has declarations
for the needed types

3. open file1.o, copy to RAM

4. figure out where the data and object code resides in RAM

5. get a pointer to my_table

6. fix up the function pointer in my_table to (re)point to my_add

7. call my_add from my C program, e.g. my_table->ft_add(left, right);

Why not simply use a shared lib, kernel module, etc and let the kernel do the relocation? Because I want to make some code available to a booting kernel _before_ it has come up enough to load such things on its own.

I'm looking at the ELF format and can parse the headers and string tables. Before I delve into the symbol table, I'd like to see if there's a better/easier way.

Is there an objcopy switch(es) that would give me a raw binary image that would be better to parse than ELF?

Will I have problems from the memory manager since the code isn't necessarily loaded in an "ok to execute" area?

Old 01-27-2006, 07:46 PM   #2
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
Welcome to LQ!
This post is more likely to be answered in the programming forum.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in loading a shared object in linux phani@tcs Linux - Newbie 2 01-11-2006 01:57 PM
Problem in Loading a shared object in linux phani@tcs Programming 1 01-11-2006 09:29 AM
problem in loading a shared object in linux phani@tcs Linux - General 2 01-10-2006 04:50 PM
about running c++ object file glee4ever Programming 2 03-02-2004 11:26 PM
problem in dynamically loading the shared object sumit Programming 1 01-10-2002 04:15 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:29 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration