Skip to content
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

linker: update section names to be unambiguous #87395

Merged
merged 1 commit into from
Mar 20, 2025

Conversation

fabiobaltieri
Copy link
Member

@fabiobaltieri fabiobaltieri commented Mar 20, 2025

Recently 0ae0c3d allowed for three digit priorities, this resulted in objects potentially matching multiple sections, for example:

.z_init_PRE_KERNEL_2_0_0_
.z_init_PRE_KERNEL_2_?_*
.z_init_PRE_KERNEL_2_???_*

This does not seem to be detected by ld, but the IAR linker emits a warning.

Add some extra qualifiers in the object section name to make it unambiguous, this has the extra value of making it easier to interpret, for example going from:

.z_init_POST_KERNEL_90_00012_

to

.z_init_POST_KERNEL_P_90_SUB_00012_

@fabiobaltieri
Copy link
Member Author

cc @dewitt-garmin @GoranWall, would this fix the issue detected in #86999 (comment)?

@fabiobaltieri fabiobaltieri requested a review from kartben March 20, 2025 11:33
Recently 0ae0c3d allowed for three digit priorities, this resulted
in objects potentially matching multiple sections, for example:

.z_init_PRE_KERNEL_2_0_0_
.z_init_PRE_KERNEL_2_?_*
.z_init_PRE_KERNEL_2_???_*

This does not seem to be detected by ld, but the IAR linker emits a
warning.

Add some extra qualifiers in the object section name to make it
unambiguous, this has the extra value of making it easier to interpret,
for example going from:

.z_init_POST_KERNEL_90_00012_

to

.z_init_POST_KERNEL_P_90_SUB_00012_

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
@fabiobaltieri fabiobaltieri added Compliance: False Positive Hotfix Fix for issues blocking development, i.e. CI issues, tests failing in CI, etc. and removed Hotfix Fix for issues blocking development, i.e. CI issues, tests failing in CI, etc. labels Mar 20, 2025
@RobinKastberg
Copy link
Contributor

@fabiobaltieri the IAR linker doesn't complain with this.

@dewitt-garmin
Copy link
Contributor

Good catch. Another option might be to use a character class, [0-9], instead of ?

@fabiobaltieri
Copy link
Member Author

fabiobaltieri commented Mar 20, 2025

Good catch. Another option might be to use a character class, [0-9], instead of ?

Interesting, did not realize the linker supported it, not sure why that hasn't been used in the first place but I feel like it may not be supported by some old release or something like that, though it's used in include/zephyr/linker/common-rom/common-rom-kernel-devices.ld so I think it should work?

I think it's worth a try, but maybe let's merge this now to remove the ambiguity issue and consider that for a followup, and then we can revert it separately if something breaks.

I like the new symbols names anyway, makes them way more understandable.

@fabiobaltieri fabiobaltieri added the Hotfix Fix for issues blocking development, i.e. CI issues, tests failing in CI, etc. label Mar 20, 2025
@fabiobaltieri
Copy link
Member Author

Tagging has hotfix, strictly speaking it does not break the CI, but one may argue that it should.

@pdgendt
Copy link
Collaborator

pdgendt commented Mar 20, 2025

Good catch. Another option might be to use a character class, [0-9], instead of ?

Interesting, did not realize the linker supported it, not sure why that hasn't been used in the first place but I feel like it may not be supported by some old release or something like that, though it's used in include/zephyr/linker/common-rom/common-rom-kernel-devices.ld so I think it should work?

There were issues with using [0-9] as this wasn't supported by all tools in the field.

@fabiobaltieri
Copy link
Member Author

There were issues with using [0-9] as this wasn't supported by all tools in the field.

@pdgendt it's used in here though:

Do you happen to remember the specific issue?

@dewitt-garmin
Copy link
Contributor

Good catch. Another option might be to use a character class, [0-9], instead of ?

Interesting, did not realize the linker supported it, not sure why that hasn't been used in the first place but I feel like it may not be supported by some old release or something like that, though it's used in include/zephyr/linker/common-rom/common-rom-kernel-devices.ld so I think it should work?

There were issues with using [0-9] as this wasn't supported by all tools in the field.

Do you know what tools could not support this? I just tried [0-9] and all of the ones that twister builds seemed to pass but as we have just seen that apparently is not sufficient. Maybe IAR is also the limitation here?

@RobinKastberg
Copy link
Contributor

Yeah.. These linker wildcards are NOT regexps, even though it seems ld supports a little bit more than we (IAR do)
This is IAR documentation:
From https://wwwfiles.iar.com/arm/webic/doc/EWARM_DevelopmentGuide.ENU.pdf

section section-name Only sections whose names match the section-name
                     will be selected. Two wildcards are allowed: 
                     ? matches any single character
                     * matches zero or more characters

Note: A section selector with narrower scope has higher priority than a more generic 
section selector. If more than one section selector matches for the same purpose, one of 
them must be more specific. A section selector is more specific than another one if in 
priority order:
* It specifies a public symbol name with no wildcards and the other one does not.
* It specifies a section name or object name with no wildcards and the other one does 
not
* It specifies a section type and the other one does not
* There could be sections that match the other selector that also match this one, 
however, the reverse is not true.

@LoveKarlsson
Copy link
Contributor

There were issues with using [0-9] as this wasn't supported by all tools in the field.

@pdgendt it's used in here though:

Do you happen to remember the specific issue?

I have a PR to remove that regular expression, as the IAR linker does not support regular expressions.

#87112

@nashif nashif merged commit c60ffe1 into zephyrproject-rtos:main Mar 20, 2025
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System area: Device Model area: Linker Scripts Compliance: False Positive Hotfix Fix for issues blocking development, i.e. CI issues, tests failing in CI, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants