Skip to content

Linker scripts: remove malformed DISCARD block that pulled in full newlib - #715

Open
zeroisnan wants to merge 1 commit into
electro-smith:masterfrom
zeroisnan:cmake-newlib-nano
Open

Linker scripts: remove malformed DISCARD block that pulled in full newlib#715
zeroisnan wants to merge 1 commit into
electro-smith:masterfrom
zeroisnan:cmake-newlib-nano

Conversation

@zeroisnan

Copy link
Copy Markdown
Contributor

Removes the DISCARD block from core/STM32H750IB_flash.lds, _qspi.lds and _sram.lds.

DISCARD is not /DISCARD/, so the block never discarded anything. What it did do is name libc.a, libm.a and libgcc.a as plain filenames, which makes GNU ld load those archives. Full newlib's libc.a therefore entered every link. Under CMake the script is passed as -Wl,-T,... and so sits early on the linker command line, where it satisfies symbols before newlib-nano is reached; the Makefile passes -T$(LDSCRIPT), which GCC places last, so it was unaffected.

Verification on examples/SerialPrint:

_impure_data before after
CMake 288 B 76 B
Make 76 B 76 B

A typical stdio-using example drops 2,832 B flash and 1,304 B RAM.

Both build systems were checked across every storage layout the linker scripts serve:

  • CMake — all 35 examples built under DAISY_STORAGE=flash, sram and qspi, before and after. After the change none of the 105 resulting binaries links any member of full libc.a, and every _impure_data that survives --gc-sections is newlib-nano's 76 B. All three layouts behave identically.
  • Make — every example built under APP_TYPE=BOOT_NONE, BOOT_SRAM and BOOT_QSPI, before and after. All 137 resulting ELFs are byte-identical, so the Makefile path is unaffected.

(examples/QSPI_EraseTiming does not link under APP_TYPE=BOOT_SRAM, overflowing DTCMRAM by ~156 KB. That is pre-existing and identical before and after this change; it is excluded from the 137 above and left alone here.)

Fixes #714.

🤖 Generated with Claude Code

…wlib

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CMake build uses full newlib instead of newlib-nano

1 participant