MIPS – compiling relocatable code with SDE-GCC ?
Hi,
I’m using SDE-GCC to compile programs that runs on “bare iron” (i.e. no operating system). I would like to be able to create programs (“executables”) that can be loaded to arbitrary addresses on RAM and run from there.
I used to compile and run successfully such kind of programs on ARM processor (with different tool-chain of course) where the program was PC relative. MIPS don’t expose the PC and seems it has its own way to
do it.
I tried to use -mabicalls -fPIC compilation flags to create PIC (Position Independent Code): when I examined the “objdump” I could find that the “GOT” (global offset table) is still made of absolute
addresses so the program is bounded to run on a specific address (the linking address).
Can you direct me on how to do that?
Thanks in advance,
Eli


«that can be loaded to arbitrary addresses on RAM and run from there.»
if the MIPS arch does not allow it, you must write a loader that relocate the code whereever you want
as far as i can see, MIPS allow “relative” coding, so… just be sure you dont use j, jal, and more… for the rest, e.g.
lb and more, i can see they accept a offset, so the way the new PC (or Instr Pointer as you prefer) is calculated allow for relative address independent code (if the code is all inside the max range offsets can span!)