-
Notifications
You must be signed in to change notification settings - Fork 18k
debug/pe: TestInternalLinkerDWARF fail in windows #64200
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
Comments
(CC @golang/windows) |
Bug introduced in CL 534555. This logic is wrong: go/src/cmd/link/internal/loadpe/seh.go Lines 93 to 98 in d6ef98b
sort.Search will return Would be good to understand how is that no relocation was found, maybe a malformed |
Change https://go.dev/cl/543076 mentions this issue: |
Submitted the simple fix at https://go-review.googlesource.com/c/go/+/543076. (No extra tests.) @qiulaidongfeng, what C compiler and version are you using? It sounds like this would be useful information to be able to reproduce the issue and perhaps figure out a test case. I also haven't seen this before. |
The test still failed gcc --version Get from here: https://winlibs.com/ |
Hmm, this error means that the We should understand why |
Confirmed with
I tested a few other versions using MSVCRT (12.2.0, 12.3.0, 13.2.0) and got the same result. Using UCRT on the same 12.1.0 version runs successfully. (Side note: these builds are listed on https://www.mingw-w64.org/downloads/, so they aren't really obscure. This is something to consider when setting up more CI to validate more C compilers and/or a list of what we're testing.) My understanding is that UCRT is newer, and MSVCRT is useful to target older versions of Windows, so swapping might not be possible in some situations. I'm planning to look into this further. Advice is of course quite welcome! |
An update on what I've found so far. It looks like the first different thing about the MSVCRT vs. UCRT build is that when building with the MSVCRT MinGW, Go includes crt2.o because this condition is met: go/src/cmd/link/internal/ld/lib.go Lines 690 to 697 in e58c9ba
This is where the failing search happens. MinGW, providing
So, one part of the puzzle: is this Another part is that some of the Go logic doesn't seem to match the docs and .NET CoreCLR: go/src/cmd/link/internal/loadpe/seh.go Lines 84 to 88 in 2e77b51
In https://learn.microsoft.com/en-us/cpp/build/exception-handling-x64?view=msvc-170, the number of codes is byte 3 of UNWIND_INFO, taking into account the bit field:
Changing it to .NET CoreCLR matches that at https://github.com/dotnet/runtime/blob/02812350ddacde36e7f05f0aabd7c43b3095bc65/src/coreclr/inc/win64unwind.h#L99-L106. I'm not able to track down a source for the Both of these affect the I also noticed this: go/src/cmd/link/internal/loadpe/seh.go Lines 17 to 19 in 2e77b51
https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-rtlvirtualunwind says these should be 1, 2, 4, because they're flags. (To be clear, the bitshift is fine, it's how this code deals with the bit field.) 4 isn't being used in these entries and the CHAININFO execution path doesn't get hit in my repro, so I don't think it's related to this issue. |
Good catch. I suppose the code works even with this bug because the relocation search doesn't look for an exact offset match. It will certainly find the wrong relocation sometimes.
There are 3 logical codes, but 4 codes in disk, as that array should contain an even number of entries. See this part of the docs:
|
@dagood It looks like I got confused counting bytes. You will have to also fix |
Thanks! Yep, it seems to work now with any MinGW version I throw at it. I think I'll put up a CL shortly. |
Change https://go.dev/cl/544415 mentions this issue: |
Unwind info in .xdata was being parsed incorrectly, causing targetOff to be incorrect and miss finding data in .xdata that it should have found. This causes a linker issue when using the MinGW MSVCRT compiler. Contains several fixes based on the exception handling docs: the offset used to get the number of unwind codes, the calculation of the target offset based on the dynamic size of the unwind data, and the UNW_FLAG_CHAININFO flag's value. Fixes golang#64200 Change-Id: I6483d921b2bf8a2512a95223bf3c8ce8bc63dc4a
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
go test debug/pe
What did you expect to see?
test pass.
What did you see instead?
The text was updated successfully, but these errors were encountered: