Skip to content

Do not require the linker script on std - #91

Open
jakobjung10 wants to merge 1 commit into
probe-rs:masterfrom
jakobjung10:std-without-linker-script
Open

Do not require the linker script on std#91
jakobjung10 wants to merge 1 commit into
probe-rs:masterfrom
jakobjung10:std-without-linker-script

Conversation

@jakobjung10

Copy link
Copy Markdown

The script serves no purpose on std but still had to be passed to the linker, excluding linkers without linker script support. probe-rs does not read these binaries, and the setup default now comes from linkme.

Old embedded-test releases must not resolve to the new macros, hence 0.9.0.

The script serves no purpose on std but still had to be passed to the
linker, excluding linkers without linker script support. probe-rs does
not read these binaries, and the setup default now comes from linkme.

Old embedded-test releases must not resolve to the new macros, hence
0.9.0.
@t-moe

t-moe commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

While its true we dont need the linkerfile for the testcase list, Afaik the linker file was also needed to make sure main is not optimized away. (Main comes from a lib instead of from a binary as normally... )

Is this no longer a problem?

@jakobjung10

Copy link
Copy Markdown
Author

On std main is kept by the C runtime startup code, which references it as an undefined
symbol, the same thing that keeps an ordinary fn main. That holds with or without the
linker script.

Checked on x86_64-unknown-linux-gnu with this branch: rustc passes -Wl,--gc-sections and no -T,
nm shows T main in debug and release, and the binary lists and runs its tests. It also
builds and runs on x86_64-pc-windows-msvc, where link.exe can't take a linker script at all.

The script itself never referenced main. EXTERN(__embedded_test_start) and the PROVIDE
alias next to it were added in 27568dd to produce a link error when the script is missing from
the rustflags, and __embedded_test_start is called from main. KEEP(*(.embedded_test.*))
keeps the version symbol and the testcase metadata; on std the test list comes from linkme, so
that isn't needed either. Nothing changes for no_std, which still gets the script.

This also fixes macOS. .embedded_test.meta is an ELF section name and LLVM rejects it on
Mach-O ("mach-o section specifier requires a segment and section separated by a comma"), so on
master --features std doesn't compile for aarch64-apple-darwin at all. Gating that static out
is what makes it build.

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.

2 participants