Bug: --make non-functional on GHC compiler

Stefan O'Rear stefanor at cox.net
Sat Mar 10 16:06:13 EST 2007


On Sat, Mar 10, 2007 at 09:08:45AM -0800, Samuel A. Falvo II wrote:
> Required Information:

First, AFAIK nobody but Trac is supposed to post here - this is a
new-ticket announce list only.  All bugreports and discussions are
supposed to go through Trac. 

http://hackage.haskell.org/trac/ghc

> 1.  What kind of machine are you running on, and exactly what version
> of the operating system are you using? (on a Unix system, uname -a or
> cat /etc/motd will show the desired information.)
> 
> $ uname -a
> 
> Linux aldeberan 2.6.16.13-3c95x #3 PREEMPT Tue May 2 23:16:59 PDT 2006
> i686 unknown unknown GNU/Linux
> 
> 
> 2.  What version of GCC are you using? gcc -v will tell you.
> 
> bash-2.05b$ gcc -v
> Reading specs from /usr/lib/gcc-lib/i486-slackware-linux/3.3.4/specs
> Configured with: ../gcc-3.3.4/configure --prefix=/usr --enable-shared
> --enable-threads=posix --enable-__cxa_atexit --disable-checking
> --with-gnu-ld --verbose --target=i486-slackware-linux
> --host=i486-slackware-linux
> Thread model: posix
> gcc version 3.3.4
> 
> 3.  Run the sequence of compiles/runs that caused the offending
> behaviour, capturing all the input/output in a "script" (a UNIX
> command) or in an Emacs shell window. We'd prefer to see the whole
> thing.
> 
> bash-2.05b$ cat Main.hs
> module CutParse(main) where
> 
> main :: IO ()
> main = do putStr "Hello world!"

Quote the Revised Report: http://haskell.org/onlinereport/modules.html

A Haskell program is a collection of modules, one of which, by
convention, must be called Main and must export the value main. The
value of the program is the value of the identifier main in module
Main, which must be a computation of type IO t for some type t (see
Chapter 7). When the program is executed, the computation main is
performed, and its result (of type t) is discarded. 

In other words, if you want to be portable off GHC you *need* to call
your main module 'Main'.  Note that the filename of the main module is
irrelevant, only the header. 

Quoth the 6.7.20070308 user guide:

  4.8.2. The main package

   Every complete Haskell program must define main in module Main in
   package main. (Omitting the -package-name flag compiles code for
   package main.) Failure to do so leads to a somewhat obscure
   link-time error of the form:

 /usr/bin/ld: Undefined symbols:
 _ZCMain_main_closure
 ___stginit_ZCMain

I can't find anything in the 6.4 ug however.

> bash-2.05b$ ghc --make -v Main
> Glasgow Haskell Compiler, Version 6.4.1, for Haskell 98, compiled by
> GHC version 6.2.2
> Using package config file: /usr/local/lib/ghc-6.4.1/package.conf
> Hsc static flags: -static
> *** Chasing dependencies:
> Chasing modules from: Main
> Stable modules:
> *** Compiling CutParse         ( Main.hs, interpreted ):
> compile: input file Main.hs
> *** Checking old interface for CutParse:
> Compiling CutParse         ( Main.hs, Main.o )
> *** Parser:
> *** Renamer/typechecker:
> *** Desugar:
>    Result size = 30
> *** Simplify:
>    Result size = 6
> *** Tidy Core:
>    Result size = 6
> *** CorePrep:
>    Result size = 8
> *** Stg2Stg:
> *** CodeGen:
> *** CodeOutput:
> *** Assembler
> gcc -I. -c /tmp/ghc11833.s -o Main.o
> *** Deleting temp files
> Deleting: /tmp/ghc11833.s
> Upsweep completely successful.
> *** Deleting temp files
> Deleting:
> link(batch): upsweep (partially) failed OR
>   Main.main not exported; not linking.
> *** Deleting temp files
> Deleting:
> bash-2.05b$ ls
> Main.hi  Main.hs  Main.o
> 
> NOTE: I have verified this problem exists with both the GHC 6.2.2 and
> 6.4.1 compilers.  I do not yet have 6.6.x due to the hours it takes to
> compile on my box.
> 
> 5.  What is the program behaviour that is wrong, in your opinion?
> 
> According to two sources:
> 
> * http://haskell.org/ghc/docs/6.4/html/users_guide/modes.html#make-mode
> * ghc --help
> 
> I should be able to "simply" invoke the --make option to have it build
> a complete program.  The program was reduced to a simple "Hello world"
> program for the sake of demonstration in this bug.  However, nothing I
> do convinces GHC to produce an executable, as per provided
> documentation.
> 
> Folks on IRC also suggested using the --main-is= flag, as follows:
> 
> bash-2.05$ ghc --make -v --main-is=Main.main Main
> 
> however, this also produces the same result -- no executable binary.
> 
> 6.  If practical, please send enough source files for us to duplicate
> the problem.
> 
> See attached file.
> 
> I should point out that, in all honesty, I think this is a bug with
> the documentation more than a bug with GHC itself; clearly, GHC 6.2.2
> was used to *build* GHC 6.4.1, so it MUST be possible to emit
> binaries.  The trick is giving it the right options to do so.  My
> thinking is that the documentation is not correct in this area.
> 
> Alternatively, --make itself may be buggy, and that GHC 6.4.1 was
> built without using it.
> 
> Either way, there is a fundamental disconnect between docs and reality.  :)
> 
> Thank you.
> 
> -- 
> Samuel A. Falvo II

> module CutParse(main) where
> 
> main :: IO ()
> main = do putStr "Hello world!"
> 



More information about the Glasgow-haskell-bugs mailing list