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

[multitop] Add better support for linker scripts (preprocessing) #25908

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

pamaury
Copy link
Contributor

@pamaury pamaury commented Jan 16, 2025

Alternative approach to #25785 that preprocesses linker scripts instead of using bazel templates.

For now, this PR choses the "easy" way of keep each's top linker file name and set a defines so that users that include the correct file without knowing the name. An alternative approach would be to rename the file so it's the same for all tops. Note that even renaming would not render the preprocess useless because further multitop changes down the line cannot be handled by just renaming.

Annoyance: I couldn't make cc_common.compile to work because it does not add anything to the cout output so one can't get the output file... I had to resort to manually run the compiler, I don't know if there is an easier way to do that. It's probably semi-overkill because for the purpose of preprocessing linker script, it's very unlikely that the environment or system includes will play any role but at least it's the "textbook" way of doing it.

@pamaury pamaury changed the title [multitop] Add better support for linker scripts [multitop] Add better support for linker scripts (preprocessing) Jan 16, 2025
Copy link
Contributor

@jwnrt jwnrt left a comment

Choose a reason for hiding this comment

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

I've gone over the Bazel part a couple of times and it looks good. Nice to see the get_tool_for_action used. (aside, I realised that I missed this for the other part of our repo that uses the preprocessor here: rules/ujson.bzl#L40).

I think this is better than using Bazel substitution as discussed in the other PR.

LGTM, thanks

@pamaury pamaury force-pushed the multitop_linker_scripts2 branch 2 times, most recently from c24080a to 9683aeb Compare January 16, 2025 18:25
rules/linker.bzl Outdated Show resolved Hide resolved
rules/linker.bzl Outdated Show resolved Hide resolved
@pamaury pamaury force-pushed the multitop_linker_scripts2 branch from 9683aeb to 5ac9ac0 Compare January 16, 2025 20:33
@pamaury
Copy link
Contributor Author

pamaury commented Jan 16, 2025

One thing to note about this PR which may be confusing: it gives two ways to include files: INCLUDE and #include. The files which are #include-ed are obviously preprocessed but the files which are INCLUDE-ed are not. Maybe we should make that clear in the documentation (it's technically there, but might not be obvious).

With this commit, linker script files are now preprocessed.
The is handled similarly to `cc_library`: if `ld_library` is used
with only files in `includes`, then it simply adds them to
the compilation context. If `ld_library` is used with `script` set,
then the file with be preprocessed with the compilation context
constructed from its dependencies.

This commit also adds a `defines` attribute to the `ld_library` so
that defines can be set in bazel BUILD files.

Signed-off-by: Amaury Pouly <[email protected]>
This avoid including by mistake the wrong file: because it is
marked as incompatible, it will fail to compile.

Signed-off-by: Amaury Pouly <[email protected]>
Each top has a different top linker file name. When dependencies
switch to multitop, then need to INCLUDE the correct file. This
commit adds a define OPENTITAN_TOP_MEMORY_LD which is set to
the file name so that user can do
INCLUDE OPENTITAN_TOP_MEMORY_LD

Signed-off-by: Amaury Pouly <[email protected]>
The OPENTITAN_TOP_MEMORY_LD define is set in each top's linker
library target.

Signed-off-by: Amaury Pouly <[email protected]>
@pamaury pamaury force-pushed the multitop_linker_scripts2 branch from 5ac9ac0 to d903a15 Compare January 16, 2025 21:10
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.

3 participants