[GHC] #14081: 8.2.1 runghc from Windows x32 segfaults an all programs
GHC
ghc-devs at haskell.org
Sun Aug 20 14:46:25 UTC 2017
#14081: 8.2.1 runghc from Windows x32 segfaults an all programs
----------------------------------+------------------------------
Reporter: sergv | Owner: (none)
Type: bug | Status: new
Priority: highest | Milestone: 8.2.2
Component: Compiler | Version: 8.2.1
Resolution: | Keywords:
Operating System: Windows | Architecture: x86
Type of failure: Runtime crash | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
----------------------------------+------------------------------
Comment (by sergv):
I still wasn't able to use gdb to any good, but I think I found out the
problem. The tl;dr version is: `addDLLHandle` assumes that import table is
always present and it is not the case for 32-bit `ntdll.dll`.
The long version is:
I have stumbled upon some code for reading import table -
https://stackoverflow.com/questions/15960437/how-to-read-import-directory-
table-in-c#17457077. The GHC currently uses somewhat different but simpler
approach. In particular it doesn't use anything resembling `Rva2Offset`
function. I tried to use `Rva2Offset` and friends from the post but it
didn't work. I didn't manage to debug it, but while trying to I noticed
that post's code explicitly checks for the case when dll has no import
table. I added this check to ghc and it seems that was enough to get `ghc
--interactive` working. The check is:
{{{
diff --git i/rts/linker/PEi386.c w/rts/linker/PEi386.c
index 42e700805e..011b0a8314 100644
--- i/rts/linker/PEi386.c
+++ w/rts/linker/PEi386.c
@@ -240,6 +240,13 @@ static void addDLLHandle(pathchar* dll_name,
HINSTANCE instance) {
(PIMAGE_IMPORT_DESCRIPTOR)((BYTE *)instance + header->
OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
+ bool importTableMissing =
+
header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size ==
0;
+
+ if (importTableMissing) {
+ return;
+ }
+
/* Ignore these compatibility shims. */
const pathchar* ms_dll = WSTR("api-ms-win-");
const int len = wcslen(ms_dll);
}}}
@Phyx- is the fix sensible? Should we try to merge it in?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14081#comment:20>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list