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

btf: Implement support for bitfield relocations #573

Merged
merged 7 commits into from Mar 29, 2022

Commits on Mar 29, 2022

  1. btf: Implement support for bitfield relocations

    This adds support for relocating bitfields, e.g. rewriting of
    the load offset and bit shifts for accessing the field.
    
    The implementation is mostly following libbpf, but does not
    include the loop for doubling the size of the load as that should
    not be necessary when one assumes that loads must be aligned and
    that a bitfield cannot be larger than the variable type.
    
    Signed-off-by: Jussi Maki <jussi@isovalent.com>
    Signed-off-by: Timo Beckers <timo@isovalent.com>
    joamaki authored and ti-mo committed Mar 29, 2022
    Copy the full SHA
    eb92491 View commit details
    Browse the repository at this point in the history
  2. btf: check all of coreField in TestCOREFindField

    The current test doesn't check all fields of coreField. Fix this by
    using go-cmp.
    lmb authored and ti-mo committed Mar 29, 2022
    Copy the full SHA
    6b3b15d View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    e893e37 View commit details
    Browse the repository at this point in the history
  4. btf: store coreField.offset in bytes

    The documentation on coreField.offset states that it is in bytes,
    but the code stores it in bits. Refactor the code to use bytes,
    since that is more natural for the rest of the code.
    
    Change coreFindField to re-initialize coreField variables instead
    of only creating coreFields when returning. This has the benefit
    of implicitly zeroing fields of the local and target variables.
    It also allows us to put helper methods on coreField to slim
    coreFindField down a little bit.
    lmb authored and ti-mo committed Mar 29, 2022
    Copy the full SHA
    db7ff9f View commit details
    Browse the repository at this point in the history
  5. btf: enforce that bitfield is last accessor in coreFindField

    Make sure that we're at the end of an accessor when dealing with a
    bitfield. This also allows us to fall through to after the switch
    instead of returning early.
    lmb authored and ti-mo committed Mar 29, 2022
    Copy the full SHA
    fd42c74 View commit details
    Browse the repository at this point in the history
  6. btf: use alignof instead of sizeof for bitfield loads

    We currently use the size of the target type to align the load of
    a bitfield. This is OK for integers and enums, since their size
    equals their alignment. It's not correct in general however.
    
    Add alignof to make this explicit.
    lmb authored and ti-mo committed Mar 29, 2022
    Copy the full SHA
    c7996e8 View commit details
    Browse the repository at this point in the history
  7. btf: redefine coreField.bitfieldOffset

    coreField.bitfieldOffset is currently defined to count from the start
    of the enclosing composite type. This is incovenient, since the shift
    relocations want to know the offset from the start of the load.
    Redefine coreField.bitfieldOffset to count from the start of the
    field and add coreField.adjustOffsetBits to handle adjusting
    offset and bitfieldOffset while respecting alignment.
    
    Also compute offsets for the local relocation. We don't use this
    information at the moment, but it's what we do for other types
    of relocations.
    
    Finally, move the compatibility behaviour for regular fields accessed
    as bitfield into coreField.sizeBits. Doing the fixup only when
    encountering a bitfield leads to inconsistent behaviour.
    lmb authored and ti-mo committed Mar 29, 2022
    Copy the full SHA
    85daa93 View commit details
    Browse the repository at this point in the history