Commit fc6b23be authored by Phuong Trinh's avatar Phuong Trinh Committed by Marge Bot

Fix #16525: ObjectCode freed wrongly because of lack of info header check

`checkUnload` currently doesn't check the info header of static objects.
Thus, it may free an `ObjectCode` struct wrongly even if there's still a
live static object whose info header lies in a mapped section of that
`ObjectCode`. This fixes the issue by adding an appropriate check.
parent 5ffc266e
......@@ -404,6 +404,7 @@ void checkUnload (StgClosure *static_objects)
p = UNTAG_STATIC_LIST_PTR(p);
checkAddress(addrs, p, s_indices);
info = get_itbl(p);
checkAddress(addrs, info, s_indices);
link = *STATIC_LINK(info, p);
}
......
......@@ -1185,11 +1185,17 @@ void freeObjectCode (ObjectCode *oc)
oc->sections[i].mapped_size);
break;
case SECTION_M32:
IF_DEBUG(sanity,
memset(oc->sections[i].start,
0x00, oc->sections[i].size));
m32_free(oc->sections[i].start,
oc->sections[i].size);
break;
#endif
case SECTION_MALLOC:
IF_DEBUG(sanity,
memset(oc->sections[i].start,
0x00, oc->sections[i].size));
stgFree(oc->sections[i].start);
break;
default:
......
......@@ -24,7 +24,7 @@ Note [Compile Time Trickery]
This file implements two versions of each of the `m32_*` functions. At the top
of the file there is the real implementation (compiled in when
`RTS_LINKER_USE_MMAP` is true) and a dummy implementation that exists only to
satisfy the compiler and which hould never be called. If any of these dummy
satisfy the compiler and which should never be called. If any of these dummy
implementations are called the program will abort.
The rationale for this is to allow the calling code to be written without using
......
module A where
import B
myIntVal :: Int
myIntVal = sum [1,2,3,4]
value :: [Value]
value = [Value "a;lskdfa;lszkfsd;alkfjas" myIntVal]
v1 :: Value -> String
v1 (Value a _) = a
module B where
data Value = Value String Int
:set -fobject-code
:load A
import Control.Concurrent
_ <- forkIO $ threadDelay 1000000 >> (print (map v1 value))
:l []
System.Mem.performGC
test('T16525a',
[extra_files(['A.hs', 'B.hs', ]),
extra_run_opts('+RTS -DS -RTS'),
when(ghc_dynamic(), skip), ],
ghci_script, ['T16525a.script'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment