[GHC] #11154: Problems using GHC-API on MacOS X

GHC ghc-devs at haskell.org
Wed Dec 2 14:16:15 UTC 2015


#11154: Problems using GHC-API on MacOS X
-------------------------------------+-------------------------------------
           Reporter:  svenk          |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  7.10.2
           Keywords:                 |  Operating System:  MacOS X
       Architecture:  x86_64         |   Type of failure:  Compile-time
  (amd64)                            |  crash
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 I followed the instructions on the Haskell wiki "GHC/As a library" to
 compile a Haskell file:

 '''Main.hs'''
 {{{#!hs
 import GHC
 import GHC.Paths ( libdir )
 import DynFlags

 main =
     defaultErrorHandler defaultFatalMessager defaultFlushOut $ do
       runGhc (Just libdir) $ do
         dflags <- getSessionDynFlags
         setSessionDynFlags dflags
         target <- guessTarget "test.hs" Nothing
         setTargets [target]
         load LoadAllTargets
 }}}

 '''test.hs'''
 {{{#!hs
 main = putStrLn "hello"
 }}}

 I compile with ghc -package ghc -package ghc-paths --make Main.hs. When I
 execute ./Main, I get the following linking error:

 {{{
 ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic)
 not allowed in code signed PIE, but used in _szZ_info from test.o. To fix
 this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
 final section layout:
     __TEXT/__text addr=0x100000D40, size=0x00000206,
 fileOffset=0x00000D40, type=1
     __TEXT/__stubs addr=0x100000F46, size=0x0000001E,
 fileOffset=0x00000F46, type=28
     __TEXT/__stub_helper addr=0x100000F64, size=0x00000042,
 fileOffset=0x00000F64, type=32
     __TEXT/__const addr=0x100000FA8, size=0x0000000C,
 fileOffset=0x00000FA8, type=0
     __TEXT/__eh_frame addr=0x100000FB8, size=0x00000040,
 fileOffset=0x00000FB8, type=19
     __DATA/__program_vars addr=0x100001000, size=0x00000028,
 fileOffset=0x00001000, type=30
     __DATA/__got addr=0x100001028, size=0x00000010, fileOffset=0x00001028,
 type=29
     __DATA/__nl_symbol_ptr addr=0x100001038, size=0x00000010,
 fileOffset=0x00001038, type=29
     __DATA/__la_symbol_ptr addr=0x100001048, size=0x00000028,
 fileOffset=0x00001048, type=27
     __DATA/__const addr=0x100001070, size=0x00000028,
 fileOffset=0x00001070, type=0
     __DATA/__data addr=0x100001098, size=0x00000060,
 fileOffset=0x00001098, type=0
     __DATA/__common addr=0x1000010F8, size=0x00000020,
 fileOffset=0x00000000, type=25
 ld: 32-bit RIP relative reference out of range (-4294970840 max is
 +/-4GB): from _szZ_info (0x100000D98) to
 _ghczmprim_GHCziCString_unpackCStringzh_closure at 0x0004A460 (0x00000000) in
 '_szZ_info' from test.o for architecture x86_64
 clang-3.6: error: linker command failed with exit code 1 (use -v to see
 invocation)
 }}}

 I'm running the Nix package manager on MacOS X. Here are the compiler and
 linker commands for the GHC-API case.

 {{{
 *** Assembler:
 /nix/store/2bf6xr0v5mxlfx0lawgk6lcnw5dibk1a-clang-wrapper-3.6.2/bin/cc
 -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -I. -fno-common -U__PIC__
 -D__PIC__ -Qunused-arguments -x assembler -c
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94627_0/ghc_2.s -o
 test.o
 Upsweep completely successful.
 *** Deleting temp files:
 Deleting:
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94627_0/ghc_3.c
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94627_0/ghc_2.s
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94627_0/ghc_1.s
 Warning: deleting non-existent
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94627_0/ghc_3.c
 Warning: deleting non-existent
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94627_0/ghc_1.s
 link: linkables are ...
 LinkableM (2015-12-02 09:23:41 UTC) Main
    [DotO test.o]
 Linking test ...
 *** C Compiler:
 /nix/store/2bf6xr0v5mxlfx0lawgk6lcnw5dibk1a-clang-wrapper-3.6.2/bin/cc
 -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -c
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94627_0/ghc_4.c -o
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94627_0/ghc_5.o
 -I/nix/store/65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/include -fno-common -U__PIC__ -D__PIC__
 *** Linker:
 /nix/store/2bf6xr0v5mxlfx0lawgk6lcnw5dibk1a-clang-wrapper-3.6.2/bin/cc
 -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -m64 -o test
 -Wl,-no_compact_unwind test.o -L/nix/store
 /65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/base_GDytRqRVSUX7zckgKqJjgw -Wl,-rpath
 -Wl,/nix/store/65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/base_GDytRqRVSUX7zckgKqJjgw -L/nix/store
 /vm4zm9mh0ias79f7bqknls1xfga0lp5r-libiconv-41/lib -Wl,-rpath
 -Wl,/nix/store/vm4zm9mh0ias79f7bqknls1xfga0lp5r-libiconv-41/lib
 -L/nix/store/65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/integ_2aU3IZNMF9a7mQ0OzsZ0dS -Wl,-rpath
 -Wl,/nix/store/65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/integ_2aU3IZNMF9a7mQ0OzsZ0dS -L/nix/store
 /aw51dk2wbmnvm9hxg75gmwmcl2xral6q-gmp-5.1.3/lib -Wl,-rpath -Wl,/nix/store
 /aw51dk2wbmnvm9hxg75gmwmcl2xral6q-gmp-5.1.3/lib -L/nix/store
 /65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/ghcpr_8TmvWUcS1U1IKHT0levwg3 -Wl,-rpath
 -Wl,/nix/store/65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/ghcpr_8TmvWUcS1U1IKHT0levwg3 -L/nix/store
 /65vl06cjwmd2y985fl372r9nfchy9m6d-ghc-7.10.2/lib/ghc-7.10.2/rts -Wl,-rpath
 -Wl,/nix/store/65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/rts
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94627_0/ghc_5.o
 -Wl,-u,_ghczmprim_GHCziTypes_Izh_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Czh_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Fzh_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Dzh_static_info
 -Wl,-u,_base_GHCziPtr_Ptr_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Wzh_static_info
 -Wl,-u,_base_GHCziInt_I8zh_static_info
 -Wl,-u,_base_GHCziInt_I16zh_static_info
 -Wl,-u,_base_GHCziInt_I32zh_static_info
 -Wl,-u,_base_GHCziInt_I64zh_static_info
 -Wl,-u,_base_GHCziWord_W8zh_static_info
 -Wl,-u,_base_GHCziWord_W16zh_static_info
 -Wl,-u,_base_GHCziWord_W32zh_static_info
 -Wl,-u,_base_GHCziWord_W64zh_static_info
 -Wl,-u,_base_GHCziStable_StablePtr_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Izh_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_Czh_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_Fzh_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_Dzh_con_info
 -Wl,-u,_base_GHCziPtr_Ptr_con_info -Wl,-u,_base_GHCziPtr_FunPtr_con_info
 -Wl,-u,_base_GHCziStable_StablePtr_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_False_closure
 -Wl,-u,_ghczmprim_GHCziTypes_True_closure
 -Wl,-u,_base_GHCziPack_unpackCString_closure
 -Wl,-u,_base_GHCziIOziException_stackOverflow_closure
 -Wl,-u,_base_GHCziIOziException_heapOverflow_closure
 -Wl,-u,_base_ControlziExceptionziBase_nonTermination_closure
 -Wl,-u,_base_GHCziIOziException_blockedIndefinitelyOnMVar_closure
 -Wl,-u,_base_GHCziIOziException_blockedIndefinitelyOnSTM_closure
 -Wl,-u,_base_GHCziIOziException_allocationLimitExceeded_closure
 -Wl,-u,_base_ControlziExceptionziBase_nestedAtomically_closure
 -Wl,-u,_base_GHCziEventziThread_blockedOnBadFD_closure
 -Wl,-u,_base_GHCziWeak_runFinalizzerBatch_closure
 -Wl,-u,_base_GHCziTopHandler_flushStdHandles_closure
 -Wl,-u,_base_GHCziTopHandler_runIO_closure
 -Wl,-u,_base_GHCziTopHandler_runNonIO_closure
 -Wl,-u,_base_GHCziConcziIO_ensureIOManagerIsRunning_closure
 -Wl,-u,_base_GHCziConcziIO_ioManagerCapabilitiesChanged_closure
 -Wl,-u,_base_GHCziConcziSync_runSparks_closure
 -Wl,-u,_base_GHCziConcziSignal_runHandlersPtr_closure
 -Wl,-search_paths_first -lHSbase-4.8.1.0-GDytRqRVSUX7zckgKqJjgw-ghc7.10.2
 -lHSinteger-gmp-1.0.0.0-2aU3IZNMF9a7mQ0OzsZ0dS-ghc7.10.2 -lHSghc-
 prim-0.4.0.0-8TmvWUcS1U1IKHT0levwg3-ghc7.10.2 -lHSrts-ghc7.10.2 -lffi
 -liconv -lgmp -lm -ldl
 }}}

 And here is the compilation command for vanilla GHC:

 {{{
 *** Assembler:
 /nix/store/2bf6xr0v5mxlfx0lawgk6lcnw5dibk1a-clang-wrapper-3.6.2/bin/cc
 -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -I. -fno-common -U__PIC__
 -D__PIC__ -Qunused-arguments -x assembler -c
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94206_0/ghc_2.s -o
 test.o
 Upsweep completely successful.
 *** Deleting temp files:
 Deleting:
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94206_0/ghc_3.c
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94206_0/ghc_2.s
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94206_0/ghc_1.s
 Warning: deleting non-existent
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94206_0/ghc_3.c
 Warning: deleting non-existent
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94206_0/ghc_1.s
 link: linkables are ...
 LinkableM (2015-12-02 09:21:48 UTC) Main
    [DotO test.o]
 Linking test ...
 *** C Compiler:
 /nix/store/2bf6xr0v5mxlfx0lawgk6lcnw5dibk1a-clang-wrapper-3.6.2/bin/cc
 -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -c
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94206_0/ghc_4.c -o
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94206_0/ghc_5.o
 -I/nix/store/65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/include -fno-common -U__PIC__ -D__PIC__
 *** Linker:
 /nix/store/2bf6xr0v5mxlfx0lawgk6lcnw5dibk1a-clang-wrapper-3.6.2/bin/cc
 -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -m64 -o test
 -Wl,-no_compact_unwind test.o -L/nix/store
 /65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/base_GDytRqRVSUX7zckgKqJjgw -L/nix/store
 /vm4zm9mh0ias79f7bqknls1xfga0lp5r-libiconv-41/lib -L/nix/store
 /65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/integ_2aU3IZNMF9a7mQ0OzsZ0dS -L/nix/store
 /aw51dk2wbmnvm9hxg75gmwmcl2xral6q-gmp-5.1.3/lib -L/nix/store
 /65vl06cjwmd2y985fl372r9nfchy9m6d-
 ghc-7.10.2/lib/ghc-7.10.2/ghcpr_8TmvWUcS1U1IKHT0levwg3 -L/nix/store
 /65vl06cjwmd2y985fl372r9nfchy9m6d-ghc-7.10.2/lib/ghc-7.10.2/rts
 /var/folders/qs/963nksq94bxdb3tv41w194fh0000gn/T/ghc94206_0/ghc_5.o
 -Wl,-u,_ghczmprim_GHCziTypes_Izh_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Czh_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Fzh_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Dzh_static_info
 -Wl,-u,_base_GHCziPtr_Ptr_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Wzh_static_info
 -Wl,-u,_base_GHCziInt_I8zh_static_info
 -Wl,-u,_base_GHCziInt_I16zh_static_info
 -Wl,-u,_base_GHCziInt_I32zh_static_info
 -Wl,-u,_base_GHCziInt_I64zh_static_info
 -Wl,-u,_base_GHCziWord_W8zh_static_info
 -Wl,-u,_base_GHCziWord_W16zh_static_info
 -Wl,-u,_base_GHCziWord_W32zh_static_info
 -Wl,-u,_base_GHCziWord_W64zh_static_info
 -Wl,-u,_base_GHCziStable_StablePtr_static_info
 -Wl,-u,_ghczmprim_GHCziTypes_Izh_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_Czh_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_Fzh_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_Dzh_con_info
 -Wl,-u,_base_GHCziPtr_Ptr_con_info -Wl,-u,_base_GHCziPtr_FunPtr_con_info
 -Wl,-u,_base_GHCziStable_StablePtr_con_info
 -Wl,-u,_ghczmprim_GHCziTypes_False_closure
 -Wl,-u,_ghczmprim_GHCziTypes_True_closure
 -Wl,-u,_base_GHCziPack_unpackCString_closure
 -Wl,-u,_base_GHCziIOziException_stackOverflow_closure
 -Wl,-u,_base_GHCziIOziException_heapOverflow_closure
 -Wl,-u,_base_ControlziExceptionziBase_nonTermination_closure
 -Wl,-u,_base_GHCziIOziException_blockedIndefinitelyOnMVar_closure
 -Wl,-u,_base_GHCziIOziException_blockedIndefinitelyOnSTM_closure
 -Wl,-u,_base_GHCziIOziException_allocationLimitExceeded_closure
 -Wl,-u,_base_ControlziExceptionziBase_nestedAtomically_closure
 -Wl,-u,_base_GHCziEventziThread_blockedOnBadFD_closure
 -Wl,-u,_base_GHCziWeak_runFinalizzerBatch_closure
 -Wl,-u,_base_GHCziTopHandler_flushStdHandles_closure
 -Wl,-u,_base_GHCziTopHandler_runIO_closure
 -Wl,-u,_base_GHCziTopHandler_runNonIO_closure
 -Wl,-u,_base_GHCziConcziIO_ensureIOManagerIsRunning_closure
 -Wl,-u,_base_GHCziConcziIO_ioManagerCapabilitiesChanged_closure
 -Wl,-u,_base_GHCziConcziSync_runSparks_closure
 -Wl,-u,_base_GHCziConcziSignal_runHandlersPtr_closure
 -Wl,-search_paths_first -lHSbase-4.8.1.0-GDytRqRVSUX7zckgKqJjgw
 -lHSinteger-gmp-1.0.0.0-2aU3IZNMF9a7mQ0OzsZ0dS -lHSghc-
 prim-0.4.0.0-8TmvWUcS1U1IKHT0levwg3 -lHSrts -lCffi -liconv -lgmp -lm -ldl
 }}}

 I noticed the following differences: Some of the linked libraries in the
 API case contain a -ghc7.10.2 suffix, e.g. -lHSrts-ghc7.10.2. When I
 execute the linking command without the suffix everything works fine.
 So I looked into the directories of the referenced libraries. The rts
 directory contains the following content:

 {{{
 libCffi.a
 libCffi_debug.a
 libCffi_l.a
 libCffi_p.a
 libCffi_thr.a
 libCffi_thr_debug.a
 libCffi_thr_l.a
 libCffi_thr_p.a
 libHSrts-ghc7.10.2.dylib
 libHSrts.a
 libHSrts_debug-ghc7.10.2.dylib
 libHSrts_debug.a
 libHSrts_l-ghc7.10.2.dylib
 libHSrts_l.a
 libHSrts_p.a
 libHSrts_thr-ghc7.10.2.dylib
 libHSrts_thr.a
 libHSrts_thr_debug-ghc7.10.2.dylib
 libHSrts_thr_debug.a
 libHSrts_thr_l-ghc7.10.2.dylib
 libHSrts_thr_l.a
 libHSrts_thr_p.a
 libffi.dylib
 }}}

 It seams that only the library with the .dylib extension also have the
 `-ghc7.10.2` suffix in the file name. So, is this an issue with ghc, MacOS
 X or Nix?

 Best,
 Sven

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11154>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list