-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Move unique_id (configurably) earlier in the static init process #2379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move unique_id (configurably) earlier in the static init process #2379
Conversation
Fixes raspberrypi#2373 This enables using the unique_id in C++ static initializers by default
* \ingroup pico_unique_id | ||
* | ||
* This defines the init_priority of the pico_unique_id. By default, it is 1000. The valid range is | ||
* from 101-65535. Set to -1 to set the priority to none, thus putting it after 65535. Changing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that static initializers aren't something I know much about, but would there ever be a reason that you'd want to set this to -1 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current, existing behavior can be reverted to by setting to -1. I don't think there is a reason you couldn't use 65535 instead, but the default linker script order is that "-1" is after 65535 (I could call it 65536, but I think that may be more confusing, oddly enough)
Linker script: https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/pico_crt0/rp2040/memmap_default.ld#L79-L80
Note the .ctor.*
are the ones with init_priority, and .ctor
is the -1/default/old behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you would prefer, I can remove -1 and we then wait until someone hollers that we broke something? (I think that is unlikely, but not sure, as I haven't explicitly used init_priority before this year)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a @kilograham decision 😉
Fixes #2373
Move unique_id (configurably) earlier in the static initialization process . This enables using the unique_id in C++ static initializers by default, and avoid the static initialization order fiasco.
I added the configuration in the off chance that someone would need to adjust it, but I think 1000 is probably a good-enough default. Values range from 101-65535, or "none", which is after 65535. Normal C++ static initializers are "none". Users can still manually specify to be earlier (101-999) without any configuration changes, via any of the following:
The following will all be initialized after unique_id is initialized, by default