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

Support parsing bitfields from BTF/DWARF #2505

Merged
merged 5 commits into from
Mar 29, 2023

Commits on Mar 29, 2023

  1. Let CMake generate BTF data for unit tests

    This is done similarly to generating mocked DWARF data, using the same
    source data.
    
    Requires several utilities: pahole, llvm-objcopy, xxd, nm, awk.
    
    Especially llvm-objcopy may be troublesome as it is required by pahole
    but it is often named llvm-objcopy-XX or llvmXX-objcopy where XX is the
    LLVM version.  Hence, we set the LLVM_OBJCOPY env variable which pahole
    is able to process.
    
    Pahole is not packaged in Alpine 3.12 which is used in embedded CI
    tests. Since I was not able to bump Alpine to any newer version that
    would have pahole, we build it from source for now.
    viktormalik committed Mar 29, 2023
    Configuration menu
    Copy the full SHA
    6f7ffd0 View commit details
    Browse the repository at this point in the history
  2. Refactor work with bitfields

    Two important refactorings were done:
    
    - Bitfield info is now stored inside Field as std::optional<Bitfield>
      (instead of bool is_bitfield + Bitfield). This is more convenient to
      work with but required some changes, especially to serialization and
      tests.
    
    - Moved algorithm for computing bitfield information from ClangParser to
      the Bitfield class since the same algorithm will be used for
      generating bitfields from BTF and DWARF.
    
    Requires libcereal version >= 1.3.0 (support for std::optional), install
    it manually in the Docker image for embedded builds (focal has 1.2.1).
    viktormalik committed Mar 29, 2023
    Configuration menu
    Copy the full SHA
    7696121 View commit details
    Browse the repository at this point in the history
  3. Parse bitfields from BTF

    Re-using the existing bitfield parsing algorithm (originally from Clang
    parser). Add a unit test for bitfield parsing (FieldAnalyser). The test
    required to expand the testing BTF data.
    viktormalik committed Mar 29, 2023
    Configuration menu
    Copy the full SHA
    3c0a239 View commit details
    Browse the repository at this point in the history
  4. Parse bitfields from DWARF

    Re-using the existing bitfield parsing algorithm.
    
    The problem is that DWARF versions >=4 use a different approach to
    represent bitfield offsets from the one used in versions <4 (in
    addition, some systems, such as the one in the CI, use the old approach
    even for DWARF 4). Hence, we support both approaches. See code comments
    for implementation details.
    
    A new unit test for bitfield parsing is added to FieldAnalyser,
    supporting both variants of bitfield representation.
    viktormalik committed Mar 29, 2023
    Configuration menu
    Copy the full SHA
    8ba34f2 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    822589a View commit details
    Browse the repository at this point in the history