coff: fix incorrect default image_base values and re-enable shared library tests on Windows#21767
Merged
andrewrk merged 1 commit intoziglang:masterfrom Oct 22, 2024
Merged
Conversation
…library tests on Windows This was the cause of aarch64-windows shared libraries causing "bad image" errors during load-time linking. I also re-enabled the tests that were surfacing this bug.
alexrp
approved these changes
Oct 22, 2024
Member
|
Nice sleuthing, thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #16965
Closes #16959
Closes #16960
Closes #18427
As part of investigating a CI failure on aarch64-windows for #21758, I noticed that all the shared library tests were being skipped on either windows or aarch64-windows. I did some testing in an aarch64-windows VM, and noticed that the error happening here was a "Bad Image" error coming from the dll.
The way I figured this out was by removing each of the optional arguments from the linker line to see if I could get a different result. As it turned out, removing the -BASE:268435456 argument for the shared library caused the bug to go away. It turns out this value is incorrect for 64-bit targets, see: https://learn.microsoft.com/en-us/cpp/build/reference/base-base-address?view=msvc-170
Passing the correct value of 0x180000000 resolved the issue, which led me to the diff in this PR.
The regression that introduced this bug (as #18427 hints at) was this change in #18160:
Instead of sending the optional override,
self.image_base(which then contained the incorrect value for a 64-bit images) was now always being set on the linker line.This didn't seem to cause an issue on x86_64, but it seems aarch64 Windows is more strict about this, and an image created with the wrong BASE would result in this "Bad Image" error there.
This PR fixes the
image_basevalue as well as re-enables the disabled tests.