forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#117465 - paulmenage:small-data-limit, r=compi…
…ler-errors Add -Z small-data-threshold This flag allows specifying the threshold size above which LLVM should not consider placing small objects in a `.sdata` or `.sbss` section. Support is indicated in the target options via the small-data-threshold-support target option, which can indicate either an LLVM argument or an LLVM module flag. To avoid duplicate specifications in a large number of targets, the default value for support is DefaultForArch, which is translated to a concrete value according to the target's architecture.
- Loading branch information
Showing
10 changed files
with
241 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/doc/unstable-book/src/compiler-flags/small-data-threshold.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# `small-data-threshold` | ||
|
||
----------------------- | ||
|
||
This flag controls the maximum static variable size that may be included in the | ||
"small data sections" (.sdata, .sbss) supported by some architectures (RISCV, | ||
MIPS, M68K, Hexagon). Can be set to `0` to disable the use of small data | ||
sections. | ||
|
||
Target support is indicated by the `small_data_threshold_support` target | ||
option which can be: | ||
|
||
- `none` (`SmallDataThresholdSupport::None`) for no support | ||
- `default-for-arch` (`SmallDataThresholdSupport::DefaultForArch`) which | ||
is automatically translated into an appropriate value for the target. | ||
- `llvm-module-flag=<flag_name>` | ||
(`SmallDataThresholdSupport::LlvmModuleFlag`) for specifying the | ||
threshold via an LLVM module flag | ||
- `llvm-arg=<arg_name>` (`SmallDataThresholdSupport::LlvmArg`) for | ||
specifying the threshold via an LLVM argument. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Test for -Z small_data_threshold=... | ||
//@ revisions: RISCV MIPS HEXAGON M68K | ||
//@ assembly-output: emit-asm | ||
//@ compile-flags: -Z small_data_threshold=4 | ||
//@ [RISCV] compile-flags: --target=riscv32im-unknown-none-elf | ||
//@ [RISCV] needs-llvm-components: riscv | ||
//@ [MIPS] compile-flags: --target=mips-unknown-linux-uclibc -C relocation-model=static | ||
//@ [MIPS] compile-flags: -C llvm-args=-mgpopt -C llvm-args=-mlocal-sdata | ||
//@ [MIPS] compile-flags: -C target-feature=+noabicalls | ||
//@ [MIPS] needs-llvm-components: mips | ||
//@ [HEXAGON] compile-flags: --target=hexagon-unknown-linux-musl -C target-feature=+small-data | ||
//@ [HEXAGON] compile-flags: -C llvm-args=--hexagon-statics-in-small-data | ||
//@ [HEXAGON] needs-llvm-components: hexagon | ||
//@ [M68K] compile-flags: --target=m68k-unknown-linux-gnu | ||
//@ [M68K] needs-llvm-components: m68k | ||
|
||
#![feature(no_core, lang_items)] | ||
#![no_std] | ||
#![no_core] | ||
#![crate_type = "lib"] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
#[lang = "drop_in_place"] | ||
fn drop_in_place<T>(_: *mut T) {} | ||
|
||
#[used] | ||
#[no_mangle] | ||
// U is below the threshold, should be in sdata | ||
static mut U: u16 = 123; | ||
|
||
#[used] | ||
#[no_mangle] | ||
// V is below the threshold, should be in sbss | ||
static mut V: u16 = 0; | ||
|
||
#[used] | ||
#[no_mangle] | ||
// W is at the threshold, should be in sdata | ||
static mut W: u32 = 123; | ||
|
||
#[used] | ||
#[no_mangle] | ||
// X is at the threshold, should be in sbss | ||
static mut X: u32 = 0; | ||
|
||
#[used] | ||
#[no_mangle] | ||
// Y is over the threshold, should be in its own .data section | ||
static mut Y: u64 = 123; | ||
|
||
#[used] | ||
#[no_mangle] | ||
// Z is over the threshold, should be in its own .bss section | ||
static mut Z: u64 = 0; | ||
|
||
// Currently, only MIPS and RISCV successfully put any objects in the small data | ||
// sections so the U/V/W/X tests are skipped on Hexagon and M68K | ||
|
||
//@ RISCV: .section .sdata, | ||
//@ RISCV-NOT: .section | ||
//@ RISCV: U: | ||
//@ RISCV: .section .sbss | ||
//@ RISCV-NOT: .section | ||
//@ RISCV: V: | ||
//@ RISCV: .section .sdata | ||
//@ RISCV-NOT: .section | ||
//@ RISCV: W: | ||
//@ RISCV: .section .sbss | ||
//@ RISCV-NOT: .section | ||
//@ RISCV: X: | ||
|
||
//@ MIPS: .section .sdata, | ||
//@ MIPS-NOT: .section | ||
//@ MIPS: U: | ||
//@ MIPS: .section .sbss | ||
//@ MIPS-NOT: .section | ||
//@ MIPS: V: | ||
//@ MIPS: .section .sdata | ||
//@ MIPS-NOT: .section | ||
//@ MIPS: W: | ||
//@ MIPS: .section .sbss | ||
//@ MIPS-NOT: .section | ||
//@ MIPS: X: | ||
|
||
//@ CHECK: .section .data.Y, | ||
//@ CHECK-NOT: .section | ||
//@ CHECK: Y: | ||
//@ CHECK: .section .bss.Z, | ||
//@ CHECK-NOT: .section | ||
//@ CHECK: Z: |