HsOpenSSL segfaults on OS X - macos

I'm trying to give HsOpenSSL a whirl on Mac OS X, and it's blowing up in my face.
The latest Hackage version (HsOpenSSL-0.10.3.3) builds and imports, but doing anything with it kills my GHCi (both 7.6.3 and 7.4.2):
ghci> import OpenSSL
ghci> withOpenSSL $ do undefined
$ # Now I'm looking at a shell prompt
I put together an executable and built it with GHC, and voilà, a segfault:
$ ./test
Segmentation fault: 11
I'm using the version of OpenSSL that comes with OS X 10.8:
$ openssl version
OpenSSL 0.9.8r 8 Feb 2011
(I've also now installed the latest version of OpenSSL, v1.0.1e, and built HsOpenSSL against it. Again it builds and imports fine, but segfaults on any call out to OpenSSL.)
This is likely a problem with OpenSSL, or with some idiosyncrasy of using OS X rather than Linux, but my installation does work fine with Python's OpenSSL library. ...
Can anyone replicate this, or give me any debugging tips?

I'm afraid I have another negative report - it works here for me, on OS X. Hypothetically, I might be using a version that I might not be allowed to mention, though, so that could be the difference...
module Main (main) where
import OpenSSL
main :: IO ()
main = withOpenSSL $ do
putStrLn "Hm."
Then I can run it with:
$ ghc Crash.hs
... [it compiles] ...
$ ./Crash
Hm.
And it succeeds. I'm using GHC 7.6.3, HsOpenSSL 0.10.3.3, and OpenSSL 0.9.8y, this last dated 5 Feb 2013.

Related

On Windows, packages installed with cabal seem to be unavailable in ghc/ghci

I'm running the latest version of Haskell Platform 8.6.3 on a fairly standard Windows 10 x64 system.
Now I am at my wits end getting packages installed from Hackage to work reliably. Attributing my issues to local configuration problems, I've taken all steps short of nuking my Windows installation. I have uninstalled and reinstalled Hackage, rebooted, scoured every last configuration file I could in any hidden directory or otherwise, deleted every registry key apparently related to Haskell, most of them multiple times, all to no avail:
Packages installed with cabal just don't appear to be available under ghci, WinGHCI, either to be loaded interactively with (:m) under ghci or when compiling using ghc under WinGHCI, no matter what I do.
Below are some symptoms. Any suggestions?
#cabal new-update
Downloading the latest package list from hackage.haskell.org
To revert to previous state run:
cabal new-update 'hackage.haskell.org,2019-04-02T19:24:19Z'
#cabal new-install --lib vector
Resolving dependencies...
Up to date
#ghci
Prelude> :m Data.Vector
<no location info>: error:
Could not find module ‘Data.Vector’
Perhaps you meant Data.Functor (from base-4.12.0.0)
#ghc -O -optc-O3 -funfolding-use-threshold=16 -fexcess-precision -Wall -Wno-type-defaults -Wno-unused-imports -Wno-unused-top-binds -rtsopts "P663.hs"
[1 of 1] Compiling Main ( P663.hs, P663.o )
P663.hs:54:1: error:
Could not find module ‘Data.Vector.Unboxed’
Use -v to see a list of the files searched for.
|
54 | import Data.Vector.Unboxed (Vector, (!)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#ghc-pkg list
C:\Program Files\Haskell Platform\8.6.3\lib\package.conf.d
Cabal-2.4.0.1
Win32-2.6.1.0
array-0.5.3.0
base-4.12.0.0
binary-0.8.6.0
bytestring-0.10.8.2
containers-0.6.0.1
deepseq-1.4.4.0
directory-1.3.3.0
filepath-1.4.2.1
(ghc-8.6.3)
ghc-boot-8.6.3
ghc-boot-th-8.6.3
ghc-compact-0.1.0.0
ghc-heap-8.6.3
ghc-prim-0.5.3
ghci-8.6.3
haskeline-0.7.4.3
hpc-0.6.0.3
hscolour-1.24.4
integer-gmp-1.0.2.0
libiserv-8.6.3
mtl-2.2.2
parsec-3.1.13.0
pretty-1.1.3.6
process-1.6.3.0
rts-1.0
stm-2.5.0.0
template-haskell-2.14.0.0
text-1.2.3.1
time-1.8.0.2
transformers-0.5.5.0
xhtml-3000.2.2.1
#ghc-pkg list --user-package-db=C:\Users\Carl\AppData\Roaming\cabal\store\ghc-8.6.3\package.db
C:\Program Files\Haskell Platform\8.6.3\lib\package.conf.d
Cabal-2.4.0.1
Win32-2.6.1.0
array-0.5.3.0
base-4.12.0.0
binary-0.8.6.0
bytestring-0.10.8.2
containers-0.6.0.1
deepseq-1.4.4.0
directory-1.3.3.0
filepath-1.4.2.1
(ghc-8.6.3)
ghc-boot-8.6.3
ghc-boot-th-8.6.3
ghc-compact-0.1.0.0
ghc-heap-8.6.3
ghc-prim-0.5.3
ghci-8.6.3
haskeline-0.7.4.3
hpc-0.6.0.3
hscolour-1.24.4
integer-gmp-1.0.2.0
libiserv-8.6.3
mtl-2.2.2
parsec-3.1.13.0
pretty-1.1.3.6
process-1.6.3.0
rts-1.0
stm-2.5.0.0
template-haskell-2.14.0.0
text-1.2.3.1
time-1.8.0.2
transformers-0.5.5.0
xhtml-3000.2.2.1
C:\Users\Carl\AppData\Roaming\cabal\store\ghc-8.6.3\package.db
primitive-0.6.4.0
vector-0.12.0.2
#set GHC_PACKAGE_PATH=C:\Users\Carl\AppData\Roaming\cabal\store\ghc-8.6.3\package.db;
#ghc-pkg list
C:\Program Files\Haskell Platform\8.6.3\lib\package.conf.d
Cabal-2.4.0.1
Win32-2.6.1.0
array-0.5.3.0
base-4.12.0.0
binary-0.8.6.0
bytestring-0.10.8.2
containers-0.6.0.1
deepseq-1.4.4.0
directory-1.3.3.0
filepath-1.4.2.1
(ghc-8.6.3)
ghc-boot-8.6.3
ghc-boot-th-8.6.3
ghc-compact-0.1.0.0
ghc-heap-8.6.3
ghc-prim-0.5.3
ghci-8.6.3
haskeline-0.7.4.3
hpc-0.6.0.3
hscolour-1.24.4
integer-gmp-1.0.2.0
libiserv-8.6.3
mtl-2.2.2
parsec-3.1.13.0
pretty-1.1.3.6
process-1.6.3.0
rts-1.0
stm-2.5.0.0
template-haskell-2.14.0.0
text-1.2.3.1
time-1.8.0.2
transformers-0.5.5.0
xhtml-3000.2.2.1
C:\Users\Carl\AppData\Roaming\ghc\x86_64-mingw32-8.6.3\package.conf.d
(no packages)
C:\Users\Carl\AppData\Roaming\cabal\store\ghc-8.6.3\package.db
primitive-0.6.4.0
vector-0.12.0.2
# ghci
GHCi, version 8.6.3: http://www.haskell.org/ghc/ :? for help
Prelude> :m Data.Vector
Prelude Data.Vector> toList $ empty
Access violation in generated code when reading 0xffffffffffffffff
Attempting to reconstruct a stack trace...
Frame Code address
* 0x7e5dd90 0x3d7d618 C:\Program Files\Haskell Platform\8.6.3\bin\ghc.exe+0x397d618
So it looks like you solved your problem by setting GHC_PACKAGE_PATH, right? You might wish to file a bug about that.
The second issue, the runtime "Access violation in generated code when reading" error seems to be documented here:
https://github.com/commercialhaskell/stack/issues/3765
https://gitlab.haskell.org/ghc/ghc/issues/13112
Supposedly passing -fexternal-interpreter to ghci is a workaround. You might want to manually edit the ghc/ghci shim scripts to ensure the flag is always passed until the bug can be fixed.
Thanks for all the responses. I've experimented both with running ghc on some version of UN*X under VirtualBox and uninstalling Haskell Platform and going purely with stack under Windows 10 x64.
Both seem to avoid the many issues I listed above, but stack under Windows seems a little more light-weight and integrates better with my preferred editors (Sublime Text and Visual Studio Code), so that is what I'm going with for now.
In the meantime, with all due gratitude for all the great, free work done by the Haskell Platform guys and the author of WinGHCI, I cannot urge anybody reading this strongly enough to stay away from it, in particular version 8.6.3 under Windows, at least until things are much improved.

stack is not working after upgrading platform to 8.0.2 from 8.0.1

After upgrading haskell platform package, stack command does not work.
$ stack path
No compiler found, expected minor version match with ghc-8.0.1 (x86_64) (based on resolver setting in /home/eii/exercism/haskell/linked-list/stack.yaml).
To install the correct GHC into /home/eii/.stack/programs/x86_64-linux/, try running "stack setup" or use the "--install-ghc" flag.
$
I tried stack setup but it is trying to download an old GHC (ghc-8.0.1). I just installed Haskell platform 8.0.2 (haskell-platform-8.0.2-unknown-posix--full-x86_64.tar.gz). I am using a 64 bit Linux.
$ stack setup
Preparing to install GHC to an isolated location.
This will not interfere with any system-level installation.
ghc-8.0.1: 15.69 MiB / 108.01 MiB ( 14.52%) downloaded...^Cuser interrupt
$
I can compile with ghc-8.0.2 and ghci is working fine.. but I can't use stack nor install new packages.
$ stack update
Downloading package index from https://s3.amazonaws.com/hackage.fpcomplete.com/00-index.tar.gz
Updating package index Hackage (mirrored at https://s3.amazonaws.com/hackage.fpcomplete.com/00-index.tar.gz) ...
$ stack upgrade
Current Stack version: 1.3.2, available download version: 1.3.2
Skipping binary upgrade, your version is already more recent
$ which stack
/usr/local/bin/stack
$ ls -la /usr/local/bin/stack
lrwxrwxrwx. 1 root root 45 Feb 1 18:39 /usr/local/bin/stack -> /usr/local/haskell/ghc-8.0.2-x86_64/bin/stack
$ which ghc
/usr/local/bin/ghc
$ ls -la /usr/local/bin/ghc
lrwxrwxrwx. 1 root root 43 Feb 1 18:39 /usr/local/bin/ghc -> /usr/local/haskell/ghc-8.0.2-x86_64/bin/ghc
$
Please help.
I encountered this the other day on Arch Linux 4.17.4. The error was:
No setup information found for ghc-8.4.3 on your platform.
This probably means a GHC bindist has not yet been added for OS key 'linux64-ncurses6', 'linux64-tinfo6'.
Supported versions: ghc-7.8.4, ghc-7.10.2, ghc-7.10.3, ghc-8.0.1, ghc-8.0.2, ghc-8.2.1, ghc-8.2.2, ghc-8.4.1, ghc-8.4.2
As a workaround, I edited stack.yml to change
lts-12.0
to
lts-11.15

Lazarus using Indy + OpenSSL on OS X results in EIdOSSLCouldNotLoadSSLLibrary

I am currently using:
OS X Yosemite 10.10.5
newest Indy (10.6.2.0, download 2016 March 13 - Indy10_5346.zip)
Lazarus 1.4.4
newest openssl
OpenSSL is more specificly:
openssl-1.0.2g accordingly to home brew cmd line interface
placed in /usr/local/Cellar/openssl/1.0.2/lib/
lib files in above directory are: libcrypto.10.dylib,
libcrypto.1.0.0.dylib, libcrypto.dylib, libcrypto.a,
libssl.1.0.0.dylib, libssl.dylib, libssl.a
...
I am passing above pah to Indy using idOpenSSLSetLibPath() befoe using Indy.
but I am getting getting error: EIdOSSLCouldNotLoadSSLLibrary at:
TIdSSLIOHandlerSocketOpenSSL.Init() -> TIdSSLContext.Create()
...
LoadOpenSSLLibrary() -> IdSSLOpenSSLHeaders.Load()
...
Load()
...
hIDCrypto := LoadSSLCryptoLibrary() -> Result := HModule(HackLoad(...))
...
Result := LoadLibrary(HackLoadFileName(ALibName,ALibVersions[I])); // always zero :(
Comments
"GIdOpenSSLPath + SSLCLIB_DLL_name are correct (file extension set correctly by Indy when using "HackLoadFileName" in "LoadLibrary" call)
Indy tries to iterate/load over following names: libcrypto, libcrypto.1.0.0, libcrypto.10, libcrypto.1.0.1, libcrypto.1.0.2
...
Side question #1:
why does homebrew ship openssl 1.0.2g in a file called
libcrypto.1.0.0.dylib - is it to maximize compability?
...
Thoughts on possible cause #1:
Could all this be an issue of Lazarus compiles 32bit for OS X? And OpenSSL is 64bit?
Install openssl like this in command line: brew install openssl --universal
This ensure the library works both for 32 and 64 bit apps.
You may need to uninstall first using: brew uninstall openssl

Webkit not found on OSX

I'm trying to compile mu that uses the headers webkit/webkitwebview.h and webkit/webkitwebresource.h. The OSX version of webkit framework located in /System/Library/Frameworks doesn't seem to have it, the headers are different and use NS data types and stuff.
So I downloaded webkit-gtk with MacPorts (since it's not available through Homebrew) and pointed $PKG_CONFIG_PATH to webkit-1.0.pc. I verified and this version has the needed headers.
But the problem is, I still get an error, the configure file doesn't seem to be able to find it.
checking for WEBKIT... no
I don't even know, actually, if webkit-1.0.pc is the package config it is looking for.
I had two other compilation problems prior to this, with glib.h and gtk.h but managed to go through. This is the last issue I need to resolve to have a fully functional email client in Emacs.
Help!
this worked for me [1]:
add this to ~/.profile (or wherever you take care of this stuff):
# ~/.profile stuff
export PKG_CONFIG_PATH="/opt/local/lib/pkgconfig/:$PKG_CONFIG_PATH"
then source:
$ source ~/.profile
then (assuming you're in the mu dir) voila [2]:
$ ./configure
[1] i have gtk installed via homebrew, installed webkit-gtk3 via macports, and cloned mu from the github repo. running os x 10.9.5
[2] here's the $ ./configure output:
mu configuration is complete.
------------------------------------------------
mu version : 0.9.10
Xapian version : 1.2.19
GLib version : 2.42.1
GMime version : 2.6.20
GTK+ version : 3.14.5
Webkit version : 2.4.7
Emacs version : GNU Emacs 24.4.51.1
Have wordexp : yes
Build mu4e emacs frontend : yes
Build 'mug' toy-ui (gtk+/webkit) : yes
McCabe's Cyclomatic Complexity tool : no
Have direntry->d_ino : yes
Have direntry->d_type : yes
------------------------------------------------

Installing Haskell packages on Mac

I can't seem to get a few Haskell packages to install on my Mac (10.6.8). I first tried Happstack and it failed and then I tried Snap.
Sometimes when I run ghci I get a segmentation fault.
Other times it works and goes like this:
GHCi, version 7.4.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.
Prelude>
When trying to get Snap:
....
....
....
Loading package vector-0.10.0.1 ... linking ... done.
Loading package zlib-0.5.4.0 ... linking ... done.
Loading package zlib-bindings-0.1.1.3 ... linking ... done.
Loading package zlib-enum-0.2.3 ... linking ... done.
Loading package snap-core-0.9.3.1 ... linking ... done.
Loading package snap-server-0.9.3.3 ... linking ... done.
Loading package directory-tree-0.11.0 ... linking ... done.
cabal: Error: some packages failed to install:
snap-0.11.2 failed during the building phase. The exception was:
ExitFailure 11
I have seen this problem a few times but nothing really solved it for me. Any ideas?
Updated May 22, 2021
Have you tried using homebrew? It handles the dependencies for you.
Using homebrew, you can use the brew command to install ghc and cabal-install.
$ brew install ghc cabal-install
==> Downloading https://ghcr.io/v2/homebrew/core/ghc/manifests/8.10.4
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ghc/blobs/sha256:965f94c14b56e3db7b239860e0a1d577be0b27caf8adb6212710a7430ce723d3
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:965f94c14b56e3db7b239860e0a1d577be0b27caf8adb6212710a7430ce723d3?se=2021-05-23T05%3A15%3A00Z&sig=fkH7sUY44VCLV8hI%2BtZT%2B
######################################################################## 100.0%
==> Pouring ghc--8.10.4.big_sur.bottle.tar.gz
==> /usr/local/Cellar/ghc/8.10.4/bin/ghc-pkg recache
🍺 /usr/local/Cellar/ghc/8.10.4: 6,907 files, 1.5GB
==> Downloading https://ghcr.io/v2/homebrew/core/cabal-install/manifests/3.4.0.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/cabal-install/blobs/sha256:2c0c5cc90d4739515721557f8e9c02783b3b5f106033c5c09241657b4418b21f
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:2c0c5cc90d4739515721557f8e9c02783b3b5f106033c5c09241657b4418b21f?se=2021-05-23T05%3A15%3A00Z&sig=O7ylxHgq42YVADlzTacdRfY7W
######################################################################## 100.0%
==> Pouring cabal-install--3.4.0.0.big_sur.bottle.tar.gz
🍺 /usr/local/Cellar/cabal-install/3.4.0.0: 7 files, 39.6MB
Once installed, you should be able to run:
$ ghc
ghc: no input files
Usage: For basic information, try the `--help' option.
As well as the Haskell interpreter, ghci:
$ ghci
GHCi, version 8.10.4: https://www.haskell.org/ghc/ :? for help
Prelude>
Hope this helps!
brew install haskell-platform is no longer supported. You may want to
Error: No available formula for haskell-platform
We no longer package haskell-platform. Consider installing ghc and cabal-install instead:
brew install ghc cabal-install
Since haskell-platform on homebrew for Mac is deprecated, you can use brew install ghc cabal-install instead. I did it on Yosemite and it took about one minute…
> $ brew install ghc cabal-install
==> Downloading https://homebrew.bintray.com/bottles/ghc-7.10.1_1.yosemite.bottl
######################################################################## 100.0%
==> Pouring ghc-7.10.1_1.yosemite.bottle.tar.gz
🍺 /usr/local/Cellar/ghc/7.10.1_1: 5423 files, 821M
==> Downloading https://homebrew.bintray.com/bottles/cabal-install-1.22.2.0.yose
######################################################################## 100.0%
==> Pouring cabal-install-1.22.2.0.yosemite.bottle.1.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/cabal-install/1.22.2.0: 6 files, 19M
This is an old question but given it comes quiet high on Google search. This is how I got here.
$ brew update
$ brew install haskell-stack
$ stack --version
$ stack --help # "man stack" gives something completely different
$ stack setup # Install GHC
$ stack ghci
Source: http://seanhess.github.io/2015/08/04/practical-haskell-getting-started.html
Why stack and not cabal?
Edit:
I found annoying to have to write "stack ghci" each time I wanted to use "ghci". A solution to this was to simply add these lines to the ~/.bash_aliases file:
alias sghc='stack ghc'
alias sghci='stack ghci'
alias srunhaskell='stack runhaskell'
Then source the file to apply:
$ source ~/.bash_aliases
Then I can run ghci and / or haskell running these commands, and it will use the stack version:
$ sghc [filename]
$ sghci
$ srunhaskell
Update: February 2016: Whilst other answers were helpful, I didn't find a complete, up-to-date answer.
The install is easy:
$ brew install ghc cabal-install
An extra step I needed to perform post-install was:
$ cabal update
followed by:
$ cabal install ghc-mod
See here for details.
Alternatively, instead of using homebrew for the install, visit Haskell Platform for the installer disk image - note that Haskell Platform is only compatible with OS X 10.6 and later.
Although, as a general rule I always use homebrew to manage my dependencies, when it comes to Haskell my recommendation (unless you really know what you are doing) is to just install this binary. This avoids any surprises further down the road. There is excellent documentation post install locally at: file:///Library/Haskell/doc/start.html
The popular answer to this question (using brew to install haskell-platform) is no longer supported.
Unfortunately, GHC 7.4 isn't supported on OS X 10.6; the download page only has an installer for 10.7, and as you can see, they mean it. I know your problem from bitter experience—I was in exactly your boat for a good long while, and I never found a solution other than upgrading Mac OS X (or, presumably, downgrading GHC, but I didn't really want to do that). A colleague of mine did manage to get 7.4.1 running on OS X 10.5, but it took nontrivial effort on her part (she had to use a different version of GMP, namely 5.0.5, and edit GHC's configure script), and I never tried to replicate it myself.
In the end, you have four options, in roughly decreasing order of simplicity:
Use an older Haskell Platform. This means downgrading to GHC 7.0.x (not GHC 7.2.x—that was never in the Platform); there's not a good record of which GHC versions were in which package versions, though. Wikipedia implies that 2011.2 was the first version with GHC 7.0.x and that 2012.2 was the first version with GHC 7.4.x, so I'd try 2011.4.0.0 first.
Install GHC 7.2 (which is supported on OS X) on its own, and forgo the Haskell Platform. This can cause headaches, but is possible. Don't forget to install Cabal, cabal-install, all the packages that come with the platform, etc.
Upgrade to OS X 10.7 or 10.8, if you feel like a more global (and pricier) change.
Try to replicate what my colleague did. (Best of luck, but it's definitely possible.)
Late 2017 answer. I'm running macOS Sierra -- 10.12.6 (16G29). This worked successfully with an install time on my MacBook Air of under five minutes:
brew cask install haskell-platform
Then ghc --version reported:
The Glorious Glasgow Haskell Compilation System, version 8.2.1

Resources