[commit: ghc] wip/ghc-8.8-merges: Extend linker-script workaround to work with musl libc (4d9b4dd)

git at git.haskell.org git at git.haskell.org
Thu Feb 21 15:10:06 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/ghc-8.8-merges
Link       : http://ghc.haskell.org/trac/ghc/changeset/4d9b4dda63eb6613e4cf810296b440c568d1c7fe/ghc

>---------------------------------------------------------------

commit 4d9b4dda63eb6613e4cf810296b440c568d1c7fe
Author: Samuel Holland <samuel at sholland.org>
Date:   Sun Jan 20 20:20:16 2019 -0600

    Extend linker-script workaround to work with musl libc
    
    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


>---------------------------------------------------------------

4d9b4dda63eb6613e4cf810296b440c568d1c7fe
 rts/Linker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rts/Linker.c b/rts/Linker.c
index 5b10b79..ac030af 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -483,7 +483,7 @@ initLinker_ (int retain_cafs)
 #   endif /* RTLD_DEFAULT */
 
     compileResult = regcomp(&re_invalid,
-           "(([^ \t()])+\\.so([^ \t:()])*):([ \t])*(invalid ELF header|file too short|invalid file format)",
+           "(([^ \t()])+\\.so([^ \t:()])*):([ \t])*(invalid ELF header|file too short|invalid file format|Exec format error)",
            REG_EXTENDED);
     if (compileResult != 0) {
         barf("Compiling re_invalid failed");



More information about the ghc-commits mailing list