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]

Re: ar: POSIX way of creating static library containing similarly named objects


Hi Miguel,

Consider the following two objects,

   src/namespace_foo/state.o
   src/namespace_bar/state.o

Can `ar' be used to create a static library comprised of the objects
above without either of which replacing any symbols? In other words, both
namespace_foo/state.o and namespace_bar/state.o are put into the same
library but no symbols are replaced.

Use the 'q' option rather than the 'r' option when adding the object files to the library - and create the symbol index after adding the objects, rather than at the same time. Ie:

  % ar cr libstate.a src/namespace_foo/state.o
  % ar q  libstate.a src/namespace_bar/state.o
  % ar s  libstate.a
  % readelf -c libstate.a
  Index of archive libstate.a: (2 entries, 0x8 bytes in the symbol table)
  Binary libstate.a(state.o) contains:
        foo
  Binary libstate.a(state.o) contains:
        foo

Note - you can also achieve the same effect by creating the library and its index with just a single command:

  % ar crs libstate.o src/namespace_foo/state.o src/namespace_bar/state.o
  % ar t libstate.o
  state.o
  state.o

This appears to be a bug in the implementation of AR - the "r" command line option should eliminate duplicate entries.

Also note - if you create the symbol index at the same time as you quick-append a duplicate file to the library, the duplicate will be discarded:

  % ar cr libstate.a src/namespace_foo/state.o
  % ar qvs libstate.a src/namespace_bar/state.o
  r - namespace_bar/state.o
  % ar t libstate.a
  state.o

This is another bug. The "s" option is making the "q" option behave as if it were "r".

Cheers
  Nick



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