This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: ld generates static relocations in shared library
- From: nick clifton <nickc at redhat dot com>
- To: Thomas Schmid <scth2000 at yahoo dot de>, "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Fri, 23 Aug 2013 11:52:24 +0100
- Subject: Re: ld generates static relocations in shared library
- References: <1374764028 dot 31727 dot YahooMailNeo at web172604 dot mail dot ir2 dot yahoo dot com>
Hi Thomas,
If I compile the example code at the bottom with
arm-elf-gcc init.c -o lib.so -Wl,-shared -nostdlib
I get a shared library with some relocations (readelf lib.so -r):
0000032c 00000d02 R_ARM_ABS32 000004b8 plpv1
Yes - this is correct...
>Static relocations are processed by a static linker; they are normally either fully resolved or used to produce dynamic relocations
>for processing by a post-linking step or a dynamic loader. A well formed image will have no static relocations after static linking
>is complete,
Right - but libso.so is not a fully linked binary. It is a shared
library that is going to be used as part of another static link operation.
For example:
% cat main.c
extern void func (void);
extern int printf (const char *, ...);
unsigned char lpv1, lpv2;
int main (void)
{
lpv1 = 1;
lpv2 = 2;
func ();
return printf ("lpv1 = %d lpv2 = %d\n", lpv1, lpv2);
}
% arm-elf-gcc main.c -L. lib.so
% readelf -r a,out
Relocation section '.rel.plt' at offset 0x8220 contains 5 entries:
Offset Info Type Sym.Value Sym. Name
0001a984 00000216 R_ARM_JUMP_SLOT 00000000 malloc
0001a988 00000416 R_ARM_JUMP_SLOT 00000000 __deregister_frame_inf
0001a98c 00000916 R_ARM_JUMP_SLOT 0000828c func
0001a990 00000e16 R_ARM_JUMP_SLOT 00000000 __register_frame_info
0001a994 00001016 R_ARM_JUMP_SLOT 00000000 free
So now all of the static relocations have been resolved and only dynamic
relocations remain.
Cheers
Nick