Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MIPS - compiling relocatable code with SDE-GCC

495 views
Skip to first unread message

Eli

unread,
Nov 25, 2008, 7:46:05 AM11/25/08
to
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

Mike Sieweke

unread,
Nov 25, 2008, 6:15:44 PM11/25/08
to
Eli <era...@gmail.com> wrote:

I doubt "-fPIC" does anything, since GCC generally doesn't support
application-level PIC on the MIPS. The compiler is probably
ignoring that option and just using "-mabicalls". So it's
generating library code, which is why you have a GOT.

What version of GCC are you using? There is an undocumented
"-membedded-pic" option that's only supposed to work on ECOFF
targets, but it may work for you. I tried a very simple test,
which worked surprisingly well with GCC 4.2.4:

mipsisa32-elf-gcc -membedded-pic -no-stdlib -o test.elf test.c

This produced PIC code that uses the GP register for access
to global data. You may need other options or a linker script
to handle some small details, but I think this will get you
90% of the way there.

--
Mike Sieweke
Duluth, GA

Eli

unread,
Nov 30, 2008, 3:37:06 AM11/30/08
to
Hi Mike,
Thanks for your efforts.

I'm using "sde-gcc" 6.05. I'm afraid it's not supporting the "-
membedded-pic" option.
It seems that there is no straight-forward way to compile
"relocatable" code with this compiler.
I assume that I'll have to try the approach that Linux does (dynamic
linking) or configure the MMU per each time I launch a program.

Regards,

Eli

Mike Sieweke

unread,
Dec 1, 2008, 9:18:12 PM12/1/08
to
Eli <era...@gmail.com> wrote:

Hi Eli,

I made a mistake when I tested the "-membedded-pic" option. It
works with GCC 3.x.x, but not with 4.x.x versions. sde-gcc 6.06
is based on GCC 3.4.x, but it appears the MIPS support was taken
from a later 4.x.x version. That would explain why it doesn't
support the option.

It's pretty easy to build a cross-compiler, if you aren't required
to use sde-gcc. You could base it on 3.4.4, and you might be able
to use the other tools from sde-gcc. I have no way to try this.

0 new messages