LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 01-27-2006, 06:11 PM   #1
sto237
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
e.g.

------- 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?

Thanks!
 
Old 01-27-2006, 06:46 PM   #2
jinksys
Member
 
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.
 
  


Reply


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 12:57 PM
Problem in Loading a shared object in linux phani@tcs Programming 1 01-11-2006 08:29 AM
problem in loading a shared object in linux phani@tcs Linux - General 2 01-10-2006 03:50 PM
about running c++ object file glee4ever Programming 2 03-02-2004 10:26 PM
problem in dynamically loading the shared object sumit Programming 1 01-10-2002 03:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:06 PM.

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