Commit Graph

43 Commits (e34e8536d4fb9114a6ef9924fb34ce8fd073380a)

Author SHA1 Message Date
Tamir Duberstein 35962a4794 Document miri skip reasons 5 months ago
Dave Tucker 8c79b71bd5 feat(aya): Rename Bpf to Ebpf
And BpfLoader to EbpfLoader.
This also adds type aliases to preserve the use of the old names, making
updating to a new Aya release less of a burden. These aliases are marked
as deprecated since we'll likely remove them in a later release.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
7 months ago
Michal Rostecki c05a3b69b7 aya-obj: Handle lack of match of enum variants correctly
When comparing `local_spec` with `target_spec` for enum relocations,
we can encounter a situation when a matchinng variant in a candidate
spec doesn't exist.

Before this change, such case wasn't handled explicitly, therefore
resulted in returning currently constructed `target_spec` at the
end. The problem is that such `target_spec` was, due to lack of
match, incomplete. It didn't contain any `accessors` nor `parts`.

Later usage of such incomplete `target_spec` was leading to panics,
since the code operating on enums' `target_spec` expects at least
one `accessor` to be available.

Fixes #868
8 months ago
Tamir Duberstein d16e607fd4
rustfmt: group_imports = "StdExternalCrate"
High time we stop debating this; let the robots do the work.
12 months ago
Tamir Duberstein dfb6020a1d
aya-obj: s/types.types[i]/*t/ where possible
We already have a mutable reference in scope, use it where possible.
1 year ago
Dave Tucker e38e2566e3 aya, aya-obj: Implement ENUM64 fixups
This commit adds:

- A probe to see if the ENUM64 feature is supported
- Fixups for the use of signed enums, or enum64 types
  on systems where enum64 is not supported

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Dave Tucker 098d4364bd aya-obj: Mutate BTF in-place without clone
The BTF we're working on is Cow anyway so modifying in-place is fine.
All we need to do is store some information before we start our
mutable iteration to avoid concurrently borrowing types both mutably and
immutably.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Tamir Duberstein 826e0e5050
btf: use Self instead of restating the type 1 year ago
Tamir Duberstein 2a054d76ae
btf: avoid multiple vector allocations
Rather than creating an empty vector and iteratively appending - which
might induce intermediate allocations - create an ExactSizeIterator and
collect it into a vector, which should produce exactly one allocation.
1 year ago
Tamir Duberstein 17f25a6793
all: better panic messages
Always include operands in failing assertions. Use assert_matches over
manual match + panic.
1 year ago
Tamir Duberstein 8961be9526
Do not escape newlines on Err(LoadError).unwrap()
Wrap verifier logs in a newtype whose `Debug` impl emits unescaped
newlines. This improves ergonomics in tests where we `Result::unwrap()`
those load errors; when these fail today they emit the errors with
newlines escaped, making them incredibly difficult to read.
1 year ago
Tamir Duberstein b5ebcb7cc5
Remove verifier log special case 1 year ago
Tamir Duberstein 6b94b2080d
Hide details of VerifierLog
This type is really only used by one function.
1 year ago
Tamir Duberstein 27120b328a
aya: don't allocate static strings 1 year ago
Mary 5c86b7ee95
Merge pull request #635 from marysaka/misc/aya-obj-enum-public
misc: aya-obj: Make it possible to externally assemble BtfEnum
1 year ago
Mary d9dfd94f29 misc: aya-obj: Make it possible to externally assemble BtfEnum 1 year ago
Dave Tucker 47f764c191 aya: Make Features part of the public API
This commit adds a new probe for bpf_attach_cookie, which would be used
to implement USDT probes. Since USDT probes aren't currently supported,
we this triggers a dead_code warning in clippy.

There are cases where exposing FEATURES - our lazy static - is actually
helpful to users of the library. For example, they may wish to choose to
load a different version of their bytecode based on current features.
Or, in the case of an orchestrator like bpfd, we might want to allow
users to describe which features their program needs and return nice
error message is one or more nodes in their cluster doesn't support the
necessary feature set.

To do this without breaking the API, we make all the internal members of
the `Features` and `BtfFeatures` structs private, and add accessors for
them. We then add a `features()` API to avoid leaking the
lazy_static.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
1 year ago
Mary 85ad0197e0
Merge pull request #563 from marysaka/fix/reloc-less-strict
aya-obj: Make relocations less strict
1 year ago
Mary 35eaa50736 aya-obj: Make relocations less strict
Missing relocations at load time shouldn't cause an error in aya-obj
but instead poison related instructions.

This makes struct flavors work.
1 year ago
Alessandro Decina 3a9a54fd9b
Merge pull request #602 from marysaka/fix/btf-reloc-all-functions
aya: Apply BTF relocations to all functions
1 year ago
Mary c4e721f3d3 aya: Apply BTF relocations to all functions
This fix aya wrong logic causing non entrypoint functions to not have
any BTF relocations working.

Also fix missing section_offset computation for instruction offset in
multiple spots.
1 year ago
Andrés 5894c4ce82
Fix load errors for empty (but existent) BTF/BTF.ext sections (#608)
* use the hdr_len of BTF.ext sections rather than size of struct

Otherwise this will erroneously fail on older btf_ext_header that have
less fields than the bindgen'd struct

* do not attempt to load a BTF object that has no types

* add tests

* fix: hdr_len i32 -> u32

* guard against a bigger header in the future

* use separate unsafe blocks

* simplify writing to zero'd out header

* merge safe block and address typo
1 year ago
Mary 9e1109b3ce aya: Move program's functions to the same map 1 year ago
Kenjiro Nakayama e67025b66f Drop unnecessary mut 1 year ago
Alessandro Decina 45efa6384f
Merge pull request #586 from probulate/no-std-inversion
aya: flip feature "no_std" to feature "std"
1 year ago
Tamir Duberstein 33a0a2b604
aya: flip feature "no_std" to feature "std"
This fixes `cargo build --all-features` by sidestepping the feature
unification problem described in The Cargo Book[0].

Add `cargo hack --feature-powerset` to CI to enforce that this doesn't
regress (and that all combinations of features work).

Since error_in_core is nightly-only, use core-error and a fake std
module to allow aya-obj to build without std on stable.

[0] https://doc.rust-lang.org/cargo/reference/features.html#feature-unification
1 year ago
Alessandro Decina b2d5059ac2
Merge pull request #583 from 0xrawsec/fix-builtin-linkage
Fix builtin linkage
1 year ago
Quentin JEROME 1464bdc1d4 - comment changed to be more precise
- adapted test to be more readable

Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
1 year ago
Quentin JEROME 72c1572178 added memmove, memcmp to the list of function changed to BTF_FUNC_STATIC
Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
1 year ago
Quentin JEROME a51c9bc532 fixed indent
Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
1 year ago
Quentin JEROME 5b4fc9ea93 removed useless line break and comments
Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
1 year ago
Quentin JEROME 74bc754862 add debug messages
Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
1 year ago
Quentin JEROME 4e41da6a86 Fixed BTF linkage of memset and memcpy to static
Signed-off-by: Quentin JEROME <qjerome@users.noreply.github.com>
1 year ago
Mary 4e33fa011e aya-obj: fix DATASEC to STRUCT conversion
This fix the following issues:
- Previously the DATASEC name wasn't sanitized resulting on "Invalid
  name" returned by old kernels.
- The newly created BTF struct had a size of 0 making old kernels refuse
  it.

This was tested on Debian 10 with kernel 4.19.0-21.
1 year ago
Alessandro Decina 93ac3e94bc aya: support relocations across multiple text sections + fixes
Fix R_BPF_64_64 text relocations in sections other than .text (for
instance .text.unlikely). Also fix misc bugs triggered by integration
tests.
1 year ago
Alessandro Decina 9a6f8143a1 aya: btf: add support for BTF_KIND_ENUM64 2 years ago
Alessandro Decina 4482db42d8 aya: btf: fix relocations for signed enums (32 bits)
Enums now carry a signed bit in the info flags. Take it into account
when applying enum relocations.
2 years ago
Alessandro Decina d6b976c6f1 aya: btf: switch ComputedRelocationValue::value to u64
This is in preparation of adding Enum64 relocation support
2 years ago
Alessandro Decina 9f4ef6f67d Fix lints 2 years ago
Shenghui Ye 9ec3447e89 aya-obj: fix rustfmt diffs and typos 2 years ago
Shenghui Ye 30f1fabc05 aya-obj: add no_std feature
The crate has few libstd dependencies. Since it should be platform-
independent in principle, making it no_std like the object crate would
seem reasonable.

However, the feature `error_in_core` is not yet stabilized, and the
thiserror crate currently offers no no_std support. When the feature
no_std is selected, we enable the `error_in_core` feature, switch to
thiserror-core and replace the HashMap with the one in hashbrown.
2 years ago
Shenghui Ye e52497cb9c aya-obj: add basic documentation to public members
Types relevant to maps are moved into aya_obj::maps.
Some members are marked `pub(crate)` again.

Refs: #473
2 years ago
Shenghui Ye ac49827e20 aya-obj: migrate aya::obj into a separate crate
To split the crate into two, several changes were made:
1. Most `pub(crate)` are now `pub` to allow access from Aya;
2. Parts of BpfError are merged into, for example, RelocationError;
3. BTF part of Features is moved into the new crate;
4. `#![deny(missing_docs)]` is removed temporarily;
5. Some other code gets moved into the new crate, mainly:
   - aya::{bpf_map_def, BtfMapDef, PinningType},
   - aya::programs::{CgroupSock*AttachType},

The new crate is currenly allowing missing_docs. Member visibility
will be adjusted later to minimize exposure of implementation details.

Refs: #473
2 years ago