patchGNU Libtool - Patches: patch #9687, bugfix: make -export-dynamic imply...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #9687: bugfix: make -export-dynamic imply --whole-archive

Submitted by:  David Lamparter <equinox>
Submitted on:  Tue 04 Sep 2018 11:56:34 AM UTC
 
Category:  None Priority:  6
Status:  Need Info Privacy:  Public
Assigned to:  growpotkin Open/Closed:  Open
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       No canned response available

 

Sat 20 Nov 2021 04:28:29 PM UTC, comment #2: 

Well, it's now 3 years later, and my memory of details on this is pretty much gone, but let's try.  No warranty on anything here, I'm trying to reconstruct.

comment #1:

> Could you maybe elaborate on your use case? Perhaps there's something that I'm missing.


Any executable linked with `-export-dynamic` that links static libraries may end up missing globally visible symbols if they are not used by the executable itself.  If the program then tries to load a module that needs these symbols, it fails.

> In my opinion : the existing behavior both by `ld' and `libtool' is appropriate. Implying `--whole-archive' for dependency libraries in with `-export-dynamic' will prevent users from intentionally localizing symbols.


`--whole-archive` has no impact on symbol visibility; I don't follow at all what you're trying to say here.  A binary linked with `-export-dynamic` is essentially a shared library, and the `ld` docs state:

"This is normally used to turn an archive file into a shared library, forcing every object to be included in the resulting shared library."

I agree `ld` is doing the appropriate thing here, but `libtool` isn't.  A binary with `-export-dynamic` needs to export ALL of its global symbols from ALL of its files for dynamically loaded modules to use.  It is essentially a shared library at the same time and needs to be treated as such.

NB: `--whole-archive` does NOT make all symbols globally visible! This is about objects, i.e. files.  If you have a file getting linked in that has some global symbols, but none of them are used in the binary itself - `ld` will drop the entire file.  That's the wrong thing to do for both creating a shared library as well as for creating an executable with `-export-dynamic`.

> I see these flags as having distinct use cases. I'll note that, the need for using `--whole-archive' with `ld' isn't necessarily intuitive to users, so I see the appeal of using it in many situations - but adding additional variance between `libtool' and `ld' does not seem justified to me.


If I remember correctly, I couldn't find a way to manually add `--whole-archive` to the linker invocation that libtool does, because the option is ordering-sensitive to the file names on the ld command line.  I also do not understand what you mean with "variance" between `libtool` and `ld` - there is no equivalency here.  `libtool` is a user/wrapper of `ld` that has the express purpose of figuring out the "right" flags for `ld`, and it's failing at its job.

Also: what is that distinct use case for `--whole-archive`?  I think it's exactly this situation right here... the ld docs even hint at it.

> If the intention is to export symbols which are defined in statically linked `libtool' libraries a "convenience library" ( `noinst_' ) might be what you're actually looking for?


Barring my memory failing me, I think we tried that and it simply has the same problem.

The patch posted here has been shipped in FRRouting for 3 years now, it has not caused any breakage in any OS/distribution (prominently: Debian, Ubuntu, RHEL, *BSD, …) - as such I would urge you to just merge it and move on.  I would happily help you in understanding the issue here, but I can't do that with having more or less lost my own understanding of it.  Sorry about that, but there's a boatload of other stuff I need to understand, and my brain is not infinite :(.

David Lamparter <equinox>
Fri 19 Nov 2021 04:56:43 AM UTC, comment #1: 

Could you maybe elaborate on your use case? Perhaps there's something that I'm missing.

In my opinion : the existing behavior both by `ld' and `libtool' is appropriate. Implying `--whole-archive' for dependency libraries in with `-export-dynamic' will prevent users from intentionally localizing symbols.

I see these flags as having distinct use cases. I'll note that, the need for using `--whole-archive' with `ld' isn't necessarily intuitive to users, so I see the appeal of using it in many situations - but adding additional variance between `libtool' and `ld' does not seem justified to me.

If the intention is to export symbols which are defined in statically linked `libtool' libraries a "convenience library" ( `noinst_' ) might be what you're actually looking for?

Alex Ameen <growpotkin>
Project Administrator
Tue 04 Sep 2018 11:56:34 AM UTC, original submission:  

libtool: -export-dynamic implies --whole-archive

   

The usage of -export-dynamic implies that the program is going to load DSOs that need some of the program's symbols.  However, the linker will still drop anything that it doesn't see a reference to when linking archives.  This then breaks when the DSO tries to use something from an archive that the linker didn't bother to include.

   
  • build-aux/ltmain.in:  if -export-dynamic is given, put

  -Wl,--whole-archive around any archives we link in.

   

This changeset is placed in the public domain.

David Lamparter <equinox>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by growpotkin (Posted a comment)
  • -email is unavailable- added by equinox (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

     

     

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-11-19 growpotkin StatusNone => Need Info
        Assigned toNone => growpotkin
    2018-09-04 equinox Attached File- => Added 0001-libtool-export-dynamic-implies-whole-archive.patch, #44931

    Back to the top


    Powered by Savane 3.9