microsoft / mu_basecore

Project Mu BaseCore
https://microsoft.github.io/mu/
Other
242 stars 124 forks source link

[2405] BaseTools/build_rule.template: Set additional Rust module linker flags #1103

Closed makubacki closed 2 months ago

makubacki commented 2 months ago

Description

Cherry-pick of 202311 change #1098 (e8b5c47785a5eff7f9a4deb3c34ae3b6333c632a)


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 to efi_boot_service_driver instead of the default target specification value of EFI_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 in build_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 in build_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

Integration Instructions

This change is marked as breaking in case flows were dependent on the previous behavior. Otherwise, no changes are nedeed.

codecov-commenter commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (release/202405@8c05410). Learn more about missing BASE report.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## release/202405 #1103 +/- ## ================================================= Coverage ? 1.55% ================================================= Files ? 1447 Lines ? 360627 Branches ? 4197 ================================================= Hits ? 5622 Misses ? 354945 Partials ? 60 ``` | [Flag](https://app.codecov.io/gh/microsoft/mu_basecore/pull/1103/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=microsoft) | Coverage Δ | | |---|---|---| | [MdeModulePkg](https://app.codecov.io/gh/microsoft/mu_basecore/pull/1103/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=microsoft) | `0.61% <ø> (?)` | | | [MdePkg](https://app.codecov.io/gh/microsoft/mu_basecore/pull/1103/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=microsoft) | `5.41% <ø> (?)` | | | [NetworkPkg](https://app.codecov.io/gh/microsoft/mu_basecore/pull/1103/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=microsoft) | `0.55% <ø> (?)` | | | [PolicyServicePkg](https://app.codecov.io/gh/microsoft/mu_basecore/pull/1103/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=microsoft) | `30.41% <ø> (?)` | | | [UefiCpuPkg](https://app.codecov.io/gh/microsoft/mu_basecore/pull/1103/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=microsoft) | `4.77% <ø> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=microsoft#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.