#4818: [PATCH] OSX: undefined symbols; isysroot misconfiguration
---------------------------------+------------------------------------------
    Reporter:  altaic            |       Owner:                     
        Type:  bug               |      Status:  new                
    Priority:  normal            |   Component:  Build System       
     Version:  7.1               |    Keywords:                     
    Testcase:                    |   Blockedby:                     
          Os:  MacOS X           |    Blocking:                     
Architecture:  Unknown/Multiple  |     Failure:  Building GHC failed
---------------------------------+------------------------------------------
 '''Machine:'''
 {{{
 Processor:     3.06 GHz Intel Core 2 Duo
 Architecture:  x86/x86_64
 OS:            Mac OS X 10.6.5
 }}}

 '''Bootstrap GHC Info:'''
 {{{
 $ghc --info
  [("Project name","The Glorious Glasgow Haskell Compilation System")
  ,("Project version","7.0.0.20100924")
  ,("Booter version","6.12.3")
  ,("Stage","2")
  ,("Build platform","i386-apple-darwin")
  ,("Host platform","i386-apple-darwin")
  ,("Target platform","i386-apple-darwin")
  ,("Have interpreter","YES")
  ,("Object splitting","NO")
  ,("Have native code generator","YES")
  ,("Have llvm code generator","YES")
  ,("Use archives for ghci","True")
  ,("Support SMP","YES")
  ,("Unregisterised","NO")
  ,("Tables next to code","YES")
  ,("RTS ways","l debug  thr thr_debug thr_l thr_p  dyn debug_dyn thr_dyn
 thr_debug_dyn")
  ,("Leading underscore","YES")
  ,("Debug on","False")
 
,("LibDir","/Library/Frameworks/GHC.framework/Versions/700/usr/lib/ghc-7.0.0.20100924")
  ,("Global Package
 
DB","/Library/Frameworks/GHC.framework/Versions/700/usr/lib/ghc-7.0.0.20100924/package.conf.d")
  ]
 }}}

 '''Note:''' Other configure options cause the error; the following just
 happens to be the last one I used.

 '''Configure Info:'''
 {{{
 $./configure --build=i386-apple-darwin --host=i386-apple-darwin
 --target=x86_64-apple-darwin

 ...

 Configure completed successfully.

    Building GHC version  : 7.1.20101203

    Build platform        : i386-apple-darwin
    Host platform         : i386-apple-darwin
    Target platform       : x86_64-apple-darwin

    Bootstrapping using   : /usr/bin/ghc
       which is version   : 7.0.0.20100924

    Using GCC             : /usr/bin/gcc
       which is version   : 4.2.1

    ld       : /usr/bin/ld
    Happy    : /usr/local/bin/happy (1.18.5)
    Alex     : /usr/local/bin/alex (2.3.3)
    Python   : /usr/bin/python
    Perl     : /usr/bin/perl
    dblatex  : /usr/local/bin/dblatex
    xsltproc : /usr/bin/xsltproc
    HsColour : /Users/x/.cabal/bin/HsColour

    Building DocBook HTML documentation : YES
    Building DocBook PS documentation   : YES
    Building DocBook PDF documentation  : YES
 }}}

 '''Error:'''
 {{{
 "/usr/bin/ghc"    -H32m -O  -package-conf libraries/bootstrapping.conf
 -i -iutils/unlit/. -iutils/unlit/dist/build
 -iutils/unlit/dist/build/autogen -Iutils/unlit/dist/build
 -Iutils/unlit/dist/build/autogen        -no-user-package-conf -rtsopts
 -c utils/unlit/unlit.c -o utils/unlit/dist/build/unlit.o
 "inplace/bin/mkdirhier" utils/unlit/dist/build/tmp//.
 "/usr/bin/gcc" -o utils/unlit/dist/build/tmp/unlit  -march=i686 -m32
 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -fno-
 stack-protector              utils/unlit/dist/build/unlit.o
 Undefined symbols:
   "_fopen$UNIX2003", referenced from:
       _main in unlit.o
       _main in unlit.o
 ld: symbol(s) not found
 collect2: ld returned 1 exit status
 make[1]: *** [utils/unlit/dist/build/tmp/unlit] Error 1
 make: *** [all] Error 2
 }}}

 '''Hypothesis:''' GCC tries to use a hardcoded `-isysroot` from the
 following patch to compile `unlit`, which cannot be mixed with other
 components which seem to be using the default SDK on my machine. Even when
 I specify `--with-macosx-deployment-target=10.5` for configure, unlit
 still fails. I'm thinking that the deployment target only affects stage 2
 or something, so earlier stages are using a combination of the default SDK
 (in my case, 10.6) and the hardcoded one (10.5). Here's the patch that
 caused the problem:
 {{{
 [Tell gcc to support back to OS X 10.5
 Ian Lynagh <[email protected]>**20101203201558
  Ignore-this: f02d70e5b9cce50137981c6cb2b62a18
 ] hunk ./aclocal.m4 27
 +    case $$1 in
 +    i386-apple-darwin|x86_64-apple-darwin)
 +        # We support back to OS X 10.5
 +        $2="$$2 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-
 version-min=10.5"
 +        $3="$$3 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-
 version-min=10.5"
 +        ;;
 +    esac
 +
 }}}

 '''Temporary Workaround:''' Revert above patch and apply the following:
 {{{
 --- old-ghc/aclocal.m4  2010-12-05 14:29:54.000000000 -0500
 +++ new-ghc/aclocal.m4  2010-12-05 14:29:54.000000000 -0500
 @@ -24,6 +24,14 @@
          ;;
      esac

 +    case $$1 in
 +    i386-apple-darwin|x86_64-apple-darwin)
 +        # Only support OS X 10.5 and later
 +        $2="$$2 -mmacosx-version-min=10.5"
 +        $3="$$3 -mmacosx-version-min=10.5"
 +        ;;
 +    esac
 +
      # If gcc knows about the stack protector, turn it off.
      # Otherwise the stack-smash handler gets triggered.
      echo 'int main(void) {return 0;}' > conftest.c
 }}}

 '''Permanent Resolution:''' Instead of hardcoding `-isysroot` in
 aclocal.m4 (`-mmacosx-version-min` is fine to hard-code, though), we
 should have build, host, and target isysroots (or stage0, stage1, etc.
 isysroots), which are detected/specified by the configure script. It's
 possible that separate isysroots aren't necessary, however in any case,
 all the components in a stage must use the same isysroot if they're to be
 linked together.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to