Skip to content

Refactor avoid-default-panic to not rely on the linker script#1050

Open
knoellle wants to merge 2 commits intomainfrom
default-panic-no-linker-script
Open

Refactor avoid-default-panic to not rely on the linker script#1050
knoellle wants to merge 2 commits intomainfrom
default-panic-no-linker-script

Conversation

@knoellle
Copy link
Copy Markdown
Member

#812 introduced a feature to remove the default panicking behavior from for defmt::panic in case the user provides their own panic handler.
I don't know why this was implemented by modifying the linker script instead of just cfging out the whole function.

Not using the linker script for this also improves compatibility with macOS, see #1029 (comment)

Details

  • defmt::panic logs its error message, then calls _defmt_panic to do the actual panicking.
  • Previously, _defmt_panic wasn't defined anywhere but instead there was __defmt_default_panic.
  • These two symbols were then combined in the linker script unless the avoid-default-panic feature was enabled.
  • The new behavior just defines _defmt_panic IFF the feature is not enabled

@knoellle knoellle added the type: refactor parts of the code that should be improved or redesigned label Apr 20, 2026
@knoellle knoellle enabled auto-merge April 20, 2026 10:59
@knoellle
Copy link
Copy Markdown
Member Author

Damn, didn't think about the duplicate definitions.
That makes it a breaking change because users who were previously overriding the defmt panic handler are now required to use the avoid-default-panic feature to even compile.

The PROVIDES line in the linker script was effectively doing weak linking, which is supported by rust but hasn't been stabilized for over a decade now. rust-lang/rust#29603

Not sure if there is another way to achieve the same result without using either a linker script or an unstable feature.

@knoellle knoellle added the breaking change fix / feature / improvement involves a breaking change and needs to wait until next minor version label Apr 20, 2026
@knoellle knoellle disabled auto-merge April 20, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change fix / feature / improvement involves a breaking change and needs to wait until next minor version type: refactor parts of the code that should be improved or redesigned

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant