public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* dependency list for static libraries
@ 2017-09-19 15:49 Howard Chu
  2017-09-19 15:52 ` Simon Richter
  2017-09-19 16:54 ` Joseph Myers
  0 siblings, 2 replies; 64+ messages in thread
From: Howard Chu @ 2017-09-19 15:49 UTC (permalink / raw)
  To: binutils

We often get link errors when switching from dynamic linking to static 
linking, because dynamic libraries list all of their own dependency libraries, 
and static libraries don't. (And the program being linked doesn't know about 
those indirect dependencies.)

It Would Be Nice if we could add a dependency list to a static library too. 
Much like ranlib creates an index for a static library already, store the list 
of dependencies in a reserved module.

It seems to me I've made this suggestion before but Google and my memory have 
failed to locate it. We'd need either a new tool like ranlib, or a new flag to 
ar to store a list of dependencies, and then linker support to lookup the 
dependency list whenever referencing a static library.
-- 
   -- Howard Chu
   CTO, Symas Corp.           http://www.symas.com
   Director, Highland Sun     http://highlandsun.com/hyc/
   Chief Architect, OpenLDAP  http://www.openldap.org/project/

^ permalink raw reply	[flat|nested] 64+ messages in thread
* Re: [PATCH] dependency list for static libraries
@ 2020-09-30 10:33 Peter Smith
  2020-10-28 14:35 ` Howard Chu
  0 siblings, 1 reply; 64+ messages in thread
From: Peter Smith @ 2020-09-30 10:33 UTC (permalink / raw)
  To: Fangrui Song; +Cc: binutils

> Thanks to Nick for mentioning me :)
>
>On 2020-09-23, Howard Chu wrote:
>>Nick Clifton wrote:
>>> Hi Howard,
>>>
>>>> Sorry for the noise, this attached is the same as previous but with fixes
>>>> to whitespace / indentation.
>>>
>>> Thanks - the patch looks good now, although there are still a couple of minor
>>> issues - and one major issue:
>>>
>>>>   * The new test fails for the alpha-vms target.  This is not serious however
>>>     as almost all of the ar tests fail for this target.  One day I will track
>>>     down what is going wrong and either fix it, or arrange to skip these tests
>>>     for alpha-vms.
>>>
>>>   * There are a couple of minor formatting issues.  Specifically: comments should
>>>     end in a period followed by two spaces before the closing marker. /* Like this.  */
>>>     Plus function calls should have a space between the function name and the
>>>     opening parenthesis of the argument list.  like (this)
>>
>>I can send an updated patch after the major issue is addressed.
>>
>>> The major issue is that I would really like for this extension to be supported
>>> by the LLVM community as well.  It would be a shame to add it to the binutils
>>> only to have a different solution implemented there.  I might have misread the
>>> emails but I believe that Fangrui still has some misgivings about this approach.
>>> Is that correct ?  If so, then I would very much like to see them resolved
>>> before we commit the patch.
>>
>>It still seems pretty obvious that handling dependencies once at the library
>>level is more efficient than sticking a bunch of free-form notes in every single
>>object file. And it should also be obvious that choice of library is a buildtime
>>decision, not a decision made solely at the time the source code is written.
>>(And for shared libraries, it's a runtime decision - even further removed from
>>the time of code being written.)
>
> From my experience (I have investigated hundreds of link issues),
>archive link errors are usually caused by the following two problems:
>
>* There is a backward reference between two archives. This is related to a.out/ELF style linker >behaviors
>(https://sourceware.org/pipermail/binutils/2020-September/113194.html ).
>   + A dependency exists but is incorrectly omitted. The linker actually captures a layering problem.
>   + A dependency is intentionally omitted. If the linker allows backward references, this will not be >a problem.
>
>   I have recently thought a lot on the topic and written http://lld.llvm.org/ELF/warn_backrefs.html
>
>* Some archives are incorrectly omitted: the executable uses A, but A's
>   dependency B is not on the command line.  Now I hope Howard can clarify on this
>   topic:) What do you want to achieve with the dependency recorded in the archive?
>   I assume that you want the linker to smartly link B. This is indeed the #pragma
>   comment(lib, ...) and .deplibs feature clang/LLD support.
>
>   The proposal does not mention the ld part, which seems important. How
>   does ld handle __.LIBDEP ?
>
>   + The executable also references B and you don't want to write its dependency on B.
>     This is the traditional --copy-dt-needed-entries behavior (that the
>     designers of gold explicitly do not want to support). The linker traverses all
>    dependencies of shared objects recursively. This is against the "include what
>     you use" philosophy.  https://github.com/include-what-you-use/include-what-you->use/blob/master/docs/WhyIWYU.md
>     It imposes a lot of extra work for the linker. It makes the build brittle - if
>     A removes its dependency on B, you need to find and fix all the transitive users
>     of A. I hope this proposal is not about the bullet point.
>   + The executable does not references B. I am still unsure why you want to move the dependency information from the
>     object file to the archive.
>     - First, I want to mention that in some cases archives are not needed. For
>       some use cases people propose thin archives.  For some thin archive use cases,
>       --start-lib --end-lib surrounded object files are probably more useful.  gold
>       pioneered the idea but GNU ld still does not support the feature
>       https://sourceware.org/bugzilla/show_bug.cgi?id=24600
>     - Moving the dependency to the archive can actually increases the work for
>       the linker.  Say the two members of A are a0.o and a1.o. If a0.o depends on B
>       but a0.o is not selected, then B does not need to be linked. Having the
>       dependency in the archive will cause B to be linked.
>     - How do you ensure the dependency information does not become stale? i.e.
>       How do you maintain the dependency information when members are added to/removed from
>       the archive? The information is more difficult to maintain than the index, which only contains
>       the definitions. You may argue that the archive is finalized after it is created - then
>       we go back to square one, --start-lib may be more suitable.
>
>---
>
>Last,
>
>>  fprintf (s, _("  [L LIBDEPS]  - specify dependencies of this library\n"));
>
>In llvm-ar, 'L' is an extension used with 'q' to add all members of an archive to the current archive.
>It is similar to ADDLIB (https://sourceware.org/binutils/docs/binutils/ar-scripts.html )
>Hope the two tools don't have conflicting operations.

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.
* 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?
* 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.

Peter 

(infrequent LLD contributor)




^ permalink raw reply	[flat|nested] 64+ messages in thread

end of thread, other threads:[~2020-12-23 18:23 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-19 15:49 dependency list for static libraries Howard Chu
2017-09-19 15:52 ` Simon Richter
     [not found]   ` <WM!bae999665f49907786872b93f01ac98d53e7b97e29b4228399d8baadf9ec0ab33db74467d73c998225b250ba1d00a4c0!@mailstronghold-3.zmailcloud.com>
2017-09-19 16:04     ` Howard Chu
2017-09-20  1:42       ` R0b0t1
2017-09-19 16:54 ` Joseph Myers
     [not found]   ` <WM!83b6ad7285aa96ce69fcd1944d4eae8f20e5f19dfbf161f45313f5393bcffe1b77231520b8f4e24145a3f85eeafb39ed!@mailstronghold-1.zmailcloud.com>
2017-09-19 22:01     ` Howard Chu
2017-09-20  0:20       ` Joseph Myers
2020-09-03 20:42       ` Howard Chu
2020-09-22 10:39         ` Nick Clifton
2020-09-22 11:42           ` Howard Chu
2020-09-22 13:12             ` Nick Clifton
2020-09-22 16:23               ` [PATCH] " Howard Chu
2020-09-22 17:16                 ` Fangrui Song
2020-09-22 17:55                   ` Howard Chu
2020-09-22 20:46                 ` Howard Chu
2020-09-23 11:52                   ` Nick Clifton
2020-09-23 15:29                     ` Howard Chu
2020-09-24  5:21                       ` Fangrui Song
2020-09-24  9:19                         ` Howard Chu
2020-09-24  9:30                           ` Howard Chu
2020-09-28 11:07                           ` Howard Chu
2020-10-28 14:56                     ` Howard Chu
2020-11-03 15:14                       ` Nick Clifton
2020-11-03 15:31                         ` Howard Chu
2020-11-08  1:39                           ` Alan Modra
2020-11-08 15:07                             ` Howard Chu
2020-11-09  0:01                               ` Alan Modra
2020-11-10  2:44                                 ` Howard Chu
2020-11-10 11:07                                   ` Alan Modra
2020-11-11 14:57                                     ` Howard Chu
2020-11-11 14:59                                       ` Howard Chu
2020-11-17 14:01                                         ` Nick Clifton
2020-11-04  0:33                         ` Howard Chu
2020-11-04 11:01                           ` Nick Clifton
2020-11-04 14:50                             ` Howard Chu
2020-11-06 12:38                               ` Nick Clifton
2020-11-13 14:40                               ` Howard Chu
2020-11-24 17:49                                 ` Howard Chu
2020-11-25 11:17                                   ` Nick Clifton
2020-12-01  0:08                                     ` Howard Chu
2020-12-14 14:28                                       ` Nick Clifton
2020-12-15 16:17                                         ` Jim Wilson
2020-12-15 16:22                                           ` Jeff Law
2020-12-15 16:50                                             ` Nick Clifton
2020-12-15 19:11                                               ` Jeff Law
2020-12-15 20:04                                                 ` Jim Wilson
2020-12-15 20:22                                               ` Cary Coutant
2020-12-15 20:51                                                 ` Howard Chu
2020-12-16 11:16                                                   ` Nick Clifton
2020-12-16 14:49                                                     ` [PATCH] ld: Call plugin hooks only if they are available H.J. Lu
2020-12-16 18:34                                                       ` Howard Chu
2020-12-16 18:40                                                         ` H.J. Lu
2020-12-16 19:06                                                           ` Howard Chu
2020-12-16 19:11                                                             ` [PATCH] ld: Skip libdep plugin if not all plugin hooks " H.J. Lu
2020-12-16 21:26                                                               ` Howard Chu
2020-12-16 21:47                                                                 ` H.J. Lu
2020-12-16 18:44                                                         ` [PATCH] ld: Call plugin hooks only if they " Howard Chu
2020-12-15 20:33                             ` [PATCH] dependency list for static libraries Cary Coutant
2020-12-15 20:53                               ` Howard Chu
2020-12-16 11:18                                 ` Nick Clifton
2020-12-23 13:27                         ` Matthias Klose
2020-12-23 18:23                           ` Howard Chu
2020-09-30 10:33 Peter Smith
2020-10-28 14:35 ` Howard Chu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).