linking and loading images aware of each other
Mon Nov 13 12:43:00 GMT 2006
I would like to have your suggestions on how to achieve the following
in the simplest, cleanest way.
I have images A and B (and possibly C, D, ... ) to be loaded in
physical memory one after the other. Each have .text, .data, .bss
sections. B should be linked at the next page after A ends (so it must
know where A ends at its link time), also the code in A, should be
able to know/discover where B is going to be loaded and where it ends
at its runtime.
My possible solutions:
1) If I build A and B as separate images, by first building and
linking A, the page at which B would start (i.e. the next page after
A) can be determined. I can easily filter objdump output for A to find
out where it ends, and include B's start address in B's linker script
before building it. But I have already built A, so there's the problem
of patching A's image to insert B's start and end address somewhere,
and this might be tedious.
2) I could link the two together using a single linker script. Then
where each image is loaded would be determined at link time, and each
image can be aware of where the other is, by simply reading
linker-defined variables. The problem with this is these are actually
two different images, objects in them have no relation, also each
needs to have its own _start address, so that will probably be
ambiguous. Furthermore, I may need to have images C, D and more. So it
would quickly get tedious to maintain a single linker script for
multiple images meant to be independent.
3) After all images are built, I could compile a data structure with
all image information, and load that in a predefined region in memory.
At runtime image A or whoever image wants to discover about the others
would read this structure from a predefined location.
Are any of these feasible do you think? Do you have any cleaner,
More information about the Binutils