cmd/link: pe .rdata section should not need to be IMAGE_SCN_MEM_EXECUTE #25926
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
CL 115975 split .text section into .text (code) and .rdata (read only data).
I expected .rdata not to need IMAGE_SCN_MEM_EXECUTE flag set (flag that instructs Windows to allow code execution in that section).
Unfortunately, when I run debug/pe tests, TestInternalLinkerDWARF failed with
I managed to fix test by adding IMAGE_SCN_MEM_EXECUTE to .rdata section. I did not have time to investigate why IMAGE_SCN_MEM_EXECUTE was required, so I just put TODO for later https://go-review.googlesource.com/c/go/+/115975/3/src/cmd/link/internal/ld/pe.go#1346
I had some time to debug this. TestInternalLinkerDWARF builds a.exe executable. I run a.exe in gdb. And I can see that the crash is happening in x_cgo_thread_start. All other functions do have debug information, but this function does not. The asm for x_cgo_thread_start is:
See how call into _beginthread says <runtime.etypes+24> ? It appears _beginthread function end-up in .rdata section.
It is no surprise that this code cannot execute - it needs IMAGE_SCN_MEM_EXECUTE.
How is _beginthread code
end-up in .rdata section? How can we make it go into .text section?
I am hoping that @ianlancetaylor has some ideas about this. :-)
Alex
The text was updated successfully, but these errors were encountered: