Dubiousjim | 1 Apr 19:11 2013
Picon

porting to uClibc-based 686 Linux

My preferred system is a 686 Linux distro based on uClibc. No ghc
binaries available yet there. I'd like to remedy that.

I have ghc 7.4.2 running on an 686 Linux distro based on glibc (and also
on two different versions of Mac OS X, but they seem more distant and so
less likely to be helpful). In fact, ghc 7.6.2 binaries are also
available for that system, but I'd like to keep in synch with the last
released Haskell platform (which is what I've got on the Macs). That's
supposed to be updated in May, so if it's only possible to port ghg >=
7.6.x to my target system, that won't be so terrible. I'm hoping though
to be able to port a ghc < 7.8.x, because I don't expect to see that
version in any soon-to-be-released Haskell platform. (I mention this
because
http://hackage.haskell.org/trac/ghc/wiki/CrossCompilation says:
"Support for cross-compilation works reasonably well in 7.8.1. Previous
versions had various issues which are usually work-aroundable.")

Ok, so I'm getting stuck trying to build a version of ghc that will run
on the target, uClibc-based system. I have a working cross-compiler. (In
fact, I have two, one built using crosstools-NG, the other built using
buildroot.) My target identifier is "i686-buildroot-linux-uclibc".

I've tried the method for cross-compiling ghc posted here:
http://hackage.haskell.org/trac/ghc/wiki/Building/CrossCompiling
I had to tweak the configure script to not complain about the
"buildroot" vendor id. Here is the content of my mk/build.mk file:

    BuildFlavour = unreg
    ...
    ifeq "$(BuildFlavour)" "unreg"
(Continue reading)

Dubiousjim | 1 Apr 23:41 2013
Picon

Re: porting to uClibc-based 686 Linux

On Mon, Apr 01, 2013 at 01:11:20PM -0400, Dubiousjim wrote:
>   However, this fails at the following point:
> 
>       ""  -fno-stack-protector -DNO_REGS -DUSE_MINIINTERPRETER
>       -D__GLASGOW_HASKELL__=704 -Iincludes -DNO_REGS
>       -DUSE_MINIINTERPRETER
>       -Iincludes -Iincludes/dist-derivedconstants/header
>       -Iincludes/dist-ghcconstants/header -Irts -DNOSMP -c
>       includes/mkDerivedConstants.c -o
>       includes/dist-derivedconstants/build/mkDerivedConstants.o
>       /bin/sh: : Permission denied
>       make[1]: ***
>       [includes/dist-derivedconstants/build/mkDerivedConstants.o]
>       Error 127
>       make: *** [bootstrapping-files] Error 2
> 
>   I don't know if it's a variable that's supposed to point to $CC that's
>   coming up "", or one that's supposed to point to ghc. I'm guessing the
>   latter. I can't proceed with the porting instructions at this point
>   because includes/dist-derivedconstants is empty (just an empty build
>   dir), and includes/dist-ghcconstants doesn't exist yet.
> 
> 
> Any advice on how to proceed further using either of the strategies I
> described (cross-compiling, or bootstrapping using using unregisterised
> intermediate C files), would be welcomed.

I got past that point by re-entering the failing command line by hand,
and changing the leading "" to "gcc". I had to do that a couple of times
(four). Then I can proceed to copy some include files to the host, run
(Continue reading)

Dubiousjim | 2 Apr 15:11 2013
Picon

Re: porting to uClibc-based 686 Linux

I've shifted my attempts to cross-compile to the 7.6.2 sources. Here
I'm having better success with the instructions at
http://hackage.haskell.org/trac/ghc/wiki/Building/CrossCompiling, though
it still takes some fiddling and in the end I am still getting stuck.

To refresh, I'm trying to bootstrap from a working ghc (now I have 7.6.2
installed on the host) on a typical Linux 686 host system, glibc-based,
to get a ghc that can be installed on a similar target system, differing
in that it uses uclibc instead of glibc.

I have a working cross-compiler, and seem to have everything else I need
to have installed on my host. I did have to make sure that my
cross-compiler tree had gmp and libiconv and ncurses installed in it.

I also had to edit the file /usr/lib/ghc-7.6.2/include/ghcautoconf.h
on my host system. This was #defining _FILE_OFFSET_BITS to 64, but the
uclibc on my target system wasn't compiled with large file support,
hence I thought the uclibc in my cross-compiler toolchain shouldn't be
either. But then that #define in the host's ghcautoconf.h was
conflicting. So I just commented it out for the time being.

Here's what I've done, on the host, from a clean detar of the ghc 7.6.2
sources.

I made this change at three locations in ghc's topmost
configure script, to get it to recognize my cross-compiler tag 
"i686-buildroot-linux-uclibc":

       case "$build_vendor" in
    -  pc|gentoo) # like i686-pc-linux-gnu and i686-gentoo-freebsd8
(Continue reading)

Dubiousjim | 3 Apr 15:56 2013
Picon

Re: porting to uClibc-based 686 Linux

I've gotten somewhat further cross-compiling 7.6.2 sources, though
still not all the way.

I also tried following the instructions at
http://hackage.haskell.org/trac/ghc/wiki/Building/Porting
with these sources, but couldn't get them to work either.

This continues to log my efforts to follow the instructions at
http://hackage.haskell.org/trac/ghc/wiki/Building/CrossCompiling

One thing I notice by comparing the 7.6.2 sources and the pre-release
sources available at 
http://www.haskell.org/ghc/dist/current/dist/ghc-7.7-src.tar.bz2
is that the instructions at the wiki webpage just cited are tailored
to the post-7.6.2 sources. Some of the configure settings should be
different for 7.6.2.

In particular, I had been using this:

is that the instructions at the wiki webpage just cited are tailored
to the post-7.6.2 sources. Some of the configure settings should be
different for 7.6.2.

In particular, I had been using this:

./configure --target=i686-buildroot-linux-uclibc --disable-largefile

as the wiki pages seem to suggest. But now I see that I should also be
setting --host for 7.6.2, and also supplying an --alien=<script> option.

(Continue reading)

Dubiousjim | 3 Apr 16:55 2013
Picon

Re: porting to uClibc-based 686 Linux

On Wed, Apr 03, 2013 at 09:56:58AM -0400, Dubiousjim wrote:

> Ok, with all of that, the build completes. And the build ghc-stage2
> (which I temporarily named inplace/lib/ghc-stage2.exe, but now let's
> restore it to its original name) does in fact execute on the target
> machine:
> 
>     $ inplace/lib/ghc-stage2 --version
>     The Glorious Glasgow Haskell Compilation System, version 7.6.2
>     $ inplace/lib/ghc-stage2 --interactive
>     ghc-stage2: missing -B<dir> option
>     $ cat ~/hello.hs
>     main = putStrLn "Hello World!\n"
>     $ inplace/lib/ghc-stage2 -B./inplace/lib ~/hello.hs -o hello
>     $ ./hello
>     Can't modify application's text section; use the GCC option -fPIE
>     for
>     position-independent executables.
> 
> That's as far as I've got for now. Hopefully someone will have
> bothered to read this far and have some suggestions for what I should be
> doing differently, or how to proceed from here, to get the compiled
> ghc-stage2 really working on the target machine, so that I can use it to
> compile ghc on the target machine directly.

Oh, in fact I'm closer than I thought. The error I reported as:

>     $ inplace/lib/ghc-stage2 -B./inplace/lib --interactive
>     GHCi, version 7.6.2: http://www.haskell.org/ghc/  :? for help
>     Loading package ghc-prim ... ghc-stage2: mmap 442368 bytes at (nil):
(Continue reading)

Dubiousjim | 6 Apr 05:12 2013
Picon

Re: porting to uClibc-based 686 Linux

Am posting this follow-up to two mailing lists, because I've inquired
about it on both. Previous messages are at:
  *
  http://www.haskell.org/pipermail/glasgow-haskell-users/2013-April/023912.html
  * http://lists.alpinelinux.org/alpine-devel/1699.html

I have seemed to successfully cross-compile a stage2 ghc for my target
system, an i686 Linux based on uClibc. One issue I don't think I've
mentioned before is that the target system uses a kernel with grsecurity
and PaX, and that involves patching the toolchain as well. However my
cross-compiling toolchain doesn't have any such tweaks applied. This
will be relevant below. Another potential issue is that my host system,
a different i686 Linux based on glibc, is running inside a chroot on my
target system. I don't think this is in fact responsible for any
problems, but I thought I should mention it.

So I last wrote on the glasgow-haskell mailing list:

On Wed, Apr 03, 2013 at 10:55:14AM -0400, Dubiousjim wrote:
> But there's still something funny with the binaries generated by the
> compiler. That means I can't yet use this ghc to directly recompile ghc
> on my target system.
> 
>     $ cat ~/hello.hs
>     main = putStrLn "Hello World!\n"
>     $ rm -f hello
>     $ inplace/bin/ghc-stage2 -B./inplace/lib ~/hello.hs -o hello
>     [1 of 1] Compiling Main             ( /home/jim/hello.hs,
>     /home/jim/hello.o ) [flags changed]
>     Linking hello ...
(Continue reading)

Dubiousjim | 6 Apr 05:16 2013
Picon

Re: porting to uClibc-based 686 Linux

Am posting this follow-up to two mailing lists, because I've inquired
about it on both. Previous messages are at:
  *
  http://www.haskell.org/pipermail/glasgow-haskell-users/2013-April/023912.html
  * http://lists.alpinelinux.org/alpine-devel/1699.html

I have seemed to successfully cross-compile a stage2 ghc for my target
system, an i686 Linux based on uClibc. One issue I don't think I've
mentioned before is that the target system uses a kernel with grsecurity
and PaX, and that involves patching the toolchain as well. However my
cross-compiling toolchain doesn't have any such tweaks applied. This
will be relevant below. Another potential issue is that my host system,
a different i686 Linux based on glibc, is running inside a chroot on my
target system. I don't think this is in fact responsible for any
problems, but I thought I should mention it.

So I last wrote on the glasgow-haskell mailing list:

On Wed, Apr 03, 2013 at 10:55:14AM -0400, Dubiousjim wrote:
> But there's still something funny with the binaries generated by the
> compiler. That means I can't yet use this ghc to directly recompile ghc
> on my target system.
> 
>     $ cat ~/hello.hs
>     main = putStrLn "Hello World!\n"
>     $ rm -f hello
>     $ inplace/bin/ghc-stage2 -B./inplace/lib ~/hello.hs -o hello
>     [1 of 1] Compiling Main             ( /home/jim/hello.hs,
>     /home/jim/hello.o ) [flags changed]
>     Linking hello ...
(Continue reading)

Ian Lynagh | 18 Apr 00:18 2013

Re: porting to uClibc-based 686 Linux

On Fri, Apr 05, 2013 at 11:12:38PM -0400, Dubiousjim wrote:
>     target$ inplace/bin/ghc-stage2 -o hello-cross hello.hs
>     [1 of 1] Compiling Main             ( hello.hs, hello.o )
>     Linking hello-cross ...
>     target$ ./hello-cross
>     Can't modify application's text section; use the GCC option -fPIE
>     for position-independent executables.

You can pass -fPIE to gcc by using the -optc-fPIE flag.

Thanks
Ian
Dubiousjim | 18 Apr 12:48 2013
Picon

Re: porting to uClibc-based 686 Linux

On Wed, Apr 17, 2013 at 11:18:52PM +0100, Ian Lynagh wrote:
> On Fri, Apr 05, 2013 at 11:12:38PM -0400, Dubiousjim wrote:
> >     target$ inplace/bin/ghc-stage2 -o hello-cross hello.hs
> >     [1 of 1] Compiling Main             ( hello.hs, hello.o )
> >     Linking hello-cross ...
> >     target$ ./hello-cross
> >     Can't modify application's text section; use the GCC option -fPIE
> >     for position-independent executables.
> 
> You can pass -fPIE to gcc by using the -optc-fPIE flag.
> 
> Thanks
> Ian

Thanks Ian. There's much I don't fully understand about ghc, but I read
somewhere that the 
-optc-* options would only be applied when building via intermediate C
files, which isn't
happening in the compilation process specified above. Is this incorrect,
or have
I misunderstood something?

In any event, adding -optc-fPIE doesn't remove the error message.

That error message is kicked up by uclibc, on account of the hello-cross
binary having a TEXTREL section, which I understand it shouldn't have if
we're generating PIE or PIC code. The instruction to "use the GCC option
-fPIE"
is just uclibc's suggestion as to how to avoid this.

(Continue reading)

Ian Lynagh | 21 Apr 20:00 2013

Re: porting to uClibc-based 686 Linux

On Thu, Apr 18, 2013 at 06:48:12AM -0400, Dubiousjim wrote:
> On Wed, Apr 17, 2013 at 11:18:52PM +0100, Ian Lynagh wrote:
> > On Fri, Apr 05, 2013 at 11:12:38PM -0400, Dubiousjim wrote:
> > >     target$ inplace/bin/ghc-stage2 -o hello-cross hello.hs
> > >     [1 of 1] Compiling Main             ( hello.hs, hello.o )
> > >     Linking hello-cross ...
> > >     target$ ./hello-cross
> > >     Can't modify application's text section; use the GCC option -fPIE
> > >     for position-independent executables.
> > 
> > You can pass -fPIE to gcc by using the -optc-fPIE flag.
> 
> Thanks Ian. There's much I don't fully understand about ghc, but I read
> somewhere that the 
> -optc-* options would only be applied when building via intermediate C
> files, which isn't
> happening in the compilation process specified above. Is this incorrect,
> or have
> I misunderstood something?

Ah, sorry, I assumed that you were doing an unreg build.

If I were you I'd probably start off by trying to do an unreg
cross-compile with HEAD. However, the unreg build is currently broken in
HEAD (http://hackage.haskell.org/trac/ghc/ticket/7792), but I'm hoping
to have a fix soon.

Thanks
Ian
(Continue reading)


Gmane