#1843: ghc 6.8.1 broken on Mac OS X Leopard PPC
----------------------+-----------------------------------------------------
Reporter: guest | Owner:
Type: bug | Status: new
Priority: high | Milestone: 6.8.2
Component: Compiler | Version: 6.8.1
Severity: critical | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Architecture: powerpc
Os: MacOS X |
----------------------+-----------------------------------------------------
Comment (by thorkilnaur):
On a PPC Mac OS X 10.5 Leopard, I can reproduce the basic problem:
{{{
thorkil-naurs-mac-mini:1843 thorkilnaur$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.1
thorkil-naurs-mac-mini:1843 thorkilnaur$ ghc --make Test1.hs
[1 of 1] Compiling Main ( Test1.hs, Test1.o )
Linking Test1 ...
unknown scattered relocation type 4
unknown scattered relocation type 4
unknown scattered relocation type 4
thorkil-naurs-mac-mini:1843 thorkilnaur$ cat Test1.hs
main = putStr "Here I am for #1843 2007-Nov-18 10.32\n"
thorkil-naurs-mac-mini:1843 thorkilnaur$
}}}
This uses the binary distribution
http://haskell.org/ghc/dist/6.8.1/maeder/ghc-6.8.1-powerpc-apple-
darwin.tar.bz2 by Christian Maeder.
To figure out where these scattered messages come from, we do:
{{{
thorkil-naurs-mac-mini:1843 thorkilnaur$ rm Test1.o
thorkil-naurs-mac-mini:1843 thorkilnaur$ ghc --make Test1.hs -optl-t 2>&1
| awk '/scatter/{print l}{l=$0}'
/Users/thorkilnaur/tn/install/ghc-6.8.1/lib/ghc-6.8.1/lib/base-3.0.0.0/libHSbase-3.0.0.0.a(Conc__128.o)
/Users/thorkilnaur/tn/install/ghc-6.8.1/lib/ghc-6.8.1/lib/base-3.0.0.0/libHSbase-3.0.0.0.a(Conc__32.o)
/Users/thorkilnaur/tn/install/ghc-6.8.1/lib/ghc-6.8.1/lib/base-3.0.0.0/libHSbase-3.0.0.0.a(TopHandler__19.o)
thorkil-naurs-mac-mini:1843 thorkilnaur$
}}}
printing the line before each scattered message of the detailed (-optl-t)
linker output. So it appears that the base library of this binary
ghc-6.8.1 distribution contains compiled code that cannot be interpreted
properly by the Leopard ld linker.
To get an easier grip on the situation, I have split libHSbase-3.0.0.0.a
into separate .o files and checked each, using /usr/bin/ld -r, to see
whether the scattered message is produced. 94 of the about 9800 files in
this library have this problem. For example:
{{{
thorkil-naurs-mac-mini:ar thorkilnaur$ /usr/bin/ld -r Conc__128.o
unknown scattered relocation type 4
thorkil-naurs-mac-mini:ar thorkilnaur$
}}}
If I try this on a PPC Mac OS X 10.4 Tiger, the problem disappears:
{{{
Thorkil-Naurs-
Computer:~/tn/test/GHC/MacOSX/10.5Leopard/GHC6.8.1OnPPCOSX10.5Leopard/work/ar
thorkilnaur$ /usr/bin/ld -r Conc__128.o
Thorkil-Naurs-
Computer:~/tn/test/GHC/MacOSX/10.5Leopard/GHC6.8.1OnPPCOSX10.5Leopard/work/ar
thorkilnaur$
}}}
This indicates, as others have pointed out earlier, that some change
between 10.4 and 10.5 has caused the interpretation of .o files to be
changed, perhaps erroneously.
To get more information about what goes on, I have selected the smallest
of the .o files with this problem (it is {{{ST__15.o}}}) and used the
otool (suggested earlier by mokus, thanks) to dissect it:
{{{
thorkil-naurs-mac-mini:ar thorkilnaur$ /usr/bin/ld -r ST__15.o
unknown scattered relocation type 4
thorkil-naurs-mac-mini:ar thorkilnaur$ otool -r ST__15.o
ST__15.o:
Relocation information (__TEXT,__text) 9 entries
address pcrel length extern type scattered symbolnum/value
00000020 0 2 n/a 8 1 0x00000010
00000000 0 2 n/a 1 1 0x00000000
0000001c 1 2 1 3 0 7
00000018 0 2 n/a 5 1 0x0000002c
00000000 0 2 0 1 0 16777215
00000014 0 2 n/a 4 1 0x0000002c
0000002d 0 2 0 1 0 16777215
00000000 0 2 n/a 8 1 0x00000024
00000000 0 2 n/a 1 1 0x00000010
Relocation information (__DATA,__const) 2 entries
address pcrel length extern type scattered symbolnum/value
00000004 0 2 0 0 0 3
00000000 0 2 1 0 0 6
Relocation information (__DATA,__data) 6 entries
address pcrel length extern type scattered symbolnum/value
00000018 0 2 0 0 0 1
00000010 0 2 n/a 0 1 0x00000044
0000000c 0 2 1 0 0 8
00000008 0 2 1 0 0 9
00000004 0 2 1 0 0 10
00000000 0 2 1 0 0 5
thorkil-naurs-mac-mini:ar thorkilnaur$ otool -rv ST__15.o
ST__15.o:
Relocation information (__TEXT,__text) 9 entries
address pcrel length extern type scattered symbolnum/value
00000020 False long n/a SECTDIF True 0x00000010
False long n/a PAIR True 0x00000000
0000001c True long True BR24 False
_base_GHCziBase_zddmfail_info
00000018 False long n/a LO16 True 0x0000002c
False long False PAIR False half = 0x0000
00000014 False long n/a HI16 True 0x0000002c
False long False PAIR False half = 0x002d
00000000 False long n/a SECTDIF True 0x00000024
False long n/a PAIR True 0x00000010
Relocation information (__DATA,__const) 2 entries
address pcrel length extern type scattered symbolnum/value
00000004 False long False VANILLA False 3 (__DATA,__data)
00000000 False long True VANILLA False
_base_GHCziBase_zddmfail_closure
Relocation information (__DATA,__data) 6 entries
address pcrel length extern type scattered symbolnum/value
00000018 False long False VANILLA False 1 (__TEXT,__text)
00000010 False long n/a VANILLA True 0x00000044
0000000c False long True VANILLA False
_base_GHCziST_return_closure
00000008 False long True VANILLA False _base_GHCziST_zgzg_closure
00000004 False long True VANILLA False
_base_GHCziST_zgzgze_closure
00000000 False long True VANILLA False
_base_GHCziBase_ZCDMonad_static_info
thorkil-naurs-mac-mini:ar thorkilnaur$ otool -tv ST__15.o
ST__15.o:
(__TEXT,__text) section
_base_GHCziST_fail_info_dsp:
00000000 .long 0x00000014
00000004 .long 0x00050001
00000008 .long 0x00000000
0000000c .long 0x000f0003
_base_GHCziST_fail_info:
00000010 or r16,r15,r15
00000014 lis r15,0x0
00000018 ori r15,r15,0x2d
0000001c b 0x0
00000020 .long 0x00000010
thorkil-naurs-mac-mini:ar thorkilnaur$ otool -tV ST__15.o
ST__15.o:
(__TEXT,__text) section
_base_GHCziST_fail_info_dsp:
00000000 .long 0x00000014
00000004 .long 0x00050001
00000008 .long 0x00000000
0000000c .long 0x000f0003
_base_GHCziST_fail_info:
00000010 or r16,r15,r15
00000014 lis r15,hi16(_base_GHCziST_zdf2_closure+0x1)
00000018 ori r15,r15,lo16(_base_GHCziST_zdf2_closure+0x1)
0000001c b _base_GHCziBase_zddmfail_info
00000020 .long 0x00000010
thorkil-naurs-mac-mini:ar thorkilnaur$
}}}
The scattered relocation that ld complains about is presumably this one:
{{{
00000014 False long n/a HI16 True 0x0000002c
}}}
addressing the code line:
{{{
00000014 lis r15,hi16(_base_GHCziST_zdf2_closure+0x1)
}}}
(Wild guess: Some pointer tagging connection here?) I have attached the
{{{ST__15.o}}} file.
My best suggestion from this information would be to approach Apple,
reporting an error, but I may be wrong here. So please, experts, state
whether you agree with this.
If there is agreement that reporting the problem to Apple is a good idea,
I would also need some help to do that.
But there is more: One of the things that I tried was building a recent
HEAD (that would be 6.9.something) with the binary
http://haskell.org/ghc/dist/6.6.1/ghc-6.6.1-powerpc-apple-darwin.tar.bz2
by Christian Maeder. In this process, an apparently working stage1/ghc-
inplace was produced, but at some point, the scattered messages started to
appear:
{{{
/usr/bin/ld -x -r -o dist/build/HSbase-3.0.o dist/build/Data/Generics.o
dist/build/Data/Generics/Aliases.o dist/build/Data/Generics/Basics.o
dist/build/Data/Generics/Instances.o dist/build/Data/Generics/Schemes.o
dist/build/Data/Generics/Text.o dist/build/Data/Generics/Twins.o
dist/build/Foreign/Concurrent.o dist/build/GHC/Arr.o dist/build/GHC/Base.o
dist/build/GHC/Conc.o dist/build/GHC/ConsoleHandler.o
dist/build/GHC/Desugar.o dist/build/GHC/Dotnet.o dist/build/GHC/Enum.o
dist/build/GHC/Environment.o dist/build/GHC/Err.o
dist/build/GHC/Exception.o dist/build/GHC/Exts.o dist/build/GHC/Float.o
dist/build/GHC/ForeignPtr.o dist/build/GHC/Handle.o dist/build/GHC/IO.o
dist/build/GHC/IOBase.o dist/build/GHC/Int.o dist/build/GHC/List.o
dist/build/GHC/Num.o dist/build/GHC/PArr.o dist/build/GHC/Pack.o
dist/build/GHC/PrimopWrappers.o dist/build/GHC/Ptr.o dist/build/GHC/Read.o
dist/build/GHC/Real.o dist/build/GHC/ST.o dist/build/GHC/STRef.o
dist/build/GHC/Show.o dist/build/GHC/Stable.o dist/build/GHC/Storable.o
dist/build/GHC/TopHandler.o dist/build/GHC/Unicode.o dist/build/GHC/Weak.o
dist/build/GHC/Word.o dist/build/System/Timeout.o
dist/build/Control/Applicative.o dist/build/Control/Arrow.o
dist/build/Control/Category.o dist/build/Control/Concurrent.o
dist/build/Control/Concurrent/Chan.o dist/build/Control/Concurrent/MVar.o
dist/build/Control/Concurrent/QSem.o dist/build/Control/Concurrent/QSemN.o
dist/build/Control/Concurrent/SampleVar.o dist/build/Control/Exception.o
dist/build/Control/Monad.o dist/build/Control/Monad/Fix.o
dist/build/Control/Monad/Instances.o dist/build/Control/Monad/ST.o
dist/build/Control/Monad/ST/Lazy.o dist/build/Control/Monad/ST/Strict.o
dist/build/Data/Bits.o dist/build/Data/Bool.o dist/build/Data/Char.o
dist/build/Data/Complex.o dist/build/Data/Dynamic.o
dist/build/Data/Either.o dist/build/Data/Eq.o dist/build/Data/Fixed.o
dist/build/Data/Foldable.o dist/build/Data/Function.o
dist/build/Data/HashTable.o dist/build/Data/IORef.o dist/build/Data/Int.o
dist/build/Data/Ix.o dist/build/Data/List.o dist/build/Data/Maybe.o
dist/build/Data/Monoid.o dist/build/Data/Ord.o dist/build/Data/Ratio.o
dist/build/Data/STRef.o dist/build/Data/STRef/Lazy.o
dist/build/Data/STRef/Strict.o dist/build/Data/String.o
dist/build/Data/Traversable.o dist/build/Data/Tuple.o
dist/build/Data/Typeable.o dist/build/Data/Unique.o
dist/build/Data/Version.o dist/build/Data/Word.o dist/build/Debug/Trace.o
dist/build/Foreign.o dist/build/Foreign/C.o dist/build/Foreign/C/Error.o
dist/build/Foreign/C/String.o dist/build/Foreign/C/Types.o
dist/build/Foreign/ForeignPtr.o dist/build/Foreign/Marshal.o
dist/build/Foreign/Marshal/Alloc.o dist/build/Foreign/Marshal/Array.o
dist/build/Foreign/Marshal/Error.o dist/build/Foreign/Marshal/Pool.o
dist/build/Foreign/Marshal/Utils.o dist/build/Foreign/Ptr.o
dist/build/Foreign/StablePtr.o dist/build/Foreign/Storable.o
dist/build/Numeric.o dist/build/Prelude.o
dist/build/System/Console/GetOpt.o dist/build/System/CPUTime.o
dist/build/System/Environment.o dist/build/System/Exit.o
dist/build/System/IO.o dist/build/System/IO/Error.o
dist/build/System/IO/Unsafe.o dist/build/System/Info.o
dist/build/System/Mem.o dist/build/System/Mem/StableName.o
dist/build/System/Mem/Weak.o dist/build/System/Posix/Internals.o
dist/build/System/Posix/Types.o dist/build/Text/ParserCombinators/ReadP.o
dist/build/Text/ParserCombinators/ReadPrec.o dist/build/Text/Printf.o
dist/build/Text/Read.o dist/build/Text/Read/Lex.o dist/build/Text/Show.o
dist/build/Text/Show/Functions.o dist/build/Unsafe/Coerce.o `find
dist/build -name "*_stub.o" -print` dist/build/cbits/PrelIOUtils.o
dist/build/cbits/WCsubst.o dist/build/cbits/Win32Utils.o
dist/build/cbits/consUtils.o dist/build/cbits/dirUtils.o
dist/build/cbits/inputReady.o dist/build/cbits/lockFile.o
dist/build/cbits/longlong.o dist/build/cbits/selectUtils.o
ar: creating archive dist/build/libHSbase-3.0.a
unknown scattered relocation type 4
}}}
It seems that this is the first time that the linker is being asked to
link some code that has actually been produced by the stage1/ghc-inplace
compiler.
Further, I found:
{{{
thorkil-naurs-mac-mini:base thorkilnaur$ /usr/bin/ld -x -r -o
dist/build/HSbase-3.0.o dist/build/GHC/ForeignPtr.o
unknown scattered relocation type 4
thorkil-naurs-mac-mini:base thorkilnaur$ rm dist/build/GHC/ForeignPtr.o
thorkil-naurs-mac-mini:base thorkilnaur$ ../../compiler/stage1/ghc-inplace
-package-name base-3.0 -hide-all-packages -i -idist/build/autogen
-idist/build -i. -Idist/build -Iinclude -#include "HsBase.h" -odir
dist/build -hidir dist/build -stubdir dist/build -package rts-1.0 -O
-fglasgow-exts -package-name base -XCPP -idist/build -Werror -H64m -Onot
-fvia-C -O -c GHC/ForeignPtr.hs -o dist/build/GHC/ForeignPtr.o -ohi
dist/build/GHC/ForeignPtr.hi
thorkil-naurs-mac-mini:base thorkilnaur$ /usr/bin/ld -x -r -o
dist/build/HSbase-3.0.o dist/build/GHC/ForeignPtr.o
thorkil-naurs-mac-mini:base thorkilnaur$
}}}
So it appears that -fvia-C helps. But notice that I am not saying that the
native code generator is at fault, only that code provoking the problem is
apparently not being generated by gcc in this case.
And so, using -fvia-C all the way through, I have been able to produce a
working HEAD on and for PPC Mac OS X 10.5. mk/build.mk is:
{{{
HADDOCK_DOCS = YES
SRC_CC_OPTS = -Werror
SRC_HC_OPTS = -Werror -H64m -Onot -fvia-C
GhcStage1HcOpts = -Onot -fvia-C
GhcStage2HcOpts = -Onot -fvia-C
GhcLibHcOpts = -Onot -fvia-C
GhcLibWays =
SplitObjs = NO
NoFibWays =
STRIP = :
GhcBootLibs = YES
}}}
Fast testing produces (where the Pp* tests should be ignored, they are
related to work on #1337, sorry about that):
{{{
make fast stage=2 EXTRA_HC_OPTS=-fvia-C
...
OVERALL SUMMARY for test run started at Sun Nov 25 11:10:52 CET 2007
2001 total tests, which gave rise to
7595 test cases, of which
1 caused framework failures
5924 were skipped
1586 expected passes
75 expected failures
0 unexpected passes
10 unexpected failures
Unexpected failures:
Pp004(normal)
Pp005(normal)
Pp006(normal)
Pp007(normal)
Pp_coverage(normal)
currentDirectory001(normal)
directory001(normal)
ghci024(ghci)
print026(ghci)
recomp004(normal)
}}}
I haven't checked the unexpected results at all, but it doesn't look too
bad, really.
It is important to notice that this compiler is limping in the sense that
it can only reliably produce code that is accepted by the 10.5 linker with
-fvia-C.
Best regards
Thorkil
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1843#comment:13>
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