Opened 9 years ago

Closed 9 years ago

Last modified 15 months ago

#4819 closed bug (fixed)

[PATCH] undefined symbols; mixed architecture build

Reported by: altaic Owned by: simonmar
Priority: normal Milestone: 7.2.1
Component: Build System (make) Version: 7.1
Keywords: Cc: william.knop.nospam@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Building GHC failed Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

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")
 ]

Configure Info:

$./configure --build=x86_64-apple-darwin --host=x86_64-apple-darwin --target=x86_64-apple-darwin

...

Configure completed successfully.

   Building GHC version  : 7.1.20101203

   Build platform        : x86_64-apple-darwin
   Host platform         : x86_64-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  -m64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -fno-stack-protector              utils/unlit/dist/build/unlit.o    
ld: warning: in utils/unlit/dist/build/unlit.o, file was built for i386 which is not the architecture being linked (x86_64)
Undefined symbols:
  "_main", referenced from:
      start in crt1.10.5.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: The bootstrap ghc (previous one I had installed on the machine) was built for the i386 architecture and generates only i386 binaries/objects. By telling configure "--build=x86_64-apple-darwin", it assumes not only that the machine arch is x86_64 (which is true and is what I'd intended), but also that the bootstrap ghc targets x86_64 (which is false and I hadn't realized). This sort of problem seems to stem from the advent of multi-architecture machines, which has blurred the lines of native-compilation and cross-compilation.

Temporary Workaround: Have configure verify that the bootstrap ghc's arch (from ghc --info) matches the specified build arch, and spit out a sensible error if not. Here's a patch:

--- old-ghc/configure.ac	2010-12-06 01:35:13.000000000 -0500
+++ new-ghc/configure.ac	2010-12-06 01:35:13.000000000 -0500
@@ -227,6 +227,13 @@
     GHC_CONVERT_OS([$build_os], [BuildOS])
 fi
 
+# Verify that the installed (bootstrap) GHC is capable of generating code for the requested build platform.
+if test "$build" != "$bootstrap_target"
+then
+    echo "The bootstrap GHC ($bootstrap_target) cannot generate code for the given build platform ($build)"
+    exit 1
+fi
+
 if test "$host_alias" = ""
 then
     if test "${WithGhc}" != ""

Permanent Resolution: Allow ghc to directly target multiple platforms.

Change History (5)

comment:1 Changed 9 years ago by igloo

Status: newpatch

comment:2 Changed 9 years ago by igloo

Milestone: 7.0.3
Owner: set to igloo

Thanks, we'll take a look.

comment:3 Changed 9 years ago by simonmar

Owner: changed from igloo to simonmar

comment:4 Changed 9 years ago by simonmar

Resolution: fixed
Status: patchclosed

Fixed:

Fri Jan  7 08:35:41 PST 2011  Simon Marlow <marlowsd@gmail.com>
  * In configure, test that GHC generates code for the correct platform (#4819)
  Patch supplied by the bug reporter, tidied up by me.
  
  $ ./configure --with-ghc=$HOME/fp/bin/i386-unknown-linux/ghc --build=x86_64-unknown-linux
  checking for gfind... no
  checking for find... /usr/bin/find
  checking for sort... /usr/bin/sort
  checking for GHC version date... inferred 7.1.20110107
  checking version of ghc... 7.0.1
  checking build system type... x86_64-unknown-linux-gnu
  checking host system type... x86_64-unknown-linux-gnu
  checking target system type... x86_64-unknown-linux-gnu
  Host platform inferred as: i386-unknown-linux
  Target platform inferred as: i386-unknown-linux
  This GHC (/home/simonmar/fp/bin/i386-unknown-linux/ghc) does not generate code for the build platform
     GHC target platform    : i386-unknown-linux
     Desired build platform : x86_64-unknown-linux

comment:5 Changed 15 months ago by bgamari

Component: Build SystemBuild System (make)

The new Hadrian build system has been merged. Relabeling the tickets concerning the legacy make build system to prevent confusion.

Note: See TracTickets for help on using tickets.