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

[🍒 stable/20240723] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI #9418

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Oct 15, 2024

Cherry-pick llvm#111332, llvm#112275, llvm#112520, llvm#112569, and llvm#112695 to add coverage support for Wasm targets. Those changes need to be applied together to avoid breaking Windows build.


Original PR description

Currently, WebAssembly/WASI target does not provide direct support for code coverage.
This patch set fixes several issues to unlock the feature. The main changes are:

  1. Port compiler-rt/lib/profile to WebAssembly/WASI.
  2. Adjust profile metadata sections for Wasm object file format.
    • [CodeGen] Emit __llvm_covmap and __llvm_covfun as custom sections instead of data segments.
    • [lld] Align the interval space of custom sections at link time.
    • [llvm-cov] Copy misaligned custom section data if the start address is not aligned.
    • [llvm-cov] Read __llvm_prf_names from data segments
  3. [clang] Link with profile runtime libraries if requested

@kateinoigakukun
Copy link
Member Author

@swift-ci test

…m#111332)

Currently, WebAssembly/WASI target does not provide direct support for
code coverage.
This patch set fixes several issues to unlock the feature. The main
changes are:

1. Port `compiler-rt/lib/profile` to WebAssembly/WASI.
2. Adjust profile metadata sections for Wasm object file format.
- [CodeGen] Emit `__llvm_covmap` and `__llvm_covfun` as custom sections
instead of data segments.
    - [lld] Align the interval space of custom sections at link time.
- [llvm-cov] Copy misaligned custom section data if the start address is
not aligned.
    - [llvm-cov] Read `__llvm_prf_names` from data segments
3. [clang] Link with profile runtime libraries if requested

See each commit message for more details and rationale.
This is part of the effort to add code coverage support in Wasm target
of Swift toolchain.
WASI doesn't support signal, so we should exclude signal.h on WASI.
This patch is only for the swiftlang fork of compiler-rt because those
signal usages don't exist in the upstream.
…ments" (llvm#112520)

This reverts commit efc9dd4 in order to
fix Windows test failure:
llvm#111332 (comment)
…ments (llvm#112569)

On WebAssembly, most coverage metadata contents read by llvm-cov (like
`__llvm_covmap` and `__llvm_covfun`) are stored in custom sections
because they are not referenced at runtime. However, `__llvm_prf_names`
is referenced at runtime by the profile runtime library and is read by
llvm-cov post-processing tools, so it needs to be stored in a data
segment, which is allocatable at runtime and accessible by tools as long
as "name" section is present in the binary.

This patch changes the way llvm-cov reads `__llvm_prf_names` on
WebAssembly. Instead of looking for a section, it looks for a data
segment with the same name.

This reverts commit 157f10d and fixes
PE/COFF `.lprfn$A` section handling.
@kateinoigakukun kateinoigakukun force-pushed the yt/cherry-pick-wasm-coverage-support branch from c181e46 to 6efc1b4 Compare October 24, 2024 17:07
@kateinoigakukun
Copy link
Member Author

@swift-ci test

@kateinoigakukun kateinoigakukun marked this pull request as ready for review October 25, 2024 04:03
@kateinoigakukun
Copy link
Member Author

@swift-ci test

@kateinoigakukun
Copy link
Member Author

@swift-ci test Windows

@kateinoigakukun kateinoigakukun merged commit c0b1b8b into swiftlang:stable/20240723 Oct 31, 2024
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.

1 participant