
#12031: GHCi segfaults on Windows when compiling C code using extern-declared
variable
--------------------------------+----------------------------------------
Reporter: RyanGlScott | Owner: Phyx-
Type: bug | Status: new
Priority: normal | Milestone:
Component: GHCi | Version: 8.0.1
Resolution: | Keywords:
Operating System: Windows | Architecture: Unknown/Multiple
Type of failure: GHCi crash | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
--------------------------------+----------------------------------------
Changes (by Phyx-):
* owner: => Phyx-
Comment:
Thanks for the simplified example @RyanGlScott. It made it a lot easier to
find.
This seems like it has to do with MingW-w64's pseudo-relocation features.
The references to the `foo` extern value seems to go through a `.refptr`
reference.
The values to jump to are contained in their own `$rdata` section such as
{{{
Disassembly of section .rdata$.refptr.foo:
0000000000000000 <.refptr.foo>:
...
0: R_X86_64_64 foo
}}}
Which contains the address of `foo`. It seems that this is done to take
advantage of the
full 48-bit address space for x64 Windows. This because the instruction
relocations are done
in 32-bit space. e.g. using R_X86_64_PC32.
Looking at the dissassembly of `baz.c` you see that the direct lookup of
`foo` has been replaced.
{{{
Disassembly of section .text:
0000000000000000 <baz>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 83 ec 20 sub $0x20,%rsp
8: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # f