-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
applications: sdp: Add asm_gen target #17638
Conversation
CI InformationTo view the history of this post, clich the 'edited' button above Inputs:Sources:sdk-nrf: PR head: d2efaacdfc7529e14dfa9b47f0a5ed8711218e72 more detailssdk-nrf:
Github labels
List of changed files detected by CI (6)
Outputs:ToolchainVersion: 3dd8985b56 Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped;
|
You can find the documentation preview for this PR at this link. It will be updated about 10 minutes after the documentation build succeeds. Note: This comment is automatically posted by the Documentation Publishing GitHub Action. |
6b53169
to
8f89e65
Compare
cmake/sdp.cmake
Outdated
|
||
zephyr_include_directories(include) | ||
|
||
add_custom_target(asm_gen |
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.
please specify BYPRODUCTS
.
Also, I can see this create a custom asm_gen
target, but afaict there is no use of this target / its byproducts in the build system, and I see no documentation describing the intention or usage of this target.
How / when is this target intended to be invoked ?
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 just a part of a larger work related to generating assembler files for the Hard-Real Time part of SDP. This PR only aims to add a custom target in the form of asm_gen
, which will be used in subsequent PRs.
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.
please let the original commenter decide if the comment has been resolved.
This is not done:
please specify BYPRODUCTS.
also, regarding this:
This is just a part of a larger work related to generating assembler files for the Hard-Real Time part of SDP.
That might be, but without corresponding code I cannot review this function in depth, namely I cannot verify incremental builds or check that byproducts are correctly removed on a ninja clean
.
If I approve this PR and later discover issues with the code in your next PR which uses the function , then that just results in a reply to me that, but this function was approved in PR#17638
(talking by experience).
So I need at least the follow up / usage of this code to be able to verify the full behavior of this code.
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.
@tejlmand here is my draft PR that uses asm_gen
: #18018. The intention is to run asm_check
either in west build after the CMake configuration and before the building starts, or directly in CMake at the beginning of a build. We want to run asm_check
in every SDP build, so that if someone changes the hrt/.c file, they know that the ASM file should be updated (the .c file will not be included in the build, it only serves as a source to generate the ASM file. The ASM file will be included in the build instead). We do not want to update the ASM file by default because it may change solely because a different compiler was used - which is what we are trying to avoid here.
Please, note that my PR is still a work in progress, thus calling asm_check
is not added yet.
Also, if anything is done incorrectly in this PR, it is most likely also done incorrectly in mine, as I was basing my work on it.
8f89e65
to
79cad1c
Compare
79cad1c
to
0385e0d
Compare
0385e0d
to
628448e
Compare
628448e
to
e29c043
Compare
@tejlmand can you take a look? |
scripts/sdp/clean_asm.py
Outdated
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 lack the reason for this clean_asm.py
file.
Why is it important to remove all lines starting with a #
in the assembly files ?
The files generated by the compilation proper step (-S
) should always generate valid assembly files.
If you're trying to handle badly written user files, then perhaps it's better to ensure they write proper asm files in first place instead of outsmart as
.
Perhaps check the docs regarding binutils as
.
https://sourceware.org/binutils/docs/as/ARM_002dChars.html
https://sourceware.org/binutils/docs/as/Comments.html
https://sourceware.org/binutils/docs/as/Preprocessing.html
More information needed regarding the purpose.
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 reason is that an assembly file will include full path to original files in some of the comments.
Those are unique to the user's environment and would come up as a diff when comparing functionally identical assembly files.
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 reason is that an assembly file will include full path to original files in some of the comments.
do you have any examples ?
Generally there should not be comments starting with # ...
when only doing the compilation proper (-S
).
Have you perhaps been using -E
during local local testing ?
Using -E
(without -P
) will stop right after pre-processing.
Note -P
will not create line markers.
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.
e29c043
to
9a02543
Compare
@tejlmand I addressed your comments. Please check it out as soon as possible. |
I've noticed that hrt.s file was removed in the recent push. Was it intentional? |
Yes, because this is just the output file from the sample hrt.c and is not needed in the repo. The target files will be uploaded with this PR: |
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.
Thanks for the update.
This looks much better 👍
But i'm still not convinced on the need for remove_comments.py
script.
I have a feeling the issue you might have seen has been due to using -E
instead -S
during local testing / development, and when using -E
you have been omitting -P
.
Note, the below sub-comment is not directly related to this PR, and thus us not blocking approval of the PR.
Note that any Kconfig optimization change, for example -DCONFIG_SPEED_OPTIMIZATIONS=y
or -DCONFIG_DEBUG_OPTIMIZATIONS=y
will impact the generated assembly file, but if the assembly file is intended for hard real time support, then I don't think that is desirable.
And in such cases, as well as situations where an assembly file has further been hand optimized, then I don't think it's wise to always be printed a warning that you cannot turn off, as it currently is presented in #18018.
cmake/sdp.cmake
Outdated
|
||
function(sdp_assembly_generate hrt_srcs) | ||
set(hrt_msg "Generating ASM files for Hard Real Time files.") | ||
set(hrt_opts -g0 -P -fno-ident -fno-verbose-asm) |
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.
why -P
?
You are stopping after compiler proper, not after the preprocessor, so there should be no line markers in the assemply.
Ref: https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Preprocessor-Options.html
-P
Inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers.
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.
To generate asm output we use the -S
option, not -E
.
I also removed the -P
because the code looks the same with and without it, and the comments are still there:
If you can suggest something that will allow me to remove these comments from the asm file without having to use a Python script, I would be grateful.
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.
To generate asm output we use the -S option, not -E.
yes, I know, I was just curious if you during development had been using -E
, in which case you normally see the # <lineno> "<path>"
It's common to see people experiencing issues during development with certain flags, and thus introducing fixes.
Fixes which later becomes obsolete when later changes are introduced.
So was trying to avoid such case.
Are you using the #APP
and #NO_APP
identifiers in the original source file ?
Will ping ofline for more into.
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.
seems to be caused by inline assembly.
Please note that not every version of gcc will use #
, you can also risk a @
, for example like this:
@ 14 "/projects/github/review/nrf/applications/sdp/gpio/src/hrt/hrt.c" 1
.align 1
@ 0 "" 2
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.
current investigation has found no options to prevent gcc from placing a file comment in generated assembly.
One risk with the post comment removal is the fact that gcc can use #
or @
as comment identifier.
One factor impacting gcc's choice seems to be the -std=<std>
in use.
An alternative is to invoke the compiler from the source folder or west workspace, and then use a relative path to the source file.
This can be done by setting WORKING_DIRECTORY <dir>
and adjust the input source path accordingly.
This can result in generated output like:
@ 14 "hrt.c" 1
.align 1
@ 0 "" 2
or
@ 14 "nrf/applications/sdp/gpio/src/hrt/hrt.c" 1
.align 1
@ 0 "" 2
but for this PR, such change is not requested.
It's better to do such alternative in future followup.
message(FATAL_ERROR "sdp_assembly_generate() was called on a directory") | ||
endif() | ||
get_filename_component(src_filename ${hrt_src} NAME_WE) # filename without extension | ||
add_custom_command(TARGET asm_gen |
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 will be a problem if the sdp_assembly_generate()
function is called multiple times, for example like this:
sdp_assembly_generate(foo.c)
sdp_assembly_generate(bar.c)
because there can only be a single asm_gen
target created.
This might be an acceptable limitation for now, but could you please make this check and provide a use-ful error to the user, for example a check like this:
if(TARGET asm_gen)
message(FATAL_ERROR "sdp_assembly_generate() already called, please note that
sdp_assembly_generate() must be called only once with a list of all source files."
)
endif()
Note, line length not checked in above example.
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 message with FATAL_ERROR
has been added.
Added asm_gen target, which is needed to generate assembler files for the hard real time part. Signed-off-by: Jakub Zymelka <[email protected]>
763b935
to
d2efaac
Compare
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.
approving.
Not fond of the current post-process as I'm concerned we will see issues / corner-cases in future. See #17638 (comment).
But approach is approved for now, but do create follow ticket for future improvements.
# Filter out lines starting with # | ||
cleaned_lines = [line for line in lines if not line.startswith('#')] |
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.
note, gcc may use @
instead.
See #17638 (comment)
Added asm_gen target, which is needed to generate assembler files for the hard real time part.