#2615: ghci doesn't play nice with linker scripts
---------------------------------+------------------------------------------
Reporter: AlecBerryman | Owner: igloo
Type: bug | Status: new
Priority: normal | Milestone: 6.10.2
Component: GHCi | Version: 6.10.1
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Os: Linux
Architecture: Unknown/Multiple |
---------------------------------+------------------------------------------
Changes (by igloo):
* priority: high => normal
Comment:
The problem is illustrated by this C program:
{{{
#include <stdio.h>
#include <dlfcn.h>
int main(void) {
void *p;
p = dlopen("/usr/lib/libgmp.so", RTLD_LAZY | RTLD_GLOBAL);
if (p) printf("OK\n");
else printf("%s\n", dlerror());
p = dlopen("/usr/lib/libpthread.so", RTLD_LAZY | RTLD_GLOBAL);
if (p) printf("OK\n");
else printf("%s\n", dlerror());
return 0;
}
}}}
which fails to `dlopen` `/usr/lib/pthread.so` because it's a linker
script:
{{{
$ gcc -ldl c.c -o c
$ ./c
OK
/usr/lib/libpthread.so: invalid ELF header
$ cat /usr/lib/libpthread.so
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib/libpthread.so.0 /usr/lib/libpthread_nonshared.a )
}}}
This most commonly crops up with `-lpthread` and `-lc`, and in both these
cases you can work around it by just not passing the flag.
I've done some digging, but haven't been able to find a replacement for
`dlopen` that can handle linker scripts. There are two things we could do:
* Special case `-lpthread` and `-lc`. This wouldn't solve the problem in
general, but would fix the most common instances of it.
* Make an empty library linked with `-lpthread` (or whatever other `-l`
flags we're given) and `dlopen` that library. Then the system linker takes
care of it for us. This is ugly, but if we have code to generate `.so`
libraries anyway (for making dynamic Haskell libraries) then at least it's
not too much work to implement.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2615#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs