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

scripts: code_relocate: support section filter #74402

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

schouleu
Copy link

One might want to select the symbols to be relocated inside a file or a library.
To do this, one can use the FILTER argument of zephyr_code_relocate which
must contain a regular expression of the section names to be selected for relocation.

This pull-request covers the issue #64148

About the dependency on -ffunction-sections and -fdata-sections flags, those are enabled by default in arch/common//home/schouleur/GML/zephyr_upstream/zephyr/arch/common/CMakeLists.txt:37

In case the flags are not enabled, this feature can also be used to select some specific sections.

One might want to select the symbols to be relocated inside a file or
a library. To do this, one can use the FILTER argument of
zephyr_code_relocate which must contain a regular expression of the
section names to be selected for relocation.

Signed-off-by: Sylvain Chouleur <sylvain.chouleur@gmail.com>
@MaureenHelm
Copy link
Member

@tejlmand can you take a look please?

Comment on lines +540 to +541
# Replace pipes used in symbol filter regular expression
input_rel_dict = input_rel_dict.replace("\\|", "##PIPE##")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the | is used widely in regex'es, so it's natural to support them directly, but going through this substitution seems less than optimal to me.

This PR #60999 changed the input relocation argument from being a string to be a file.

Being a file actually means that there is no reason for a single string because a file can be multi-line.
I suggest to make a #60999 follow-up commit which remove the use of | as separator and instead create a multi-line input file.

Doing so will free the use of | and thereby remove the need for special handling in the regex.

@@ -514,12 +520,13 @@ def parse_input_string(line):
phdr, rest = rest.split(':', 1)

# Split lists by semicolons, in part to support generator expressions
flag_list, file_list = (lst.split(';') for lst in rest.split(':', 1))
flag_list, file_list, symbol_filter = (lst.split(';') for lst in rest.split(':', 2))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails on windows, most likely because drive letters contains :.

c:/users/torsten/zephyr-sdk-0.16.8/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(test_file1.c.obj): in function `code_relocation_test_function_in_sram2':
C:/projects/github/ncs/zephyr/tests/application_development/code_relocation/src/test_file1.c:80: undefined reference to `__sram2_data_reloc_start'
c:/users/torsten/zephyr-sdk-0.16.8/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: C:/projects/github/ncs/zephyr/tests/application_development/code_relocation/src/test_file1.c:80: undefined reference to `__sram2_data_reloc_end'
....

Also note the existing warning in this script:

# Be careful when splitting by : to avoid breaking absolute paths on Windows

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tejlmand do you have a way to test on windows without windows?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately not.

@carlescufi
Copy link
Member

@schouleu do you have plans to address @tejlmand's comments?

@schouleu
Copy link
Author

schouleu commented Sep 6, 2024

Hi @carlescufi
Yes, I don't have a lot of time right now but I'll implement @tejlmand's suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants