[GHC] #9386: GHCi cannot load .so in same ./

#9386: GHCi cannot load .so in same ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: GHCi crash Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- In my directory ./ I have an empty file Foo.hs and a shared object file mylib.so. From that directory in the shell, $ ghci Foo *.so GHCi, version 7.8.2: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading object (dynamic) mylib.so ... failed. <command line>: user specified .o/.so/.DLL could not be loaded (mylib.so: cannot open shared object file: No such file or directory) Whilst trying to load: (dynamic) mylib.so Additional directories searched: (none) It's interesting that GHCi searches ./ and identifies the correct object file, but then fails to load it. I have also tried the path ./*.so for the GHCi option. However, if I move mylib.so to a directory ./Temp, $ ghci Foo Temp/*.so loads without issue. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: GHCi crash | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: GHCi crash | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Description changed by crockeea: Old description:
In my directory ./ I have an empty file Foo.hs and a shared object file mylib.so. From that directory in the shell,
$ ghci Foo *.so GHCi, version 7.8.2: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading object (dynamic) mylib.so ... failed. <command line>: user specified .o/.so/.DLL could not be loaded (mylib.so: cannot open shared object file: No such file or directory) Whilst trying to load: (dynamic) mylib.so Additional directories searched: (none)
It's interesting that GHCi searches ./ and identifies the correct object file, but then fails to load it. I have also tried the path ./*.so for the GHCi option.
However, if I move mylib.so to a directory ./Temp,
$ ghci Foo Temp/*.so
loads without issue.
New description: In my directory ./ I have an empty file Foo.hs and a shared object file mylib.so. From that directory in the shell, $ ghci Foo *.so GHCi, version 7.8.2: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading object (dynamic) mylib.so ... failed. <command line>: user specified .o/.so/.DLL could not be loaded (mylib.so: cannot open shared object file: No such file or directory) Whilst trying to load: (dynamic) mylib.so Additional directories searched: (none) It's interesting that GHCi searches ./ and identifies the correct object file, but then fails to load it. I have also tried the path ./*.so, mylib.so and ./mylib.so for the GHCi option. However, if I move mylib.so to a directory ./Temp, $ ghci Foo Temp/*.so loads without issue. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.8.2 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: GHCi crash | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thomie): * status: new => infoneeded Comment: crockeea: I am not able to reproduce your issue on Ubuntu x86_64. {{{ $ cp /usr/lib/x86_64-linux-gnu/libbsd.so -H . $ touch Foo.hs $ ghc-7.8.2 --interactive Foo *.so GHCi, version 7.8.2: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading object (dynamic) libbsd.so ... done final link ... done [1 of 1] Compiling Main ( Foo.hs, interpreted ) Ok, modules loaded: Main. }}} Which OS and architecture are you using? Could you supply the most simple source for `mylib.so` with which you encounter this issue, including build and run instructions. Thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by crockeea): * cc: hvr (added) * failure: GHCi crash => Other * status: infoneeded => new * component: Compiler => GHCi * version: 7.8.2 => 7.8.3 Comment: I'm still experiencing this issue with ghc-7.8.3-x86-64-unknown-linux and gcc-4.8.2. Consider the following C file, mul.c: {{{#!c //zipWith (*) void mul (int* a, int* b, int n) { int i; for(i = 0; i < n; i++) { a[i] = a[i]*b[i]; } } }}} At the terminal (where Foo.hs is empty): {{{
gcc -c mul.c gcc -shared -o mylib.so *.o ghci Foo *.o GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading object (dynamic) mylib.so ... failed. <command line>: user specified .o/.so/.DLL could not be loaded (mylib.so: cannot open shared object file: No such file or directory) Whilst trying to load: (dynamic) mylib.so Additional directories searched: (none) mkdir Temp cp *.so Temp/ ghci Foo Temp/*.o GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading object (static) Temp/*.o ... not found final link ... done [1 of 1] Compiling Main ( Foo.hs, interpreted ) Ok, modules loaded: Main. *Main> }}}
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by rwbarton): hvr: presumably dlopen is finding the `libbsd.so` on your library path, not the one in `.`. I can reproduce this in 7.8.3 but not in HEAD, so I guess it is fixed, though I don't know why yet. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by rwbarton): Actually it's not fixed, it just works for the inplace GHC only, because the `inplace/bin/ghc-stage2` sets `LD_LIBRARY_PATH=...:$LD_LIBRARY_PATH`, my existing `LD_LIBRARY_PATH` is empty and so GHC's `LD_LIBRARY_PATH` gets an empty component at the end, which is interpreted as the current directory... It's actually not entirely clear what the behavior of `ghci Foo libbar.so` ''should'' be; maybe it should search the system library path for `libbar.so`, like it does today? But I'm inclined to say not, since you could get that behavior with `ghci Foo -lbar` instead. The fact that it doesn't work even when you specify `./mylib.so` is clearly wrong. I guess the pathname gets normalized before being passed to `dlopen`, but I don't yet know where or why. I'm inclined to fix it with a hammer by prepending `./` to the `dlopen` argument whenever it is a relative pathname (if its argument contains a `/` then `dlopen` will treat it is as a pathname and not search the system library path). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by crockeea): * component: GHCi => Compiler Comment: For the purposes of finding and fixing the bug, here are two more tidbits: 1. This bug also affects GHC with .so files 2. This bug does ''not'' affect .o files. In that case, I can just type a list of files '''a.o b.o ...''' and GHC searches the local directory. This seems to support your suggested solution to just prepend a ./ to paths. But why is the behavior different for .o and .so files? Perhaps it's a matter of hardcoded extensions? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

presumably dlopen is finding the `libbsd.so` on your library path, not
#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by thomie): Replying to [comment:5 rwbarton]: the one in `.`. Correct. When I remove `/usr/lib/x86_64-linux-gnu/libbsd.so`, the test from comment:3 also fails. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Unknown Type of failure: Other | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by rwbarton): As a workaround, you can use an absolute path {{{ghci Foo `pwd`/*.so}}}. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: Phab:D593 -------------------------------------+------------------------------------- Changes (by thoughtpolice): * differential: => Phab:D593 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./
-------------------------------------+-------------------------------------
Reporter: crockeea | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Other | Unknown/Multiple
Blocked By: | Test Case:
Related Tickets: | Blocking:
| Differential Revisions: Phab:D593
-------------------------------------+-------------------------------------
Comment (by Reid Barton

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Other | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: Phab:D593 -------------------------------------+------------------------------------- Comment (by rwbarton): I did some experiments with `gcc ... libfoo.so`, and it looked for `libfoo.so` in the current directory only, so I guess `ghc` and `ghci` ought to do the same. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.8.3 (Linker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: Phab:D593 -------------------------------------+------------------------------------- Changes (by ezyang): * component: Compiler => Runtime System (Linker) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9386: GHCi cannot load .so in ./ -------------------------------------+------------------------------------- Reporter: crockeea | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.8.3 (Linker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D593 Wiki Page: | -------------------------------------+------------------------------------- Comment (by crockeea): Did the patch ever get merged? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9386#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC