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

Android: -ldl must appear after -lgcc when linking #91381

Closed
wants to merge 1 commit into from

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Nov 30, 2021

#90846 accidentally broke Android builds because it causes the standard library to no longer use dlsym on Android. This results in libdl being ignored by the linker since no symbols are needed from it. However, we later import libgcc for unwinding which does depend on libdl for dl_iterate_phdr. Since linkers don't revisit previous libraries when resolving symbols, this causes a linker error due to an undefined reference to dl_iterate_phdr.

This is resolved by adding a second -ldl after -lgcc in the linker command-line.

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 30, 2021
@petrochenkov
Copy link
Contributor

the standard library to no longer use dlsym on Android. This results in libdl being ignored by the linker since no symbols are needed from it.

In this case perhaps libdl shouldn't be passed at all to save some work for the linker.
(I assume it's the one from library\std\src\sys\unix\mod.rs?)

@Amanieu
Copy link
Member Author

Amanieu commented Nov 30, 2021

It's getting included by the unwindcrate anyways so it doesn't matter in this end.

The link flags are a bit weird: some are defined in the libc crate and others in std, with no clear pattern.

@petrochenkov
Copy link
Contributor

The link flags are a bit weird: some are defined in the libc crate and others in std, with no clear pattern.

The rule of thumb is that if std uses something directly from libX then it adds a dependency on X, and if libc uses (reexports in that case) something directly from libX then it adds a dependency of X.
(Of course people forget to update dependencies or rely on accidental dependencies all the time, but ideally such cases should be fixed if found.)

@Amanieu
Copy link
Member Author

Amanieu commented Nov 30, 2021

I think a proper cleanup of the link attributes in std/libc can be done in another PR. In the meantime, CI on stdarch is blocked on this PR because android builds are failing.

@apiraino apiraino added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Dec 1, 2021
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Dec 2, 2021

📌 Commit 41e2a53 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 2, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 3, 2021
Android: -ldl must appear after -lgcc when linking

rust-lang#90846 accidentally broke Android builds because it causes the standard library to no longer use `dlsym` on Android. This results in `libdl` being ignored by the linker since no symbols are needed from it. However, we later import `libgcc` for unwinding which *does* depend on `libdl` for `dl_iterate_phdr`. Since linkers don't revisit previous libraries when resolving symbols, this causes a linker error due to an undefined reference to `dl_iterate_phdr`.

This is resolved by adding a second `-ldl` after `-lgcc` in the linker command-line.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 3, 2021
Android: -ldl must appear after -lgcc when linking

rust-lang#90846 accidentally broke Android builds because it causes the standard library to no longer use `dlsym` on Android. This results in `libdl` being ignored by the linker since no symbols are needed from it. However, we later import `libgcc` for unwinding which *does* depend on `libdl` for `dl_iterate_phdr`. Since linkers don't revisit previous libraries when resolving symbols, this causes a linker error due to an undefined reference to `dl_iterate_phdr`.

This is resolved by adding a second `-ldl` after `-lgcc` in the linker command-line.
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 3, 2021
…askrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#88906 (Implement write() method for Box<MaybeUninit<T>>)
 - rust-lang#90269 (Make `Option::expect` unstably const)
 - rust-lang#90854 (Type can be unsized and uninhabited)
 - rust-lang#91170 (rustdoc: preload fonts)
 - rust-lang#91273 (Fix ICE rust-lang#91268 by checking that the snippet ends with a `)`)
 - rust-lang#91381 (Android: -ldl must appear after -lgcc when linking)
 - rust-lang#91453 (Document Windows TLS drop behaviour)
 - rust-lang#91462 (Use try_normalize_erasing_regions in needs_drop)
 - rust-lang#91474 (suppress warning about set_errno being unused on DragonFly)
 - rust-lang#91483 (Sync rustfmt subtree)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Contributor

bors commented Dec 3, 2021

☔ The latest upstream changes (presumably #91486) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 3, 2021
@pietroalbini
Copy link
Member

This has been merged into master by bors (in #91486), but GitHub didn't detect it for whatever reason. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants