Skip to content

Binary size regression on MSP430 #165189

In review

Description

@RossPorter506

A large binary size regression appeared between nightly-2026-10-22 and nightly-2026-10-23 on the MSP430 target, increasing binary size by ~40%, from 23KiB to 33KiB. It persists on the latest nightly-2026-10-29 toolchain.
While running CI for the msp430-hal project, I noticed some examples suddenly failing to link due to insufficient space on the target device. For example, building spi_nb.rs:

cd device_examples/msp430fr2355
cargo +nightly-2026-10-22 build --example spi_nb

Analyzing the generated binary shows it's about 23KiB:

$ msp430-elf-size -A target/msp430-none-elf/debug/examples/spi_nb
target/msp430-none-elf/debug/examples/spi_nb  :
section                 size    addr
.defmt                     3       1
.vector_table             92   65444
.text                   9530   32768
.rodata                14100   42300
.bss                       2    8192
.data                      0    8194

But the same example built with cargo +nightly-2026-10-23 build --example spi_nb produces a binary that's too large to fit in program memory: region 'ROM' overflowed by 548 bytes.
If we modify the memory.x file to pretend to have more space than we actually do, we can see the generated binary would have been about 33KiB:

$ msp430-elf-size -A target/msp430-none-elf/debug/examples/spi_nb
target/msp430-none-elf/debug/examples/spi_nb  :
section                 size    addr
.defmt                     3       1
.vector_table             92   65444
.text                  15590   12288 <--- significantly bigger
.rodata                17596   27880 <--- bigger
.bss                       2    8192
.data                      0    8194

Removing the possibly fallible .unwrap()s on lines 52 and 58 makes the regression disappear (also reducing the binary size to practically nothing), so I presume this is related to unwrapping an Err variant, and string parsing during a panic.

If you want to replicate this, you will need to download the msp430-hal repo, install the MSP430-GCC toolchain, then the rust toolchains (and rust-src):

rustup install nightly-2026-10-22
rustup component add rust-src --toolchain nightly-2026-10-22-x86_64-unknown-linux-gnu
rustup install nightly-2026-10-23
rustup component add rust-src --toolchain nightly-2026-10-23-x86_64-unknown-linux-gnu

You can then cd into the device_examples/msp430fr2355 folder and build the examples.

Activity

  1. added
    C-bug
    on Oct 30, 2026
  2. added
    needs-triage
    on Oct 30, 2026
  3. added
    I-heavy
    T-libs
    and removed
    needs-triage
    on Oct 30, 2026
  4. maxdexh commented on Oct 30, 2026

    @maxdexh
    Member

    Do we not have target maintainers for this tier 3 target?

    Edit: I suppose not #113739 (comment)

  5. added
    T-compiler
    and removed
    T-compiler
    on Oct 30, 2026
  6. folkertdev commented on Oct 30, 2026

    @folkertdev
    Contributor

    Something changed in how Debug implementations are generated, I think that is the underlying cause. This is not platform-specific, e.g. here it's quite obvious for x86_64 https://godbolt.org/z/z8rTKe6j6.

    Using "link to binary", the total output size jumps from ~1000 to ~2600 lines. The new output includes CharSearcher, slice_error_fail_rt, and a whole bunch of unicode/char logic. Based on the commit range and the problem I suspect #162535 is the cause.

  7. Jules-Bertholet commented on Oct 30, 2026

    @Jules-Bertholet
    Contributor

    My guess is the .split(' ') call. We really need a version of that specialized for ASCII…

  8. Jules-Bertholet commented on Oct 30, 2026

    @Jules-Bertholet
    Contributor

    @RossPorter506 can you check whether #165195 resolves the issue?

  9. panstromek commented on Oct 30, 2026

    @panstromek
    Contributor

    8. My guess is the .split(' ') call. We really need a version of that specialized for ASCII…

    We have split_ascii_whitespace at least. I'm doing some experiments with it in #165179

  10. panstromek commented on Oct 30, 2026

    @panstromek
    Contributor

    For context, apart from #162535, #164726 landed yesterday, it does the same thing for structs.

    [edit] #165140 should fix all the issues now (contains fixes from #165195 and two more changes that came up from the following discussions)

  11. Jules-Bertholet commented on Nov 2, 2026

    @Jules-Bertholet
    Contributor

    Should be fixed by #165140

  12. panstromek commented on Nov 2, 2026

    @panstromek
    Contributor

    One thing that I find concerning is that there was pretty much no indication that this might be a problem, neither from our test suite, nor from our benchmarks - some even show binary size improvements.

    If the interpretation of this issue is that we should never regress this, which I think is reasonable, then that has some significant implications - notably, that we should never use some fairly basic string manipulation primitives in some parts of the core (and maybe we should clarify which parts), and we somehow need to ensure that going forward.

    I will mark this as "needs-test" for now. I'm not exactly sure what to do, but I think we can start by adding the spi_nb.rs example from above as benchmark.

    @rustbot label +E-needs-test

  13. added
    E-needs-test
    on Nov 2, 2026
  14. maxdexh commented on Nov 2, 2026

    @maxdexh
    Member

    We could just test the final binary size, like here: https://github.com/rust-lang/rust/blob/main/tests/run-make/wasm-panic-small/rmake.rs

    Otherwise we'd need function coloring to make sure that we don't accidentally call certain functions from certain other functions ^^

  15. Jules-Bertholet commented on Nov 2, 2026

    @Jules-Bertholet
    Contributor

    Long-term, we should have .split() accept ascii::Char, and a lint that checks for use of char where ascii::Char would do

  16. panstromek commented on Nov 2, 2026

    @panstromek
    Contributor

    That would certainly be nice, but the problem is not only split, but also just string indexing, which is even more basic.

    [edit] ..and something somebody might want to use to improve unwrap error message in the future, for example.

  17. RossPorter506 commented on Nov 3, 2026

    @RossPorter506
    Author

    Thanks for the quick responses and action! I've tested with nightly-2026-11-02 and the vast majority of the bloat has disappeared. The .rodata segment grew a bit from 14100 -> 14726 when compared to nightly-2026-10-23, but I'm content to write that off as the cost of progress. This is resolved from my side, though I will leave this issue open since there's still discussion about adding testing.

    Built with nightly-2026-11-02:

    msp430-elf-size -A target/msp430-none-elf/debug/examples/spi_nb
    target/msp430-none-elf/debug/examples/spi_nb  :
    section                 size    addr
    .defmt                     3       1
    .vector_table             92   65444
    .text                   9530   32768
    .rodata                14726   42300
    .bss                       2    8192
    .data                      0    8194
    
  18. panstromek commented on Nov 17, 2026

    @panstromek
    Contributor

    We could just test the final binary size, like here: https://github.com/rust-lang/rust/blob/main/tests/run-make/wasm-panic-small/rmake.rs

    That makes sense, I think we can take the Folkert's reproducer and add it as a this kind of test, it reproduces the problem pretty clearly and doesn't have any dependencies.

    If somebody wants to pick it up, feel free to do so, I'll add a label ;) I can do it later when I get through the backlog of other tasks.

  19. added
    E-help-wanted
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugE-help-wantedE-needs-testI-heavyO-msp430T-libs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions