From: Joel Fernandes on
Hello,
I have a small question about relocation in object files (.o)
generated by a compiler for i386.

In my example, I'm using 32 bit x86, and the gcc compiler with the -c
option to generate objects without linking them.

I am interested in understanding the following behavior: If I define a
function as static, then no relocation entries are created to fixup
address of callers in the same object file, but not defining the
function as static creates such relocation entries.

My questions are:
1. Since the call instruction uses relative addressing anyway, why are
reloc entries required at all for fixing up callers in the same object
file?
2. Why aren't such the relative addresses computed or relocation
entries created for non-static functions?

thanks,
Joel
From: MitchAlsup on
A relocation entry does two things, it supplies a name that the
outside world (the linker) can use to determine a memory location, and
it also provides an offset into and the segment name so that an
external reference can be 'linked' to the named item. The linker can
then locate (determine the virtual address at which they will sit) all
of the segments, and by knowing the absolute (virtual=linear) address
of the item, can then make proper offset calculations and fixes up the
instruction bytestream so the extrenal 'caller' will arrive at the
called function entry point.

The word static in 'C' only eliminates the name so the linker (and
nobody else) can see this location and thus cannot 'call' it.

As to question 2--this is probably the compiler defering to the linker
all of the call-point relocations. The linker has to know how to do
it, the compiler has to know how to tell the linker to do it, so why
should the compiler also have to know how to do it?

Mitch
From: nmm1 on
In article <830e6110-a740-498a-82d8-0cc3e0a3023a(a)c33g2000yqm.googlegroups.com>,
MitchAlsup <MitchAlsup(a)aol.com> wrote:
>
>The word static in 'C' only eliminates the name so the linker (and
>nobody else) can see this location and thus cannot 'call' it.

Not quite, but close enough. Until you also add 'inline', when
sanity is thrown out of the window ....


Regards,
Nick Maclaren.
From: Joel Fernandes on
> >The word static in 'C' only eliminates the name so the linker (and
> >nobody else) can see this location and thus cannot 'call' it.
>
> Not quite, but close enough.  Until you also add 'inline', when
> sanity is thrown out of the window ....

hehe.

-Joel