Thread: Including functions at run-time

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    36

    Including functions at run-time

    Hi all,

    Is there a way to include load in a file at run-time and execute the functions without doing it as a dll?

    I am writing for an ARM procesor without an OS. The compiled code are .axf files. Is there some way to load an axf file into memory, find out the address of the 'main' function (I will know its prototype) and execute it?

    Cheers,
    Pea

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I am writing for an ARM procesor without an OS.
    Sounds like it doesn't have a file system either.

    The only thing I can think of is compile the axf file into your code as a data array
    Code:
    unsigned char axf_file1[] = {
      0x00, 0x01, /* etc etc */
    };
    Then it's simply a matter of casting some offset into that array into some suitable function pointer.

    Is your ARM processor one of those with separate address spaces for code and data?

    If it is, you need to do something like this (gcc syntax)
    Code:
    unsigned char axf_file1[] __attribute__ ((section ("code"))) = {
      0x00, 0x01, /* etc etc */
    };
    to make sure the initialised array exists somewhere which is valid for code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    36
    Hi,

    The system I am developing for is the handheld called the GP32. It has a 200MHz ARM9 processor, 8MB or memory, and has a smartMedia slot for up to 128MB of RAM, 320x240 pixel screen with 65535 colours.

    Although the GP32 doesn't have an operating system as such, many people have written file browsers, image viewers, file launchers, mp3 players, divX players (yep, divX!) etc for it, and it has an official sdk with basic functions to access the major features, as well as several homebrew sdk's.

    However, what I think I need is an implementation of dlopen that will run on it to open dynamic libraries. Any ideas on how to 'port' this function set?

    salem: Thanks for your answer. I think that dlopen basically does what you recommend salem, but it can also do stuff like determining exactly where in the code all the various functions are. I'm not sure what type of file dlopen actually uses because I don't think its a standard 'windows' dll.
    Last edited by Pea; 10-13-2004 at 07:43 PM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    There are only 3 functions to implement.
    http://www.opengroup.org/onlinepubs/...ons/dlsym.html

    From what I've just read, AXF is basically the same as ELF, so it should be pretty each to just grab the Linux implementation (say) and modify to suit your needs.
    http://sources.redhat.com/ml/ecos-di.../msg00310.html

    But for any of this to work, you need to have a "malloc" to allocate space to store the library when you need it, and a file system to store the library when you don't.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    36
    Yeah, thats no problem.

    As I said in my previous post, the GP32 has a smart media card which it uses as its file system. All applications are run from the card, and there are wrappers to the standard file system commands to work with the smc.

    There are also malloc equivs (maybe even malloc itself).

    Cheers!
    Pea

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Run time error?
    By shwetha_siddu in forum C Programming
    Replies: 6
    Last Post: 04-21-2009, 01:37 PM
  2. Need help with time
    By Gong in forum C++ Programming
    Replies: 7
    Last Post: 01-11-2007, 02:43 PM
  3. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. Average asymptotic run time?
    By Ariod in forum C Programming
    Replies: 1
    Last Post: 08-03-2005, 06:47 PM