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

[Backtracing][Linux] Add Linux support to swift-backtrace. #66410

Merged
merged 17 commits into from Jun 7, 2023

Commits on Jun 7, 2023

  1. [Backtracing][Linux] Add Linux crash handler to the runtime.

    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
    al45tair committed Jun 7, 2023
    Copy the full SHA
    bfe8087 View commit details
    Browse the repository at this point in the history
  2. [Backtracing][Linux] Add missing CrashInfo.h header.

    This was added to a later PR, but not to this one, though we need
    it here.
    
    rdar://110261430
    al45tair committed Jun 7, 2023
    Copy the full SHA
    dc05590 View commit details
    Browse the repository at this point in the history
  3. [Backtracing][Linux] Disable backtrace-on-crash until enabling PR.

    This should have been disabled until apple#66338.
    
    rdar://110261430
    al45tair committed Jun 7, 2023
    Copy the full SHA
    546c93d View commit details
    Browse the repository at this point in the history
  4. [Backtracing][Linux] Tidy a few things up after review.

    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
    al45tair committed Jun 7, 2023
    Copy the full SHA
    fe6238a View commit details
    Browse the repository at this point in the history
  5. [Backtracing][Linux] Move doc comment to header.

    Moved the comment for `_swift_backtrace_demangle` into the header file
    instead of it being in the implementation.
    
    rdar://110261430
    al45tair committed Jun 7, 2023
    Copy the full SHA
    8ee9b8b View commit details
    Browse the repository at this point in the history
  6. [Backtracing][IRGen] Add a semantic attribute to force frame pointer.

    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
    al45tair committed Jun 7, 2023
    Copy the full SHA
    49ac8c3 View commit details
    Browse the repository at this point in the history
  7. [Backtracing][Linux] Reorganise modules for _Backtracing.

    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
    al45tair committed Jun 7, 2023
    Copy the full SHA
    33e1af1 View commit details
    Browse the repository at this point in the history
  8. [Backtracing][Linux] Add Linux support to the _Backtracing module.

    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
    al45tair committed Jun 7, 2023
    Copy the full SHA
    efa90a5 View commit details
    Browse the repository at this point in the history
  9. [Backtracing][Linux] Temporarily add a default addressWidth.

    This is for compatibility, so that I can split up the PRs.
    We'll remove it in the next PR.
    
    rdar://110261712
    al45tair committed Jun 7, 2023
    Copy the full SHA
    e3b8e51 View commit details
    Browse the repository at this point in the history
  10. [Backtracing][Linux] Work correctly in the presence of partial reads.

    There's a chance that pipes might perform a partial read; we should
    handle that case.
    
    rdar://110261712
    al45tair committed Jun 7, 2023
    Copy the full SHA
    3e2df1f View commit details
    Browse the repository at this point in the history
  11. [Backtracing][Linux] Remove status argument.

    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
    al45tair committed Jun 7, 2023
    Copy the full SHA
    1d8fe3b View commit details
    Browse the repository at this point in the history
  12. [Backtracing][Linux] Add a comment about __cxa_demangle.

    `__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
    al45tair committed Jun 7, 2023
    Copy the full SHA
    3791b47 View commit details
    Browse the repository at this point in the history
  13. [Backtracing][Linux] Also remove the status argument from Runtime mod…

    …ule.
    
    There's a separate declaration here because we can't include the `Backtrace.h`
    header from inside `modules/Runtime/Runtime.h`.
    
    rdar://110261712
    al45tair committed Jun 7, 2023
    Copy the full SHA
    b664339 View commit details
    Browse the repository at this point in the history
  14. [Backtracing][Linux][Tests] Fix verify_all_overlays test.

    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
    al45tair committed Jun 7, 2023
    Copy the full SHA
    b25a04c View commit details
    Browse the repository at this point in the history
  15. [Backtracing][Linux] Add Linux support to swift-backtrace.

    We need a Linux specific `Target` implementation, and a couple of minor
    tweaks to make things build everywhere.
    
    rdar://110262673
    al45tair committed Jun 7, 2023
    Copy the full SHA
    7cc2446 View commit details
    Browse the repository at this point in the history
  16. Copy the full SHA
    9379477 View commit details
    Browse the repository at this point in the history
  17. [Backtracing][Linux] Remove some stray "public" annotations.

    We don't need these here.  They were a leftover from previous code.
    
    rdar://110262673
    al45tair committed Jun 7, 2023
    Copy the full SHA
    f61e72c View commit details
    Browse the repository at this point in the history