Skip to content

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

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

Merged
merged 1 commit into from
Jul 1, 2025

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 mikeash as a code owner June 30, 2025 13:24
@al45tair
Copy link
Contributor Author

@swift-ci Please smoke test

}
imageBase = ImageSource.Address(exactly: minAddr ?? 0)!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any benefit to failing gracefully here for values that aren't representable, like minAddr.map { ImageSource.Address(exactly: $0) } ?? 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. On the one hand, that would stop it crashing in such a case. On the other, I think that's rather unlikely in practice (ImageSource.Address is usually UInt64).

@al45tair al45tair merged commit 76f2351 into swiftlang:main Jul 1, 2025
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants