Skip to content

Rts hooks don't work with -dynamic

Summary

Defining my own FlagDefaultsHook doesn't work when using -dynamic. It could be just a documentation bug.

https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/runtime_control.html#hooks-to-change-rts-behaviour mentions that it doesn't work for Windows DLLs, but after a7ab1616 I don't think it works at all for -dynamic.

Steps to reproduce

$ cat hooks.c 
#include <stdio.h>
#include "Rts.h"

void FlagDefaultsHook(void) {
    printf("FlagDefaultsHook\n");
}

$ cat main.hs
module Main where

main = putStrLn "Haskell main"
$ ghc -fforce-recomp -dynamic hooks.c main.hs
[1 of 1] Compiling Main             ( main.hs, main.o )
Linking main ...

$ ./main
Haskell main

Expected behavior

$ ghc -fforce-recomp -static hooks.c main.hs
[1 of 1] Compiling Main             ( main.hs, main.o )
Linking main ...

$ ./main
FlagDefaultsHook
Haskell main

Or additional documentation about the requirements for using the hooks.

Environment

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.6.4
Edited by adam
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information