Skip to content
  • Samuel Holland's avatar
    Extend linker-script workaround to work with musl libc · 64ce6afa
    Samuel Holland authored and Marge Bot's avatar Marge Bot committed
    GHC has code to handle unsuffixed .so files that are linker scripts
    pointing to the real shared library. The detection is done by parsing
    the result of `dlerror()` after calling `dlopen()` and looking for
    certain error strings. On musl libc, the error message is "Exec format
    error", which happens to be `strerror(ENOEXEC)`:
    
    ```
    $ cat tmp.c
    #include <dlfcn.h>
    #include <stdio.h>
    
    int main(void) {
            dlopen("libz.so", RTLD_NOW | RTLD_GLOBAL);
            puts(dlerror());
            return 0;
    }
    $ gcc -o tmp tmp.c
    $ ./tmp
    Error loading shared library libz.so: Exec format error
    $
    ```
    
    This change fixes the workaround to also work on musl libc.
    
    Link: https://phabricator.haskell.org/D5474
    64ce6afa