[GHC] #9189: Linking fails on OSX when -staticlib and -threaded are enabled
GHC
ghc-devs at haskell.org
Tue Jun 10 10:22:12 UTC 2014
#9189: Linking fails on OSX when -staticlib and -threaded are enabled
-------------------------------------+-------------------------------------
Reporter: frode | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.2
Keywords: pthread staticlib | Operating System: MacOS X
threaded | Type of failure: Compile-time
Architecture: x86 | crash
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
-------------------------------------+-------------------------------------
I'm trying to build a library with ffi exported functions to be called
from ObjectiveC in an Xcode project on OSX. With just -staticlib it works,
but when I add -threaded as well I get a linker error saying that it
cannot find pthread. This happens even with a trivial program:
{{{
Test.hs:
module Test where
main :: IO ()
main = putStrLn "Hello"
}}}
{{{
$ ghc Test.hs -staticlib -threaded
[1 of 1] Compiling Test ( Test.hs, Test.o )
Linking liba.a ...
error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool:
can't locate file for: -lpthread
error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool:
file: -lpthread is not an object file (not allowed in a library)
}}}
The linker command that fails:
{{{
*** Linker:
libtool -static -o liba.a Test.o -L/usr/local/lib/ghc-7.8.2/base-4.7.0.0
-L/usr/local/lib/ghc-7.8.2/integer-gmp-0.5.1.0 -L/usr/local/lib/ghc-7.8.2
/ghc-prim-0.3.1.0 -L/usr/local/lib/ghc-7.8.2/rts-1.0
/var/folders/jc/3pqglx_x3z9dk3gnxgh56tv80000gp/T/ghc26454_0/ghc26454_3.o
-lHSbase-4.7.0.0 -lHSinteger-gmp-0.5.1.0 -lHSghc-prim-0.3.1.0 -lHSrts_thr
-lCffi -lpthread
}}}
If I make a script that removes the -lpthread argument, it links ok and
the project works with multiple threads calling my ffi-functions
simultaneously.
It was suggested by Bob on Haskell Cafe that it should not link against
libpthread on OSX since it is included in libSystem (like IOS):
https://groups.google.com/d/msg/haskell-cafe/GGEkifs_-uY/uzHeV-Z2E2YJ
https://github.com/ghc/ghc/blob/master/compiler/main/DriverPipeline.hs#L1869-L1873
OSX version 10.9.3
Verbose output:
{{{
$ ghc Test.hs -staticlib -threaded -v
Glasgow Haskell Compiler, Version 7.8.2, stage 2 booted by GHC version
7.6.3
Using binary package database:
/usr/local/lib/ghc-7.8.2/package.conf.d/package.cache
Using binary package database:
/Users/frode/.ghc/x86_64-darwin-7.8.2/package.conf.d/package.cache
hiding package Cabal-1.18.1.3 to avoid conflict with later version
Cabal-1.20.0.0
hiding package hoauth2-0.3.6.2 to avoid conflict with later version
hoauth2-0.3.7
hiding package hoauth2-0.3.6.1 to avoid conflict with later version
hoauth2-0.3.7
wired-in package ghc-prim mapped to ghc-
prim-0.3.1.0-948744e1f99cc8bcc7c7d3ba60c7c2d8
wired-in package integer-gmp mapped to integer-
gmp-0.5.1.0-dc47f6b546fc171f67a7f7d311684a99
wired-in package base mapped to
base-4.7.0.0-a333addb6892f3cc2e6baa5ec782bd04
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-
haskell-2.9.0.0-ed6ecfb467e6936688bb20f968f702e1
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags:
hiding package Cabal-1.18.1.3 to avoid conflict with later version
Cabal-1.20.0.0
hiding package hoauth2-0.3.6.2 to avoid conflict with later version
hoauth2-0.3.7
hiding package hoauth2-0.3.6.1 to avoid conflict with later version
hoauth2-0.3.7
wired-in package ghc-prim mapped to ghc-
prim-0.3.1.0-948744e1f99cc8bcc7c7d3ba60c7c2d8
wired-in package integer-gmp mapped to integer-
gmp-0.5.1.0-dc47f6b546fc171f67a7f7d311684a99
wired-in package base mapped to
base-4.7.0.0-a333addb6892f3cc2e6baa5ec782bd04
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-
haskell-2.9.0.0-ed6ecfb467e6936688bb20f968f702e1
wired-in package dph-seq not found.
wired-in package dph-par not found.
*** Chasing dependencies:
Chasing modules from: *Test.hs
Stable obj: [Test]
Stable BCO: []
Ready for upsweep
[NONREC
ModSummary {
ms_hs_date = 2014-06-10 10:02:41 UTC
ms_mod = main:Test,
ms_textual_imps = [import (implicit) Prelude]
ms_srcimps = []
}]
*** Deleting temp files:
Deleting:
compile: input file Test.hs
Created temporary directory:
/var/folders/jc/3pqglx_x3z9dk3gnxgh56tv80000gp/T/ghc26454_0
*** Checking old interface for main:Test:
[1 of 1] Skipping Test ( Test.hs, Test.o )
Upsweep completely successful.
*** Deleting temp files:
Deleting:
/var/folders/jc/3pqglx_x3z9dk3gnxgh56tv80000gp/T/ghc26454_0/ghc26454_1.s
Warning: deleting non-existent
/var/folders/jc/3pqglx_x3z9dk3gnxgh56tv80000gp/T/ghc26454_0/ghc26454_1.s
link: linkables are ...
LinkableM (2014-06-10 10:02:55 UTC) main:Test
[DotO Test.o]
Linking liba.a ...
*** C Compiler:
/usr/bin/gcc -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -c
/var/folders/jc/3pqglx_x3z9dk3gnxgh56tv80000gp/T/ghc26454_0/ghc26454_2.c
-o
/var/folders/jc/3pqglx_x3z9dk3gnxgh56tv80000gp/T/ghc26454_0/ghc26454_3.o
-I/usr/local/lib/ghc-7.8.2/include
*** Linker:
libtool -static -o liba.a Test.o -L/usr/local/lib/ghc-7.8.2/base-4.7.0.0
-L/usr/local/lib/ghc-7.8.2/integer-gmp-0.5.1.0 -L/usr/local/lib/ghc-7.8.2
/ghc-prim-0.3.1.0 -L/usr/local/lib/ghc-7.8.2/rts-1.0
/var/folders/jc/3pqglx_x3z9dk3gnxgh56tv80000gp/T/ghc26454_0/ghc26454_3.o
-lHSbase-4.7.0.0 -lHSinteger-gmp-0.5.1.0 -lHSghc-prim-0.3.1.0 -lHSrts_thr
-lCffi -lpthread
error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool:
can't locate file for: -lpthread
error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool:
file: -lpthread is not an object file (not allowed in a library)
*** Deleting temp files:
Deleting:
/var/folders/jc/3pqglx_x3z9dk3gnxgh56tv80000gp/T/ghc26454_0/ghc26454_3.o
/var/folders/jc/3pqglx_x3z9dk3gnxgh56tv80000gp/T/ghc26454_0/ghc26454_2.c
*** Deleting temp dirs:
Deleting: /var/folders/jc/3pqglx_x3z9dk3gnxgh56tv80000gp/T/ghc26454_0
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9189>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list