[2405] BaseTools/build_rule.template: Set additional Rust module linker flags #1103
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Cherry-pick of 202311 change #1098 (e8b5c47)
This change sets the ImageBase in the PE header for Rust modules to
0
so they do not have a preferred base. This is similar to the EFI images produced by the edk2 build system. The subsystem type is also set toefi_boot_service_driver
instead of the default target specification value ofEFI_APPLICATION
. Details for changing the subsystem type are here:https://doc.rust-lang.org/nightly/rustc/platform-support/unknown-uefi.html#requirements
Ideally, these values would be set as individual
target.<triple>.rustflags
in.cargo/config.toml
. However, we override the/MAP
argument using-C linker-args
inbuild_rule.txt
to the build output directory. This must be set dynamically since the output directory and module name are based on per module values.Since the cargo configuration file does not support reading environment variables and setting an environment there in a
[env]
section would be too late to impact the commands that run inbuild_rules.txt
(cargo is called from cargo make based on those rules), this is the simplest approach to retain the map file path in addition to the new changes.In the future, this may be moved to a common target specification so the values are available without these changes.
How This Was Tested
ImageBase
andSubsystem
of EFI images in output directory to confirm expected values.Integration Instructions
This change is marked as breaking in case flows were dependent on the previous behavior. Otherwise, no changes are nedeed.