Ryan, can you do one final thing? When you run that program, be sure
to specify `+RTS -Dl` (must be linked with -debug.) This will enable
all the debug output where the linker is concerned. There will be a
few hundred lines just for initialization (based on my machine.) If my
theory is correct, you'll probably see stuff like 'Unloading object
file ...' right as the invalid read/segfault occurs.

Hi Austin,

I did this, and it produced a 97MB text file of debug output, the tail end of which was:

initLinker: idempotent return
lookupSymbol: value of stg_gc_unpt_r1 is 0x485570
`stg_gc_unpt_r1' resolves to 0x485570Reloc: P = 0x40b510f3   S = 0x485570   A = 0xfffffffffffffffc
relocations for section 3 using symtab 8
Rel entry   0 is raw( (nil) 0x800000001  (nil))   lookupSymbol: looking up base_ControlziApplicative_zdfApplicativeIO3_info
initLinker: start
initLinker: idempotent return
lookupSymbol: value of base_ControlziApplicative_zdfApplicativeIO3_info is 0x40b51058
`base_ControlziApplicative_zdfApplicativeIO3_info' resolves to 0x40b51058Reloc: P = 0x40b51100   S = 0x40b51058   A = (nil)
resolveObjs: done
lookupSymbol: looking up f
initLinker: start
initLinker: idempotent return
lookupSymbol: value of f is 0x440330c0
initLinker: start
initLinker: idempotent return
unloadObj: Test.o
Checking whether to unload Test.o
Unloading object file Test.o

And that's when it segfaulted (notusing valgrind).  If it is of any use, here is the full output, which fortunately compresses down to 4.4MB:

    http://www.cs.indiana.edu/~rrnewton/temp/linker_unload_debug_output.txt.bz2

Best,
  -Ryan

P.S. Here is the equivalent output from the same thing being run under valgrind:

initLinker: idempotent return
lookupSymbol: value of base_ControlziApplicative_zdfApplicativeIO3_info is 0x4c15058
`base_ControlziApplicative_zdfApplicativeIO3_info' resolves to 0x4c15058Reloc: P = 0x4c15100   S = 0x4c15058   A = (nil)
resolveObjs: done
lookupSymbol: looking up f
initLinker: start
initLinker: idempotent return
lookupSymbol: value of f is 0x4c0f0c0
initLinker: start
initLinker: idempotent return
unloadObj: Test.o
Checking whether to unload Test.o
Unloading object file Test.o
==9030== Invalid read of size 8
==9030==    at 0x492502: checkUnload (CheckUnload.c:286)
==9030==    by 0x476580: GarbageCollect (GC.c:666)
==9030==    by 0x46ADCD: scheduleDoGC (Schedule.c:1652)
==9030==    by 0x46B976: performGC_ (Schedule.c:2551)
==9030==    by 0x46B9AE: performMajorGC (Schedule.c:2565)
==9030==    by 0x4043E1: main (in /home/beehive/ryan_scratch/ghc-working/testsuite/tests/rts/linker_unload2)
==9030==  Address 0x95c4580 is 80 bytes inside a block of size 120 free'd
==9030==    at 0x4A063F0: free (vg_replace_malloc.c:446)
==9030==    by 0x4656D5: stgFree (RtsUtils.c:107)
==9030==    by 0x45DDF4: freeObjectCode (Linker.c:2087)
==9030==    by 0x4924CF: checkUnload (CheckUnload.c:295)
==9030==    by 0x476580: GarbageCollect (GC.c:666)
==9030==    by 0x46ADCD: scheduleDoGC (Schedule.c:1652)
==9030==    by 0x46B976: performGC_ (Schedule.c:2551)
==9030==    by 0x46B9AE: performMajorGC (Schedule.c:2565)
==9030==    by 0x4043E1: main (in /home/beehive/ryan_scratch/ghc-working/testsuite/tests/rts/linker_unload2)
==9030==