|
| | antime said: |
I'm not entirely sure on all the details as they seem to vary with target and operating system, but as I understand it you should define a section in the linker script that collects all the GOT entries and defines the _GLOBAL_OFFSET_TABLE_ symbol at the start of that section. The symbol is then used to locate the GOT at runtime. This also implies that the GOT's address must be fixed unless you have a dynamic linker.
Have you checked the compiler output when not using -fPIC? Due to the architecture SH code is pretty position-independent by nature (relative offsets used for most things) and some small utility routines I've written have turned out to be completely relocatable without any extra effort on my part.
|
I managed to to fix the _GLOBAL_OFFSET_TABLE_ issue. Instead of specifying the address in the linker script like so:
OUTPUT_FORMAT("binary")
SECTIONS
{
. = 0x06004000;
.text : { *(.text) }
[etc]
You do it like this:
OUTPUT_FORMAT("binary")
SECTIONS
{
_GLOBAL_OFFSET_TABLE_ = .;
.text : { *(.text) }
[etc]
I'm still getting one more linker error I couldn't figure out though. I'm getting "undefined reference to `_(double, int, void, short, int, _i4, int) __restrict".
From what I could tell from the output, when using a regular compile larger functions were called using jsr's with hard-coded addresses. Where as -fpic generally used bsr or bsrf. Obviously there were other differences relating to fetching positioning from the GOT, but that's the main change I noticed. |