Skip to content

[Backtracing][Linux] Fix crash handler for musl. #82634

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

Open
wants to merge 1 commit into
base: release/6.2
Choose a base branch
from

Conversation

al45tair
Copy link
Contributor

Musl's clone() wrapper returns EINVAL if you try to use CLONE_THREAD, which seems a bit wrong (certainly it is in this particular application, since we really don't care whether the thread is a valid C library thread at this point).

Also properly support ELF images that are built with a base address other than zero (this typically isn't an issue for dynamically linked programs, as they will be relocated at runtime anyway, but for statically linked binaries it's very common to set the base address to a non-zero value).

rdar://154282813

Musl's `clone()` wrapper returns `EINVAL` if you try to use `CLONE_THREAD`,
which seems a bit wrong (certainly it is in this particular application,
since we *really* don't care whether the thread is a valid C library
thread at this point).

Also properly support ELF images that are built with a base address other
than zero (this typically isn't an issue for dynamically linked programs,
as they will be relocated at runtime anyway, but for statically linked
binaries it's very common to set the base address to a non-zero value).

rdar://154282813
@al45tair al45tair requested a review from a team as a code owner June 30, 2025 16:43
@al45tair al45tair added Linux Platform: Linux 🍒 release cherry pick Flag: Release branch cherry picks swift 6.2 labels Jun 30, 2025
@al45tair
Copy link
Contributor Author

@swift-ci Please test

@al45tair
Copy link
Contributor Author

Explanation: Musl makes clone() fail if you pass CLONE_THREAD, which we are doing because we want to start a new thread in the crashed process (we can't use the pthread APIs for this because we're crashed, we're running from a signal handler, and nothing is safe). There's also an issue with symbol resolution that I found while fixing that problem where statically linked ELF images are built with a fixed non-zero base address, which was causing symbol lookups to fail as I wasn't correctly accounting for that.
Risk: Low. Only affects Linux.
Original PR: #82624
Reviewed by: @mikeash
Resolves: rdar://154282813
Tests: The backtrace's tests will exercise this code for the non-Static SDK case. The Static SDK case was tested manually at a prompt.

@al45tair
Copy link
Contributor Author

al45tair commented Jul 1, 2025

@swift-ci Please test macOS platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linux Platform: Linux 🍒 release cherry pick Flag: Release branch cherry picks swift 6.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant