-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add a sparc-unknown-none-elf target. #113535
Add a sparc-unknown-none-elf target. #113535
Conversation
r? @jackh726 (rustbot has picked a reviewer for you, use r? to override) |
These commits modify compiler targets. |
9fee593
to
c04d988
Compare
This comment has been minimized.
This comment has been minimized.
c04d988
to
36781de
Compare
Fixed. |
This comment has been minimized.
This comment has been minimized.
36781de
to
fed33fb
Compare
Ignored example Rust code in sparc-unknown-none-elf.md because it doesn't compile on the default target. |
This comment has been minimized.
This comment has been minimized.
fed33fb
to
214d4fe
Compare
OK, I explained why the test is ignored. |
This comment has been minimized.
This comment has been minimized.
OK, I don't think the build failures are my fault? |
Try rebasing over the latest master branch. I think there was any issue the concurrency key with GHA. |
Tested with the Gaisler bcc2 toolchain (both gcc and clang) and the Leon3 simulator.
214d4fe
to
4bccf83
Compare
Rebased |
@jackh726 can I do anything else to help here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Now that's a name I haven't heard in a long time."
By default, code generated with this target should run on any `SPARC` hardware; | ||
enabling additional target features may raise this baseline. | ||
|
||
- `-Ctarget-cpu=v8` adds the extra SPARC V8 instructions. | ||
|
||
- `-Ctarget-cpu=leon3` adds the SPARC V8 instructions and sets up scheduling to | ||
suit the Gaisler Leon3. | ||
|
||
Functions marked `extern "C"` use the [standard SPARC architecture calling | ||
convention](https://sparc.org/technical-documents/). | ||
|
||
This target generates ELF binaries. Any alternate formats or special | ||
considerations for binary layout will require linker options or linker scripts. | ||
|
||
## Building the target | ||
|
||
You can build Rust with support for the target by adding it to the `target` | ||
list in `config.toml`: | ||
|
||
```toml | ||
[build] | ||
build-stage = 1 | ||
target = ["sparc-unknown-none-elf"] | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-critical: Does using cargo +nightly build -Zbuild-std=core,alloc,compiler_builtins --release
work? If so, it may be preferable in lieu of building a compiler with such support, if the v8 instructions and Leon3 scheduling is a significant difference, as that will rebuild std with the relevant instructions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've only tried with build-std=core but that's how I've been using it (rather than having the toolchain build the libcore in advance).
I suppose you could make this sparcv8-unknown-none-elf because I think SPARC V7 stuff is very very niche at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, then I think we should document a recommendation to use -Zbuild-std
if that's what the target's maintainer is preferentially using. ^^; No opinion on the arch version question.
@bors r+ rollup |
…r=jackh726 Add a sparc-unknown-none-elf target. # `sparc-unknown-none-elf` **Tier: 3** Rust for bare-metal 32-bit SPARC V7 and V8 systems, e.g. the Gaisler LEON3. ## Target maintainers - Jonathan Pallant, `[email protected]`, https://ferrous-systems.com ## Requirements > Does the target support host tools, or only cross-compilation? Only cross-compilation. > Does the target support std, or alloc (either with a default allocator, or if the user supplies an allocator)? Only tested with `libcore` but I see no reason why you couldn't also support `liballoc`. > Document the expectations of binaries built for the target. Do they assume specific minimum features beyond the baseline of the CPU/environment/etc? What version of the OS or environment do they expect? Tested by linking with a standard SPARC bare-metal toolchain - specifically I used the [BCC2] toolchain from Gaisler (both GCC and clang variants, both pre-compiled for x64 Linux and compiling my own SPARC GCC from source to run on `aarch64-apple-darwin`). The target is set to use the lowest-common-denominator `SPARC V7` architecture (yes, they started at V7 - see [Wikipedia](https://en.wikipedia.org/wiki/SPARC#History)). [BCC2]: https://www.gaisler.com/index.php/downloads/compilers > Are there notable `#[target_feature(...)]` or `-C target-feature=` values that programs may wish to use? `-Ctarget-cpu=v8` adds the instructions added in V8. `-Ctarget-cpu=leon3` adds the V8 instructions and sets up scheduling to suit the Gaisler LEON3. > What calling convention does `extern "C"` use on the target? I believe this is defined by the SPARC architecture reference manuals and V7, V8 and V9 are all compatible. > What format do binaries use by default? ELF, PE, something else? ELF ## Building the target > If Rust doesn't build the target by default, how can users build it? Can users just add it to the `target` list in `config.toml`? Yes. I did: ```toml target = ["aarch64-apple-darwin", "sparc-unknown-none-elf"] ``` ## Building Rust programs > Rust does not yet ship pre-compiled artifacts for this target. To compile for this target, you will either need to build Rust with the target enabled (see "Building the target" above), or build your own copy of `core` by using `build-std` or similar. Correct. ## Testing > Does the target support running binaries, or do binaries have varying expectations that prevent having a standard way to run them? No - it's a bare metal platform. > If users can run binaries, can they do so in some common emulator, or do they need native hardware? But if you use [BCC2] as the linker, you get default memory map suitable for the LEON3, and a default BSP for the LEON3, and so you can run the binaries in the `tsim-leon3` simulator from Gaisler. ```console $ cat .cargo/config.toml | grep runner runner = "tsim-leon3 -c sim-commands.txt" $ cat sim-commands.txt run quit $ cargo +sparcrust run --targe=sparc-unknown-none-elf Compiling sparc-demo-rust v0.1.0 (/work/sparc-demo-rust) Finished dev [unoptimized + debuginfo] target(s) in 3.44s Running `tsim-leon3 -c sim-commands.txt target/sparc-unknown-none-elf/debug/sparc-demo-rust` TSIM3 LEON3 SPARC simulator, version 3.1.9 (evaluation version) Copyright (C) 2023, Frontgrade Gaisler - all rights reserved. This software may only be used with a valid license. For latest updates, go to https://www.gaisler.com/ Comments or bug-reports to [email protected] This TSIM evaluation version will expire 2023-11-28 Number of CPUs: 2 system frequency: 50.000 MHz icache: 1 * 4 KiB, 16 bytes/line (4 KiB total) dcache: 1 * 4 KiB, 16 bytes/line (4 KiB total) Allocated 8192 KiB SRAM memory, in 1 bank at 0x40000000 Allocated 32 MiB SDRAM memory, in 1 bank at 0x60000000 Allocated 8192 KiB ROM memory at 0x00000000 section: .text, addr: 0x40000000, size: 104400 bytes section: .rodata, addr: 0x400197d0, size: 15616 bytes section: .data, addr: 0x4001d4d0, size: 1176 bytes read 1006 symbols Initializing and starting from 0x40000000 Hello, this is Rust! PANIC: PanicInfo { payload: Any { .. }, message: Some(I am a panic), location: Location { file: "src/main.rs", line: 33, col: 5 }, can_unwind: true } Program exited normally on CPU 0. ``` > Does the target support running the Rust testsuite? I don't think so, the testsuite requires `libstd` IIRC. ## Cross-compilation toolchains and C code > Does the target support C code? Yes. > If so, what toolchain target should users use to build compatible C code? (This may match the target triple, or it may be a toolchain for a different target triple, potentially with specific options or caveats.) I suggest [BCC2] from Gaisler. It comes in both GCC and Clang variants.
…r=jackh726 Add a sparc-unknown-none-elf target. # `sparc-unknown-none-elf` **Tier: 3** Rust for bare-metal 32-bit SPARC V7 and V8 systems, e.g. the Gaisler LEON3. ## Target maintainers - Jonathan Pallant, `[email protected]`, https://ferrous-systems.com ## Requirements > Does the target support host tools, or only cross-compilation? Only cross-compilation. > Does the target support std, or alloc (either with a default allocator, or if the user supplies an allocator)? Only tested with `libcore` but I see no reason why you couldn't also support `liballoc`. > Document the expectations of binaries built for the target. Do they assume specific minimum features beyond the baseline of the CPU/environment/etc? What version of the OS or environment do they expect? Tested by linking with a standard SPARC bare-metal toolchain - specifically I used the [BCC2] toolchain from Gaisler (both GCC and clang variants, both pre-compiled for x64 Linux and compiling my own SPARC GCC from source to run on `aarch64-apple-darwin`). The target is set to use the lowest-common-denominator `SPARC V7` architecture (yes, they started at V7 - see [Wikipedia](https://en.wikipedia.org/wiki/SPARC#History)). [BCC2]: https://www.gaisler.com/index.php/downloads/compilers > Are there notable `#[target_feature(...)]` or `-C target-feature=` values that programs may wish to use? `-Ctarget-cpu=v8` adds the instructions added in V8. `-Ctarget-cpu=leon3` adds the V8 instructions and sets up scheduling to suit the Gaisler LEON3. > What calling convention does `extern "C"` use on the target? I believe this is defined by the SPARC architecture reference manuals and V7, V8 and V9 are all compatible. > What format do binaries use by default? ELF, PE, something else? ELF ## Building the target > If Rust doesn't build the target by default, how can users build it? Can users just add it to the `target` list in `config.toml`? Yes. I did: ```toml target = ["aarch64-apple-darwin", "sparc-unknown-none-elf"] ``` ## Building Rust programs > Rust does not yet ship pre-compiled artifacts for this target. To compile for this target, you will either need to build Rust with the target enabled (see "Building the target" above), or build your own copy of `core` by using `build-std` or similar. Correct. ## Testing > Does the target support running binaries, or do binaries have varying expectations that prevent having a standard way to run them? No - it's a bare metal platform. > If users can run binaries, can they do so in some common emulator, or do they need native hardware? But if you use [BCC2] as the linker, you get default memory map suitable for the LEON3, and a default BSP for the LEON3, and so you can run the binaries in the `tsim-leon3` simulator from Gaisler. ```console $ cat .cargo/config.toml | grep runner runner = "tsim-leon3 -c sim-commands.txt" $ cat sim-commands.txt run quit $ cargo +sparcrust run --targe=sparc-unknown-none-elf Compiling sparc-demo-rust v0.1.0 (/work/sparc-demo-rust) Finished dev [unoptimized + debuginfo] target(s) in 3.44s Running `tsim-leon3 -c sim-commands.txt target/sparc-unknown-none-elf/debug/sparc-demo-rust` TSIM3 LEON3 SPARC simulator, version 3.1.9 (evaluation version) Copyright (C) 2023, Frontgrade Gaisler - all rights reserved. This software may only be used with a valid license. For latest updates, go to https://www.gaisler.com/ Comments or bug-reports to [email protected] This TSIM evaluation version will expire 2023-11-28 Number of CPUs: 2 system frequency: 50.000 MHz icache: 1 * 4 KiB, 16 bytes/line (4 KiB total) dcache: 1 * 4 KiB, 16 bytes/line (4 KiB total) Allocated 8192 KiB SRAM memory, in 1 bank at 0x40000000 Allocated 32 MiB SDRAM memory, in 1 bank at 0x60000000 Allocated 8192 KiB ROM memory at 0x00000000 section: .text, addr: 0x40000000, size: 104400 bytes section: .rodata, addr: 0x400197d0, size: 15616 bytes section: .data, addr: 0x4001d4d0, size: 1176 bytes read 1006 symbols Initializing and starting from 0x40000000 Hello, this is Rust! PANIC: PanicInfo { payload: Any { .. }, message: Some(I am a panic), location: Location { file: "src/main.rs", line: 33, col: 5 }, can_unwind: true } Program exited normally on CPU 0. ``` > Does the target support running the Rust testsuite? I don't think so, the testsuite requires `libstd` IIRC. ## Cross-compilation toolchains and C code > Does the target support C code? Yes. > If so, what toolchain target should users use to build compatible C code? (This may match the target triple, or it may be a toolchain for a different target triple, potentially with specific options or caveats.) I suggest [BCC2] from Gaisler. It comes in both GCC and Clang variants.
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#112741 (fix typo in `rustdoc/src/what-is-rustdoc.md`) - rust-lang#113535 (Add a sparc-unknown-none-elf target.) - rust-lang#113651 (self type param infer, avoid ICE) - rust-lang#113770 (Generate safe stable code for derives on empty enums) r? `@ghost` `@rustbot` modify labels: rollup
This came from x86_64-unknown-none and doesn't make sense here.
Did I break it with the extra commit? Sorry about that. |
Ok, I'll do a second PR with the text updates then? |
I'm going to close this since a couple commits got merged. Weird state, but let's not make it any more weird. Please make another PR for changes that didn't get merged. |
…wn-readme, r=Amanieu Update sparc-unknown-none-elf platform README Cherry picked a couple of commits that didn't quite make it in rust-lang#113535
sparc-unknown-none-elf
Tier: 3
Rust for bare-metal 32-bit SPARC V7 and V8 systems, e.g. the Gaisler LEON3.
Target maintainers
[email protected]
, https://ferrous-systems.comRequirements
Only cross-compilation.
Only tested with
libcore
but I see no reason why you couldn't also supportliballoc
.Tested by linking with a standard SPARC bare-metal toolchain - specifically I used the BCC2 toolchain from Gaisler (both GCC and clang variants, both pre-compiled for x64 Linux and compiling my own SPARC GCC from source to run on
aarch64-apple-darwin
).The target is set to use the lowest-common-denominator
SPARC V7
architecture (yes, they started at V7 - see Wikipedia).-Ctarget-cpu=v8
adds the instructions added in V8.-Ctarget-cpu=leon3
adds the V8 instructions and sets up scheduling to suit the Gaisler LEON3.I believe this is defined by the SPARC architecture reference manuals and V7, V8 and V9 are all compatible.
ELF
Building the target
Yes. I did:
Building Rust programs
Correct.
Testing
No - it's a bare metal platform.
But if you use BCC2 as the linker, you get default memory map suitable for the LEON3, and a default BSP for the LEON3, and so you can run the binaries in the
tsim-leon3
simulator from Gaisler.I don't think so, the testsuite requires
libstd
IIRC.Cross-compilation toolchains and C code
Yes.
I suggest BCC2 from Gaisler. It comes in both GCC and Clang variants.