
#8935: Obscure linker bug leads to crash in GHCi
-------------------------------------+------------------------------------
Reporter: simonmar | Owner: simonmar
Type: bug | Status: patch
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:
-------------------------------------+------------------------------------
Comment (by dagit):
After playing with your example a bit I see what you mean about the copy
semantics. I found this article:
http://netwinder.osuosl.org/users/p/patb/public_html/elf_relocs.html
Interestingly, [http://src.gnu-darwin.org/src/libexec/rtld-
elf/amd64/reloc.c.html glibc] has these comments:
{{{
/*
* Process the special R_X86_64_COPY relocations in the main program.
These
* copy data from a shared object into a region in the main program's BSS
* segment.
*
* Returns 0 on success, -1 on failure.
*/
int
do_copy_relocations(Obj_Entry *dstobj)
}}}
And:
{{{
case R_X86_64_COPY:
/*
* These are deferred until all other relocations have
* been done. All we do here is make sure that the COPY
* relocation is not in a shared library. They are
allowed
* only in executable files.
*/
}}}
The elf interpreter delays processing of the `R_COPY`'s so that it gets
the correct behavior. I think this supports your earlier hypothesis.
At this point, I noticed that I can switch `environ` in the executable
between `R_X86_64_GLOB_DAT` and `R_X86_64_COPY` by adding `-fPIC` (you
probably already knew that). Specifically, without `-fPIC` I get copy and
with it I get glob dat.
Test program again:
{{{
#define _GNU_SOURCE
#include