This is the mail archive of the binutils@sourceware.org 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]

Eliminating relocation entries in partiallly linked objects


Hi all,

I'm trying to restrict symbol visibility in a static library such that
only specific symbols appear in the symbol table. This is pretty
straightforward in the shared object case, but I haven't been able to
make it work in the static case.

My approach has been to link the objects in my archive into a single
relocatable object, use objcopy to localize any symbols that aren't to
be exported, then strip the resulting object. This isn't working because
the linker generates relocation entries for the references to global
symbols, thus requiring the symbol for relocation, thus preventing them
to be stripped, even after I've changed them to be local.

I'm wondering if there's a way I can run the resulting object through
the linker a second time to remove the relocations on the now-local
symbols, but I haven't figured it out yet. I'm most interested in the
ARM ELF case, but it seems to happen on x86/x86_64 ELF as well (example
below). Can this be done?

John


Examples:

do_it.c:
  int do_it(void) {return 0};
wrapper.c:
  void wrapper(void) {do_it();}

$ gcc -c wrapper.c do_it.c
$ ld -r -o module.o wrapper.o do_it.o
$ objcopy -G wrapper -x module.o 
$ nm module.o 
00000010 t do_it
00000000 T wrapper

$ objcopy --strip-symbol do_it module.o
objcopy: not stripping symbol `do_it' because it is named in a
relocation

$ readelf -r module.o
Relocation section '.rel.text' at offset 0x2a8 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000007  00000902 R_386_PC32        00000010   do_it




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