Skip to content

add custom linker script #103

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

Merged
merged 4 commits into from
Nov 28, 2022
Merged

Conversation

JojoS62
Copy link

@JojoS62 JojoS62 commented Nov 26, 2022

This is a PR for an additional feature:
a custom linker script can be applied by adding the .ld filepath as 2nd argument to mbed_set_post_build.

This PR replaces the draft #93

E.g. in CMakeLists.txt for an executable:

add_executable(Hello main.cpp)

target_link_libraries(Hello mbed-os)

mbed_set_post_build(Hello mbed-disco-f769ni-SRAM2.ld)

In this case, the .ld file must exist in the source dir of the project. The linker script is processed by the linker, so defines like in the mbed-os linkerscript templates can used in the same way.

The custom linker script is not applied to mbed built-in tests.

Summary of changes

adding a custom linker script is supported now.
It is necessary to map variables or code to linker supplied sections. Especially for M4 or M7 MCUs with serveral busses and DMA constraints makes it mandatory to specify memory addresses.

Impact of changes

This feature is optional and existing linker script is not changed unless a custom linker script is set.

Migration actions required

Documentation

Will be updated when this feature is merged.


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[x] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[x] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Tested with DISCO_F769NI

Reviewers

@multiplemonomials

a custom linker script can be applied by adding the .ld filepath
as 2nd argument to mbed_set_post_build
Copy link
Collaborator

@multiplemonomials multiplemonomials left a comment

Choose a reason for hiding this comment

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

Looking pretty good! Just a few minor changes.

Also, I made another MR to fix the CI failure issue. Feel free to approve that when you get a chance.

@JojoS62
Copy link
Author

JojoS62 commented Nov 28, 2022

The only thing I do not understand why I don't get the comment output from the custom command

    add_custom_command(
        TARGET
            ${target}
        PRE_LINK
        COMMAND
            ${CMAKE_C_COMPILER} @${linker_defs_response_file}
        COMMENT
            "Preprocess custom linker script: ${RAW_LINKER_SCRIPT_NAME} -> ${LINKER_SCRIPT_NAME}"
        VERBATIM
    )

The difference to the other custom command is OUTPUT/TARGET:

    add_custom_command(
        OUTPUT
            ${LINKER_SCRIPT_PATH}
        PRE_LINK
        COMMAND
            ${CMAKE_C_COMPILER} @${linker_defs_response_file}
            -E -x assembler-with-cpp
        COMMENT
            "Preprocess linker script: ${RAW_LINKER_SCRIPT_NAME} -> ${LINKER_SCRIPT_NAME}"
        VERBATIM
    )

The command is executed, the linker script is preprocessed and written to the target build dir. What is the reason that the comment "Preprocess custom linker script: ' is not shown?

edit:
it seems that COMMENT is not reliable printed:
https://cmake.org/pipermail/cmake/2017-April/065274.html
.
so I have changed the comments by using a cmake echo command

COMMENT is not reliable printed
Copy link
Collaborator

@multiplemonomials multiplemonomials left a comment

Choose a reason for hiding this comment

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

Looks good!

@multiplemonomials
Copy link
Collaborator

I am going to go ahead and merge this in spite of the CI failure, because that CI failure was fixed by #104 .

@multiplemonomials multiplemonomials merged commit 9d9ba58 into master Nov 28, 2022
@multiplemonomials multiplemonomials deleted the feature-custom-linker-script branch November 28, 2022 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants