target: default to the medium code model on LoongArch targets by heiher · Pull Request #130266 · rust-lang/rust

@xen0n @heiher

The Rust LoongArch targets have been using the default LLVM code model
so far, which is "small" in LLVM-speak and "normal" in LoongArch-speak.
As described in the "Code Model" section of LoongArch ELF psABI spec
v20231219 [1], one can only make function calls as far as ±128MiB with
the "normal" code model; this is insufficient for very large software
containing Rust components that needs to be linked into the big text
section, such as Chromium.

Because:

* we do not want to ask users to recompile std if they are to build
  such software,
* objects compiled with larger code models can be linked with those
  with smaller code models without problems, and
* the "medium" code model is comparable to the "small"/"normal" one
  performance-wise (same data access pattern; each function call
  becomes 2-insn long and indirect, but this may be relaxed back into
  the direct 1-insn form in a future LLVM version), but is able to
  perform function calls within ±128GiB,

it is better to just switch the targets to the "medium" code model,
which is also "medium" in LLVM-speak.

[1]: https://github.com/loongson/la-abi-specs/blob/v2.30/laelf.adoc#code-models

Co-authored-by: WANG Rui <wangrui@loongson.cn>

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

labels

Sep 12, 2024

@bors bors added the S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

label

Sep 13, 2024

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 13, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#129320 (Fix crash when labeling arguments for call_once and friends)
 - rust-lang#130266 (target: default to the medium code model on LoongArch targets)
 - rust-lang#130297 (Dataflow cleanups)
 - rust-lang#130299 (Add set_dcx to ParseSess)
 - rust-lang#130301 (some fixes for clashing_extern_declarations lint)
 - rust-lang#130305 (Clippy: consider msrv for const context for const_float_bits_conv)

r? `@ghost`
`@rustbot` modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Sep 13, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#129320 (Fix crash when labeling arguments for call_once and friends)
 - rust-lang#130266 (target: default to the medium code model on LoongArch targets)
 - rust-lang#130297 (Dataflow cleanups)
 - rust-lang#130299 (Add set_dcx to ParseSess)
 - rust-lang#130301 (some fixes for clashing_extern_declarations lint)
 - rust-lang#130305 (Clippy: consider msrv for const context for const_float_bits_conv)

r? `@ghost`
`@rustbot` modify labels: rollup

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Sep 13, 2024
Rollup merge of rust-lang#130266 - heiher:loong-medium-cmodel, r=compiler-errors

target: default to the medium code model on LoongArch targets

The Rust LoongArch targets have been using the default LLVM code model so far, which is "small" in LLVM-speak and "normal" in LoongArch-speak. As described in the "Code Model" section of LoongArch ELF psABI spec v20231219 [1], one can only make function calls as far as ±128MiB with the "normal" code model; this is insufficient for very large software containing Rust components that needs to be linked into the big text section, such as Chromium.

Because:

* we do not want to ask users to recompile std if they are to build such software,
* objects compiled with larger code models can be linked with those with smaller code models without problems, and
* the "medium" code model is comparable to the "small"/"normal" one performance-wise (same data access pattern; each function call becomes 2-insn long and indirect, but this may be relaxed back into the direct 1-insn form in a future LLVM version), but is able to perform function calls within ±128GiB,

it is better to just switch the targets to the "medium" code model, which is also "medium" in LLVM-speak.

Relands [2]:  rust-lang#120661

[1]: https://github.com/loongson/la-abi-specs/blob/v2.30/laelf.adoc#code-models
[2]: rust-lang#121289 (comment)

@heiher heiher deleted the loong-medium-cmodel branch

September 14, 2024 02:01

@xen0n xen0n mentioned this pull request

Sep 14, 2024

heiher added a commit to heiher/rust that referenced this pull request

Oct 18, 2024
The context for this is rust-lang#130266: setting the medium code model for the
'loongarch64-linux-ohos' target.

jhpratt added a commit to jhpratt/rust that referenced this pull request

Oct 18, 2024
Default to the medium code model on OpenHarmony LoongArch target

The context for this is rust-lang#130266: setting the medium code model for the `loongarch64-linux-ohos` target.

r? `@jieyouxu`

jhpratt added a commit to jhpratt/rust that referenced this pull request

Oct 18, 2024
Default to the medium code model on OpenHarmony LoongArch target

The context for this is rust-lang#130266: setting the medium code model for the `loongarch64-linux-ohos` target.

r? ``@jieyouxu``

jieyouxu added a commit to jieyouxu/rust that referenced this pull request

Oct 18, 2024
Default to the medium code model on OpenHarmony LoongArch target

The context for this is rust-lang#130266: setting the medium code model for the `loongarch64-linux-ohos` target.

r? ```@jieyouxu```

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Oct 18, 2024
Rollup merge of rust-lang#131874 - heiher:loong-ohos-medium, r=jieyouxu

Default to the medium code model on OpenHarmony LoongArch target

The context for this is rust-lang#130266: setting the medium code model for the `loongarch64-linux-ohos` target.

r? ```@jieyouxu```

nikic added a commit to nikic/rust that referenced this pull request

Feb 17, 2025

@nikic nikic mentioned this pull request

Feb 17, 2025

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Feb 17, 2025
…ingjubilee

Update default loongarch code model in docs

Since rust-lang#130266 loongarch defaults to medium code model.

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Feb 18, 2025
Rollup merge of rust-lang#137166 - nikic:loongarch-code-model, r=workingjubilee

Update default loongarch code model in docs

Since rust-lang#130266 loongarch defaults to medium code model.

github-merge-queue bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request

Feb 24, 2025
Update default loongarch code model in docs

Since rust-lang/rust#130266 loongarch defaults to medium code model.

@xen0n xen0n mentioned this pull request

Oct 13, 2025

10 tasks