This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ld generates static relocations in shared library

Hi Thomas,
If I compile the example code at the bottom with

     arm-elf-gcc init.c -o -Wl,-shared -nostdlib

I get a shared library with some relocations (readelf -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 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.

  % 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]