Skip to content

Commit

Permalink
[CHERRY-PICK] MdePkg/BaseMemoryLib: Prevent potential VS2022 linker f…
Browse files Browse the repository at this point in the history
…ailure

After updating between various VS2022 versions such as 17.4 to
17.5, , linker failures began to appear in several modules because
`memset` is an unresolved symbol.

The following functions in BaseMemoryLib/MemLibGeneric.c have their
loop pattern replaced with the `memset` intrinsic function:

- `InternalMemSetMem16()`
- `InternalMemSetMem32()`
- `InternalMemSetMem64()`

An example of an error related to `InternalMemSetMem64()` in
VariableSmmRuntimeDxe is shown below:

```
INFO - BaseMemoryLib.lib(MemLibGeneric.obj) : error LNK2001:
         unresolved external symbol memset
INFO - <...>\VariableSmmRuntimeDxe.dll : fatal error LNK1120:
         1 unresolved externals
```

This was reproduced in several environments including:

- Public VM image:
  https://github.com/actions/runner-images/blob/win22/20230226.1/images/win/Windows2022-Readme.md

- Locally when updating from 17.4.4 to 17.5.1

> Note: This image (with 17.4) does not have this issue
  https://github.com/actions/runner-images/blob/win22/20230219.1/images/win/Windows2022-Readme.md

This change updates the type cast for the destination buffer to be
a pointer to `volatile` data to prevent this optimization with a
relatively minimum delta to prior implementation.

Signed-off-by: Michael Kubacki <[email protected]>
(cherry picked from commit c46bc0ea98b4a8483c970e2282ea46891ea94f57)
  • Loading branch information
makubacki committed Mar 3, 2025
1 parent 59f4100 commit b077d2f
Showing 1 changed file with 0 additions and 6 deletions.
6 changes: 0 additions & 6 deletions MdePkg/Library/BaseMemoryLib/MemLibGeneric.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ InternalMemSetMem16 (
)
{
for ( ; Length != 0; Length--) {
// MU_CHANGE use a pointer to volatile data to prevent Visual Studio 17.5 (VS2022)
// from replacing the assignment with a `memset()` intrinsic
((volatile UINT16 *)Buffer)[Length - 1] = Value;
}

Expand All @@ -59,8 +57,6 @@ InternalMemSetMem32 (
)
{
for ( ; Length != 0; Length--) {
// MU_CHANGE use a pointer to volatile data to prevent Visual Studio 17.5 (VS2022)
// from replacing the assignment with a `memset()` intrinsic
((volatile UINT32 *)Buffer)[Length - 1] = Value;
}

Expand All @@ -86,8 +82,6 @@ InternalMemSetMem64 (
)
{
for ( ; Length != 0; Length--) {
// MU_CHANGE use a pointer to volatile data to prevent Visual Studio 17.5 (VS2022)
// from replacing the assignment with a `memset()` intrinsic
((volatile UINT64 *)Buffer)[Length - 1] = Value;
}

Expand Down

0 comments on commit b077d2f

Please sign in to comment.