#38151 - cyclone - Wed Mar 23, 2005 1:59 am
Hello,
Once a program that consists of for example 3 object code files, has been assembled, does it need to linked by a linker for a specific file format?
Or does the linker just need to do relocation and linking, since the gba game will always run from the same address?
I just want to know if I understand things correctly.
basically what the way I understand it is, the assembler will just need to generate the instructions, leave the blanks/symbols for the linker with no regard to anything other than address modification (due to one module using another module and thereby not knowing the exact address of a variable). And then the linker that relocates the addresses and links the object files into one gba file to be run.
Is that right?
Please correct me where needed.
Thank You.
#38164 - Vince - Wed Mar 23, 2005 10:15 am
Hello,
You are mostly right here. The linker has to understand the object file format generated by the assembler. This is because the linker will read contents from the various object files, resolve symbols as needed, perform relocations, add library code and create a new object file containing everything necessary to run on the platform.
There is another difference between a GBA binary and a Linux binary for instance : on the former, there is no operating system loader. This means that the final binary will run at fixed address whereas with an OS, the loading address is generally not known : the linker relocates as if all programs will run at, for instance address 0 and the loader relocates as needed when loading the program. This means there will be some relocation information left in the final object file whereas the GBA binary is stripped from all of these.
I hope it was clear (this is a big subject however). Feel free to ask any more questions if needed.
Vince
_________________
Reclaim control of your F2A/F2AU with if2a !!
#38176 - cyclone - Wed Mar 23, 2005 4:20 pm
Thanks Vince, that's mostly what I was thinking.
That makes writing all sorts of low level tools easier since there is no need to adhier to any file format.
It's like the com format of dos, except even then the os does some loading there but not much.
Anyway, thanks again for the reply.
#38232 - sasq - Thu Mar 24, 2005 11:36 am
I am pretty sure that Linux ELF-files are not relocated but mapped to a static adress and then the MMU takes care of the relocation in hardware instead. That's why there is an option for the gnu-linker that will add relocation data to the ELF, but this option is not commonly used.
#38241 - Vince - Thu Mar 24, 2005 2:57 pm
There is still some relocation information in a final Linux object file that uses dynamic libraries (as shown by the rel.dyn and rel.plt in, for instance, /bin/ls that was dynamically linked). However, these relocations are not meant to be applied to a section of the object file (data, rodata or text).
As for the MMU, I won't call that relocation. With an MMU, nothing is done on code in the object file, the _translation_ is done in HW on the virtual addresses.
Finally, you are right concerning ELF _programs_ on Linux (which are never relocated). However, keep in mind that shared libraries (which are also ELF files) are relocated nevertheless in Linux.
Vince
_________________
Reclaim control of your F2A/F2AU with if2a !!