Repository navigation
[Backtracing][Linux] Add support for Linux in the _Backtracing module. - #66335
Merged
Merged
Conversation
This also adds a function to demangle a symbol, and a way for the backtracing code to report warning messages to the same place as the main runtime. I'd like to rename the _swift_isThunkFunction() SPI also, but we can't do that until we've made the changes to the _Backtracing library, so we'll do that there instead. rdar://110261430
Contributor
Author
al45tair
force-pushed
the
eng/PR-110261712
branch
from
June 5, 2023 15:12
30559c8 to
c8377ae
Compare
This was referenced Jun 5, 2023
This was added to a later PR, but not to this one, though we need it here. rdar://110261430
Contributor
Author
|
@swift-ci Please smoke test |
This should have been disabled until swiftlang#66338. rdar://110261430
al45tair
force-pushed
the
eng/PR-110261712
branch
from
June 5, 2023 21:35
c8377ae to
0d7c45d
Compare
Contributor
Author
|
@swift-ci Please smoke test |
Contributor
Author
|
@swift-ci Please smoke test Linux platform |
Contributor
Author
Contributor
Author
|
If you're wondering where the tests are, I left them until the last PR (#66338) so everything was enabled and they'd actually work. |
mikeash
approved these changes
Jun 6, 2023
mikeash
left a comment
Contributor
There was a problem hiding this comment.
LGTM. I'm trusting you and your tests for large chunks of the DWARF/ELF/compression stuff.
Mike and Max made various helpful suggestions, so I've added and updated various comments and amended the code to cope with partial reads and writes. rdar://110261430
Moved the comment for `_swift_backtrace_demangle` into the header file instead of it being in the implementation. rdar://110261430
The Swift backtracer's frame pointer unwinder cannot work on Linux without this change, because the compiler omits the frame pointer from the function in libSwift_Backtracing that actually captures the stack. rdar://110260855
Using `SwiftShims` is undesirable - it creates all kinds of build issues, and means shipping the `_SwiftBacktracing.h` header in the SDK, which is not necessary. While we're doing this, add the necessary definitions for reading ELF and DWARF information. rdar://110261712
Use the new module structure rather the old SwiftShims header. This is much cleaner and lets us include operating system headers to get the relevant definitions where possible. Add code to support ELF and DWARF, including decompression using zlib, zstd and liblzma if those turn out to be required and available. rdar://110261712
This is for compatibility, so that I can split up the PRs. We'll remove it in the next PR. rdar://110261712
al45tair
force-pushed
the
eng/PR-110261712
branch
from
June 6, 2023 16:20
0d7c45d to
5e709b3
Compare
Contributor
Author
|
@swift-ci Please smoke test |
There's a chance that pipes might perform a partial read; we should handle that case. rdar://110261712
al45tair
force-pushed
the
eng/PR-110261712
branch
from
June 6, 2023 17:22
5e709b3 to
8d91384
Compare
Contributor
Author
|
@swift-ci Please smoke test |
etcwilde
reviewed
Jun 6, 2023
etcwilde
left a comment
Member
There was a problem hiding this comment.
Okay, some comments. Maybe could use a little more documenting. The code mostly looks fine though.
etcwilde
reviewed
Jun 6, 2023
The `status` argument to the `_swift_backtrace_demangle()` function isn't especially useful, won't match behaviour on Windows, and we actually don't use it in the Swift code that calls this SPI. Remove it. rdar://110261712
`__cxa_demangle()` is a rather unusual API; one of its "features" is that the pointer you pass in must either be `nullptr`, in which case it will call `malloc()` itself, _or_ it has to be a pointer to a block of memory allocated with `malloc()`, because `__cxa_demangle()` may `realloc()` it for you. This seems to me to be something of a non-obvious footgun, so we never pass the caller's pointer through to `__cxa_demangle()`, which lets them decide how they want to allocate space. rdar://110261712
Contributor
Author
|
@swift-ci Please smoke test |
…ule. There's a separate declaration here because we can't include the `Backtrace.h` header from inside `modules/Runtime/Runtime.h`. rdar://110261712
The `_Backtracing` module has a number of private implementation only imports that aren't used outside of the module and that don't require any additional libraries (hence they aren't relevant to the outside world). `verify_all_overlays.py` needs to know about these when it does its test, because it loadas the module as the main module, which results in implementation only imports being required instead of ignored. rdar://110261712
Contributor
Author
|
@swift-ci Please test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rearrange things to avoid using SwiftShims, because that's grotty and means we have to carry all kinds of definitions from the C library. Instead, turn off implicit modules for the
_Backtracingbuild and add some explicit modules that we can use as we please.Also add the code to handle ELF and DWARF for Linux, including symbol lookup, demangling, line number/source file extraction, Linux
mcontext_tsupport et al.Tests for all of this will be in a separate PR that also enables everything.
rdar://110261712