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

docs: Add documentation for BPF targets #135107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vadorovsky
Copy link
Contributor

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Jan 4, 2025

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 4, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add the page to the SUMMARY.md

src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for signing up as maintainer contact by the way, this is definitely one of our... odder... targets and it will probably benefit a lot from having someone to talk to about it.

Copy link
Contributor

@tamird tamird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting this going!

src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
@vadorovsky vadorovsky force-pushed the docs-platform-bpf branch 2 times, most recently from e323a85 to 9397c4d Compare January 5, 2025 14:50
Copy link
Contributor

@tamird tamird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird I can't resolve comments :(

src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved
Comment on lines 19 to 20
BPF targets require a Rust toolchain with the `rust-src` component and
[bpf-linker][bpf-linker].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is best to full stop here. The current phrasing seems easy to misinterpret as "bpf-linker is part of the Rust toolchain". Notably, we do ship custom linkers for many targets!

Suggested change
BPF targets require a Rust toolchain with the `rust-src` component and
[bpf-linker][bpf-linker].
BPF targets require a Rust toolchain with the `rust-src` component.
In addition, you must install the [bpf-linker].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a side note, I would love to see bpf-linker eventually being included in the Rust toolchain. I'm happy to help with that. I suppose it would be one of requirements of updating BPF targets to Tier 2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably!

Also uh, probably would need them to support more than 5 arguments in Rust functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is "them"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tamird The BPF targets.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Do I understand you correctly that such support would be a requirement for promotion to Tier 2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be... difficult for me to imagine that we would accept a tier 2 target that cannot accept a dozen arguments to its Rust functions, yes. Generally, for tier 2 targets, we want them to feel like fairly "normal" targets, even if they don't have first class support (yet?).

Note how I am saying "Rust functions" very specifically: if you want to impose some peculiar constraint on the extern "C" ABI, that's less likely to be a blocker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what would be the point of supporting more than 5 args if the eBPF spec mandates max 5 and the vms don't support more?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be possible to handle more than 5 arguments by passing the rest on the stack, right? That is what regular targets do too when they run out of argument registers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default response to upstreaming changes - even a lot less invasive than changing the calling convention - so far has been "if clang and the kernel don't need it, it doesn't belong to the target". Then there's the issue that the verifier would have to be made aware too, or Fn(u8, u8, u8, u8, u8) and Fn(u8, u8, u8, u8, u8, u8) would look like the same type to it. But nothing in the kernel uses more than 5 args, so the chance of getting that merged seems very slim too.

Technically yes this is a very easy thing to fix (and in fact at work we have a LLVM fork that already does all this and more), but socially it's much harder (and at work we've given up on upstreaming).

BTF, which can be enabled by adding `-C link-arg=--btf` to `RUSTFLAGS`. With
that feature enabled, [bpf-linker][bpf-linker] does not only link different
crates/modules, but also performs a necessary sanitization of debug info, which
is required to produce valid [BTF][btf] acceptable by the Linux kernel.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted by what, exactly? You mean a specific component of the kernel, right? Does the eBPF verifier also check debuginfo? Or is it that the debugger requires a specific debuginfo format?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the BPF dynamic linker uses BTF to do things like checking for compatibility of the BPF module with the type layouts of the kernel itself. And through special relocations it can fill in the offsets of fields for kernel types such that the BPF module can run on multiple kernel versions even if the layout of types used by the BPF module changes across those kernel versions. The latter almost certainly will require explicit rustc support to get wired up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@workingjubilee the kernel validates the BTF info as part of calling bpf_program_load. Producing valid BTF right now means... generating whatever clang generates for C code. Non-C symbols in type names are not allowed (eg < in Foo<u8>), and there are some other annoying constraints.

@bjorn3 we discussed implementing BTF relocs on zulip a couple of years ago. Long term, you're correct it requires explicit rustc support if only because what debuginfo rustc generates with -C debuginfo is unspecified, so going from DI => relocs is fragile. In the meantime we think we can probably hack it up in bpf-linker tho.

src/doc/rustc/src/platform-support/bpf-unknown-none.md Outdated Show resolved Hide resolved

BPF bytecode needs to be executed on a BPF virtual machine, like the one
provided by the Linux kernel or one of the user-space implementations like
[rbpf][rbpf]. None of them support running Rust testsuite. One of the reasons
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this referring to our UI testsuite, or is it referring to #[test] functions, or both?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To both.

Comment on lines 93 to 94
Currently the best way of unit testing the code used in BPF programs is
extracting it to a separate crate, which can be built and ran on a host target,
and using it as a dependency.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh...

wouldn't #[cfg_attr(not(target_arch = "bpfel"), test)] work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[cfg(all(not(target_arch = "bpf"), test))]

works. I updated the paragraph accordingly.

[uprobes][uprobe] allow dynamic function tracing and lookup into registers.
Registers and calling convenctions are different across architectures. Due to
`char` in C being signed or unsigned on different architectures, the signatures
of [BPF helpers][bpf-helpers] and [kfuncs][kfunc] also end up different.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't Linux compile with -funsigned-char nowadays?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From relatively recently right? 6.1 or 6.2 can't remember. But we need to support older kernels.

But I agree that it seems a detail I wouldn't single out char here.

@rust-log-analyzer

This comment has been minimized.

expected to handle errors in a recoverable manner. Therefore most BPF programs
written in Rust use the following no-op panic handler implementation:

```rust
Copy link
Member

@workingjubilee workingjubilee Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this has to be one of these in order for CI to stop complaining:

Suggested change
```rust
```rust,ignore
Suggested change
```rust
```rust
#![no_std]

@workingjubilee workingjubilee added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 11, 2025
@rust-log-analyzer

This comment has been minimized.

@vadorovsky vadorovsky marked this pull request as ready for review January 19, 2025 21:30
@rustbot
Copy link
Collaborator

rustbot commented Jan 19, 2025

Some changes occurred in src/doc/rustc/src/platform-support

cc @Noratrieb

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
info: removing rustup binaries
info: rustup is uninstalled
##[group]Image checksum input
mingw-check-tidy
# We use the ghcr base image because ghcr doesn't have a rate limit
# and the mingw-check-tidy job doesn't cache docker images in CI.
FROM ghcr.io/rust-lang/ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
  g++ \
  make \
---

COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/

# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
           --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---
#12 2.931 Building wheels for collected packages: reuse
#12 2.932   Building wheel for reuse (pyproject.toml): started
#12 3.142   Building wheel for reuse (pyproject.toml): finished with status 'done'
#12 3.142   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132719 sha256=be6760d5849de4a58bbe52b85ca57a55f2b32b518b17029a5ad2e530db0d4303
#12 3.143   Stored in directory: /tmp/pip-ephem-wheel-cache-orb9ydt4/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#12 3.145 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#12 3.549 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#12 3.550 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#12 4.091 Collecting virtualenv
#12 4.091 Collecting virtualenv
#12 4.158   Downloading virtualenv-20.29.1-py3-none-any.whl (4.3 MB)
#12 4.316      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 27.6 MB/s eta 0:00:00
#12 4.378 Collecting filelock<4,>=3.12.2
#12 4.388   Downloading filelock-3.16.1-py3-none-any.whl (16 kB)
#12 4.432 Collecting platformdirs<5,>=3.9.1
#12 4.440   Downloading platformdirs-4.3.6-py3-none-any.whl (18 kB)
#12 4.462 Collecting distlib<1,>=0.3.7
#12 4.484      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 35.7 MB/s eta 0:00:00
#12 4.484      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 35.7 MB/s eta 0:00:00
#12 4.566 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#12 4.750 Successfully installed distlib-0.3.9 filelock-3.16.1 platformdirs-4.3.6 virtualenv-20.29.1
#12 DONE 4.9s

#13 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#13 DONE 0.0s
---
DirectMap4k:      122816 kB
DirectMap2M:     6168576 kB
DirectMap1G:    12582912 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test            --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
    Finished `dev` profile [unoptimized] target(s) in 0.05s
##[endgroup]
WARN: currently no CI rustc builds have rustc debug assertions enabled. Please either set `rust.debug-assertions` to `false` if you want to use download CI rustc or set `rust.download-rustc` to `false`.
downloading https://static.rust-lang.org/dist/2025-01-08/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz
---
fmt check
fmt: checked 5786 files
tidy check
tidy: Skipping binary file check, read-only filesystem
##[error]tidy error: /checkout/src/doc/rustc/src/platform-support/bpf-unknown-none.md:74: unexplained "```ignore" doctest; try one:
* make the test actually pass, by adding necessary imports and declarations, or
* make the test actually pass, by adding necessary imports and declarations, or
* use "```text", if the code is not Rust code, or
* use "```compile_fail,Ennnn", if the code is expected to fail at compile time, or
* use "```should_panic", if the code is expected to fail at run time, or
* use "```no_run", if the code should type-check but not necessary linkable/runnable, or
* explain it like "```ignore (cannot-test-this-because-xxxx)", if the annotation cannot be avoided.


##[error]tidy error: /checkout/src/doc/rustc/src/platform-support/bpf-unknown-none.md:95: unexplained "```ignore" doctest; try one:
* make the test actually pass, by adding necessary imports and declarations, or
* make the test actually pass, by adding necessary imports and declarations, or
* use "```text", if the code is not Rust code, or
* use "```compile_fail,Ennnn", if the code is expected to fail at compile time, or
* use "```should_panic", if the code is expected to fail at run time, or
* use "```no_run", if the code should type-check but not necessary linkable/runnable, or
* explain it like "```ignore (cannot-test-this-because-xxxx)", if the annotation cannot be avoided.

removing old virtual environment
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (24.3.1)
All checks passed!
checking python file formatting
28 files already formatted
checking C++ file formatting
checking C++ file formatting
some tidy checks failed
Command has failed. Rerun with -v to see more details.
  local time: Sun Jan 19 21:40:10 UTC 2025
  network time: Sun, 19 Jan 2025 21:40:10 GMT
##[error]Process completed with exit code 1.
Post job cleanup.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 31, 2025
Support clobber_abi in BPF inline assembly

This supports [`clobber_abi`](https://doc.rust-lang.org/nightly/reference/inline-assembly.html#abi-clobbers) which is one of the requirements of stabilization mentioned in the tracking Issue for `asm_experimental_arch` (rust-lang#93335).

Refs: [Section 1.1 "Registers and calling convention" in BPF ABI Recommended Conventions and Guidelines v1.0](https://github.com/torvalds/linux/blob/v6.13/Documentation/bpf/standardization/abi.rst#11registers-and-calling-convention)
> R0 - R5 are scratch registers and BPF programs needs to spill/fill them if necessary across calls.

cc `@alessandrod` `@dave-tucker` `@tamird` `@vadorovsky` (target maintainers mentioned in platform support document which will be added by rust-lang#135107)

r? `@Amanieu`

`@rustbot` label +O-eBPF +A-inline-assembly
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 31, 2025
Rollup merge of rust-lang#136194 - taiki-e:bpf-clobber-abi, r=amanieu

Support clobber_abi in BPF inline assembly

This supports [`clobber_abi`](https://doc.rust-lang.org/nightly/reference/inline-assembly.html#abi-clobbers) which is one of the requirements of stabilization mentioned in the tracking Issue for `asm_experimental_arch` (rust-lang#93335).

Refs: [Section 1.1 "Registers and calling convention" in BPF ABI Recommended Conventions and Guidelines v1.0](https://github.com/torvalds/linux/blob/v6.13/Documentation/bpf/standardization/abi.rst#11registers-and-calling-convention)
> R0 - R5 are scratch registers and BPF programs needs to spill/fill them if necessary across calls.

cc `@alessandrod` `@dave-tucker` `@tamird` `@vadorovsky` (target maintainers mentioned in platform support document which will be added by rust-lang#135107)

r? `@Amanieu`

`@rustbot` label +O-eBPF +A-inline-assembly
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Feb 1, 2025
Support clobber_abi in BPF inline assembly

This supports [`clobber_abi`](https://doc.rust-lang.org/nightly/reference/inline-assembly.html#abi-clobbers) which is one of the requirements of stabilization mentioned in the tracking Issue for `asm_experimental_arch` (#93335).

Refs: [Section 1.1 "Registers and calling convention" in BPF ABI Recommended Conventions and Guidelines v1.0](https://github.com/torvalds/linux/blob/v6.13/Documentation/bpf/standardization/abi.rst#11registers-and-calling-convention)
> R0 - R5 are scratch registers and BPF programs needs to spill/fill them if necessary across calls.

cc `@alessandrod` `@dave-tucker` `@tamird` `@vadorovsky` (target maintainers mentioned in platform support document which will be added by rust-lang/rust#135107)

r? `@Amanieu`

`@rustbot` label +O-eBPF +A-inline-assembly
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Feb 1, 2025
Support clobber_abi in BPF inline assembly

This supports [`clobber_abi`](https://doc.rust-lang.org/nightly/reference/inline-assembly.html#abi-clobbers) which is one of the requirements of stabilization mentioned in the tracking Issue for `asm_experimental_arch` (#93335).

Refs: [Section 1.1 "Registers and calling convention" in BPF ABI Recommended Conventions and Guidelines v1.0](https://github.com/torvalds/linux/blob/v6.13/Documentation/bpf/standardization/abi.rst#11registers-and-calling-convention)
> R0 - R5 are scratch registers and BPF programs needs to spill/fill them if necessary across calls.

cc `@alessandrod` `@dave-tucker` `@tamird` `@vadorovsky` (target maintainers mentioned in platform support document which will be added by rust-lang/rust#135107)

r? `@Amanieu`

`@rustbot` label +O-eBPF +A-inline-assembly
Copy link
Contributor

@tamird tamird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vadorovsky looks like this needs minor updates to land.

built from C code with [clang][clang]. It can be done using a `rustc-link-lib`
instruction in `build.rs`. Example:

```rust
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this wants a no_run?

  ---- /checkout/src/doc/rustc/src/platform-support/bpf-unknown-none.md - Tier__3::C_code (line 127) stdout ----
  Test executable failed (exit status: 101).
  
  stderr:
  
  thread 'main' panicked at /checkout/src/doc/rustc/src/platform-support/bpf-unknown-none.md:5:35:
  called `Result::unwrap()` on an `Err` value: NotPresent
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

expected to handle errors in a recoverable manner. Therefore most BPF programs
written in Rust use the following no-op panic handler implementation:

```rust,ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error: tidy error: /checkout/src/doc/rustc/src/platform-support/bpf-unknown-none.md:74: unexplained "```ignore" doctest; try one:

* make the test actually pass, by adding necessary imports and declarations, or
* use "```text", if the code is not Rust code, or
* use "```compile_fail,Ennnn", if the code is expected to fail at compile time, or
* use "```should_panic", if the code is expected to fail at run time, or
* use "```no_run", if the code should type-check but not necessary linkable/runnable, or
* explain it like "```ignore (cannot-test-this-because-xxxx)", if the annotation cannot be avoided.

Therefore, unit tests need to run on the host system. That requirement can be
enforced by the following conditional check:

```rust,ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error: tidy error: /checkout/src/doc/rustc/src/platform-support/bpf-unknown-none.md:95: unexplained "```ignore" doctest; try one:

* make the test actually pass, by adding necessary imports and declarations, or
* use "```text", if the code is not Rust code, or
* use "```compile_fail,Ennnn", if the code is expected to fail at compile time, or
* use "```should_panic", if the code is expected to fail at run time, or
* use "```no_run", if the code should type-check but not necessary linkable/runnable, or
* explain it like "```ignore (cannot-test-this-because-xxxx)", if the annotation cannot be avoided.


```toml
[build]
target = ["bpfel-unknown-none"]
Copy link

@niklaskorz niklaskorz Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails building the docs at stage2:

Documenting stage2 library {alloc, core, panic_abort, panic_unwind, proc_macro, std, sysroot, test, unwind} in HTML format (aarch64-apple-darwin -> bpfel-unknown-none)

The errors being, among others:

error[E0277]: the trait bound `System: core::alloc::GlobalAlloc` is not satisfied
   --> std/src/alloc.rs:220:43
    |
220 |             unsafe { GlobalAlloc::dealloc(self, ptr.as_ptr(), layout) }
    |                      -------------------- ^^^^ the trait `core::alloc::GlobalAlloc` is not implemented for `System`
    |                      |
    |                      required by a bound introduced by this call

error[E0277]: the trait bound `System: core::alloc::GlobalAlloc` is not satisfied
   --> std/src/alloc.rs:270:52
    |
270 |                 let raw_ptr = GlobalAlloc::realloc(self, ptr.as_ptr(), old_layout, new_size);
    |                               -------------------- ^^^^ the trait `core::alloc::GlobalAlloc` is not implemented for `System`
    |                               |
    |                               required by a bound introduced by this call

error[E0599]: no method named `fetch_add` found for struct `AtomicUsize` in the current scope
   --> std/src/panicking.rs:395:47
    |
395 |         let global_count = GLOBAL_PANIC_COUNT.fetch_add(1, Ordering::Relaxed);
    |                                               ^^^^^^^^^ method not found in `AtomicUsize`

error[E0599]: no method named `fetch_sub` found for struct `AtomicUsize` in the current scope
   --> std/src/panicking.rs:419:28
    |
419 |         GLOBAL_PANIC_COUNT.fetch_sub(1, Ordering::Relaxed);
    |                            ^^^^^^^^^ method not found in `AtomicUsize`

error[E0599]: no method named `fetch_or` found for struct `AtomicUsize` in the current scope
   --> std/src/panicking.rs:427:28
    |
427 |         GLOBAL_PANIC_COUNT.fetch_or(ALWAYS_ABORT_FLAG, Ordering::Relaxed);
    |                            ^^^^^^^^ method not found in `AtomicUsize

Could you also document how to prevent building docs for std and alloc here, which are not supported by the bpf targets? (without disabling docs entirely through --disable-docs, and without dropping other targets from the same rustc that do successfully build std docs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants