Ticket #781 (new bug)

Opened 7 years ago

Last modified 8 days ago

GHCi on x86_64, cannot link to static data in shared libs

Reported by: guest Owned by:
Priority: high Milestone: 7.8.1
Component: Compiler Version: 6.5
Keywords: getEnvironment Cc: pho@…, vandijk.roel@…, anton.nik@…, dterei, lewurm@…, jims@…
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: GHCi crash Difficulty: Unknown
Test Case: getEnvironment01 Blocked By: #3658
Blocking: Related Tickets:

Description

System.Posix.getEnvironment fails on Linux 2.6.16-1.2108_FC4smp with a segfault. (x86_64)

[aleator@thoth HopenCV]$ ghci
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.5.20060527, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base-1.0 ... linking ... done.
Prelude> :m +System.Posix.Env
Prelude System.Posix.Env> getEnv "USER"
Loading package unix-1.0 ... linking ... done.
Just "aleator"
Prelude System.Posix.Env> getEnvironment
Segmentation fault

Change History

  Changed 7 years ago by simonmar

  • os changed from Unknown to Linux
  • architecture changed from Unknown to x86_64 (amd64)
  • summary changed from getEnvironment segfaults (6.5.20060527 - snapshot) to GHCi on x86_64, cannot link to static data in shared libs

I've fixed part of the problem (getEnvironment was broken), but this still won't work with GHCi on x86_64 due to another problem: for annoying reasons the dynamic linker doesn't support linking to static data in shared libraries, which the 'environ' variable in C is. So I'm leaving the bug open with a revised heading.

  Changed 7 years ago by igloo

  • testcase set to getEnvironment01
  • milestone set to 6.6.1

  Changed 7 years ago by simonmar

  • milestone changed from 6.6.1 to 6.8

If we get shared libraries working, this one will be fixed.

  Changed 6 years ago by simonmar

  • milestone changed from 6.8 branch to _|_

We've committed Wolfgang's patch to Linker.c that understands the PIC relocations on x86_64. This means that it is possible to compile the Haskell code using -fPIC to workaround this problem. Shared libraries will also make this less of an issue, as it will then only be a problem for modules rather than packages that are loaded into GHCi.

  Changed 4 years ago by simonmar

  • priority changed from normal to high
  • milestone changed from _|_ to 6.12.1

  Changed 4 years ago by simonmar

  • milestone changed from 6.12.1 to 6.14.1

Let's look into this for 6.14.1.

  Changed 4 years ago by simonmar

Ok, to elaborate on this. The solution would be to compile everything with -fPIC on x86-64, ie. enable -fPIC by default. We have to measure the performance impact of doing that, which might not be a problem.

  Changed 4 years ago by simonmar

  • failure set to GHCi crash

  Changed 3 years ago by PHO

  • cc pho@… added

follow-up: ↓ 11   Changed 3 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

The session in the description now works, and getEnvironment01 passes all ways, on amd64/Linux.

in reply to: ↑ 10   Changed 3 years ago by simonmar

  • status changed from closed to new
  • resolution fixed deleted

Replying to igloo:

The session in the description now works, and getEnvironment01 passes all ways, on amd64/Linux.

This bug definitely still exists. Perhaps this particular test case doesn't trigger it any more?

follow-up: ↓ 13   Changed 3 years ago by igloo

  • owner set to simonmar

Simon, do you have a testcase for this?

in reply to: ↑ 12   Changed 3 years ago by simonmar

Replying to igloo:

Simon, do you have a testcase for this?

~/scratch/781 > cat a.c
int a = 42;
~/scratch/781 > gcc -shared a.c -o a.so
~/scratch/781 > cat b.hs
{-# LANGUAGE Haskell2010 #-}

import Foreign
import Foreign.C

foreign import ccall "&a" pa :: Ptr CInt

main = peek pa >>= print
~/scratch/781 > ghc -c b.hs
compilation IS NOT required
~/scratch/781 > ghc --interactive b.hs `pwd`/a.so
GHCi, version 6.13.20100826: 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 package ffi-1.0 ... linking ... done.
Loading object (dynamic) /home/simonmar/scratch/781/a.so ... done
final link ... done
Ok, modules loaded: Main.
Prelude Main> main
-907777
Prelude Main> 

  Changed 3 years ago by simonmar

  • blockedby 3658 added
  • milestone changed from 7.0.1 to 7.2.1

To fix this we need to use -fPIC by default on x86_64, which is also what we need for #3658. So let's plan to do this in 7.2, when we've thought through the implications of moving to dynamic linking by default.

  Changed 3 years ago by Roel van Dijk

  • cc vandijk.roel@… added

  Changed 2 years ago by lelf

  • cc anton.nik@… added

  Changed 2 years ago by dterei

  • cc dterei added

  Changed 19 months ago by simonmar

  • milestone changed from 7.4.1 to 7.6.1

punting; we're not moving to dynamic linking by default for 7.4.1.

  Changed 12 months ago by lewurm

  • cc lewurm@… added

  Changed 8 months ago by igloo

  • milestone changed from 7.6.1 to 7.6.2

  Changed 7 months ago by simonmar

  • milestone changed from 7.6.2 to 7.8.1

Moving this to the same milestone as #3658, the ticket it depends on.

One question I have: is this also an issue on Windows?

  Changed 6 months ago by igloo

Looks like it only affects Linux:

amd64/Linux:

Prelude Main> main
-907777

amd64/OSX:

Prelude Main> main
42

amd64/Windows:

Prelude Main> main
42

  Changed 5 months ago by simonmar

  • owner simonmar deleted

  Changed 8 days ago by jimstutt

  • cc jims@… added
Note: See TracTickets for help on using tickets.