[PATCH] dependency list for static libraries

Howard Chu hyc@symas.com
Wed Oct 28 14:35:45 GMT 2020


Peter Smith via Binutils wrote:
> Apologies in advance if the webmail client mangles the response or threading.
> 
> Just wanted to add to MaskRay's concerns about what the semantics are for a linker.
> * Where are the static library dependencies placed in the order of input files? Immediately after the static library seems the most logical choice although this will make it harder for users to interpose objects/libraries to override choices.

One major advantage of this approach is that if an end user needs to make changes, they can easily do
so without requiring the original source code or a compiler.

> * What happens when there are cyclic dependencies between libraries? Would the user be expected to know to wrap an individual library in a start-group end-group? Should the linker implicitly add start-group end-group around the dependencies?

I don't see how this is relevant. Circular dependencies would be a problem and would require the same
solution regardless.

> * This does seem like it will work for libraries designed to be incorporated as a whole (like a dynamic library), but it seems like it could have awkward corner cases.
> 
> Although not fundamentally opposed to this; personally I'm not a fan of encoding dependencies for static libraries. I see these more of a collection of objects and not a single entity like a dynamic library. If static libraries are being used whole, one way of implementing this would be to add a member to the library that is just a linker script with INPUT and GROUP commands, and link using --whole-archive.

If you're making a lot of use of --whole-archive You're Doing It Wrong. Should just use "ld -r -o aggregate.o foo.o bar.o ..."
and save the linker trouble later. Though this raises an interesting point, why not just eliminate the distinction between
libraries and individual .o files, like the AIX linker does? I.e., the AIX linker is capable of extracting individual required
symbols from a .o file, instead of just linking the entire thing as a unit.

-- 
  -- Howard Chu
  CTO, Symas Corp.           http://www.symas.com
  Director, Highland Sun     http://highlandsun.com/hyc/
  Chief Architect, OpenLDAP  http://www.openldap.org/project/


More information about the Binutils mailing list