[GHC] #8935: Obscure linker bug leads to crash in GHCi
GHC
ghc-devs at haskell.org
Tue May 6 16:18:03 UTC 2014
#8935: Obscure linker bug leads to crash in GHCi
-------------------------------------+------------------------------------
Reporter: simonmar | Owner: simonmar
Type: bug | Status: new
Priority: high | Milestone: 7.8.3
Component: Runtime System | Version: 7.8.1-rc2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: GHCi crash | Difficulty: Rocket Science
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Changes (by trommler):
* status: infoneeded => new
Comment:
Replying to [comment:29 simonmar]:
> My apologies for making a buggy test program :-) Thanks for eliminating
the strangeness there.
No problem! I learned a lot about dynamic linking!
> So it seems that `dlsym` always returns a bogus result for `environ`.
No, no, it does not look bad at all. The address looks strange but that is
caused by the fact that it was created by the dynamic linker. Look at
`*defl_env` and `*env` in the second program in comment:25. The addresses
match and I checked they really point to the environment array!
In the first program the static linker creates the reference for environ
because we take its address
`&environ` to print it. So there is a static symbol already there and that
confuses the dynamic linker when it searches in `libgmp` and then finds
`environ` in `libc`.
Once we have fixed this bug I will read the ELF specs again and see if
giving us a defunct symbol when we load a weak symbol again is really
allowed by the specification.
>
> Your proposed fix only works if we load libraries with `RTLD_LOCAL`
rather than `RTLD_GLOBAL`, I think. That is probably fine, but it needs
testing. This commit that introduced `internal_dlsym` explains the
rationale: be497c202b790999c3fd0ddc4a4176b8cf6acf7e
>
> I'm fine with refactoring away the `hdl` argument.
There is a branch on my github
[https://github.com/trommler/ghc/tree/rtld-8935] where I implemented that
and what I proposed above. While my AMD 64 bit and my old PowerMac G5
build ghc, I will read up on the rationale for `internal_dlsym`.
If validate succeeds and I am sufficiently confident I understand what
`internal_dlsym` needs to do. I'll post my patches.
We can remove the info needed.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8935#comment:30>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list