Linker-script workaround compatibility musl libc
Needs RevisionPublic

Authored by smaeul on Jan 13 2019, 8:51 PM.

Details

Summary

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.

smaeul created this revision.Jan 13 2019, 8:51 PM
bgamari accepted this revision.Jan 20 2019, 6:08 PM

Wow, I wasn't aware of this awful little bit of code. Well, given that it exists it does seem reasonable to extend it for musl. However, I can't help but wonder whether there isn't a better way to accomplish this.

This revision is now accepted and ready to land.Jan 20 2019, 6:08 PM

@smaeul, do you think you could push this to GitLab? I was going to do so myself but unfortunately Phabricator refuses to tell me your email address so I can't properly attribute the commit to you.

bgamari requested changes to this revision.Jan 20 2019, 7:23 PM
This revision now requires changes to proceed.Jan 20 2019, 7:23 PM

@smaeul, do you think you could push this to GitLab? I was going to do so myself but unfortunately Phabricator refuses to tell me your email address so I can't properly attribute the commit to you.

I've pushed it as https://gitlab.haskell.org/ghc/ghc/merge_requests/164