Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mold leaves out dynamic libraries' imported symbols from executable when provided by static archive #244

Closed
vapdrs opened this issue Jan 4, 2022 · 1 comment

Comments

@vapdrs
Copy link

vapdrs commented Jan 4, 2022

It looks like I found an inconsistency between mold and binutils ld when it comes to keeping static archive symbols in an executable when they are required by a shared library.

In the attached reproducer a shared library is setup to require an imported symbol which can be provided by a static archive. Then both the shared library and that static archive are linked into an executable. The behavior difference is as follows,

  • ld shoves the symbol from the static archive into the executable
  • mold does not include the symbol from the static archive

I'm not sure which behavior is more correct, but this creates an incompatibility between the two linkers.

I tested the reproducer with using both gcc 8.3.0, and clang 9.0.0, as well as using ld.bfs, ld.gold from binutils 2.37, and mold 1.0.1

An interesting note is that mold behaves consistent to ld when the executable is linked with object files directly rather than a static archive.

@rui314
Copy link
Owner

rui314 commented Jan 13, 2022

Thank you for your report and providing me the reproducer. I recently made a change in ce5749c to rewrite our symbol resolution algorithm, and now mold pulls out object files from archives if they can resolve undefined symbols in shared objects, which is more consistent with GNU ld.

@rui314 rui314 closed this as completed Jan 13, 2022
rui314 added a commit that referenced this issue Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants