Changes between Version 6 and Version 7 of Arm64


Ignore:
Timestamp:
Jan 25, 2016 12:41:53 AM (4 years ago)
Author:
hypoon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Arm64

    v6 v7  
    162162* Next is `libraries/unix/System/Posix/Terminal/Common.hsc`. This is probably really, really bad. I have no idea what I'm doing here. `_POSIX_VDISABLE` doesn't seem to exist in the android libraries, or not in the way that `Common.hsc` wants to use it, or... honestly, I don't know. After some googling, it looked as though `-1` is a valid definition for `_POSIX_VDISABLE`, so I just swapped that out so it would compile. I have no idea what the consequences for this actually are.
    163163
    164 * Next is `mk/config.mk.in`. This was part of me trying to get PIC and PIE enabled. Didn't know what triple to add, so I guessed at two different ones. I'm not entirely sure why this made sense at the time, perhaps rwbarton remembers.
     164* Next is `mk/config.mk.in`. This was part of me trying to get PIC and PIE enabled. Didn't know what triple to add, so I guessed at two different ones. I'm not entirely sure why this made sense at the time, perhaps `rwbarton` remembers.
    165165
    166166* Next is `rts/posix/OSThreads.c`. Well, `cpu_set_t` isn't defined in the Android libraries either. Since I don't know what I'm doing, I commented out almost the entire `if` block, leaving just the last branch because that seemed pretty foolproof. Again, I have no idea what the consequences for this may be.
     
    177177}}}
    178178
     179My [attachment:build.mk] is pretty straightforward. Somewhat of a mix between `quick.mk` and `quick-cross.mk`, with some extra options to turn off dynamic linking (I forget why, but it had something to do with making it use `-pie`... maybe `rwbarton` knows.) and to turn on `-fPIC`. Download it to `$PROJDIR`.
     180
     181{{{
     182mv $PROJDIR/build.mk $PROJDIR/ghc-8.0.0.20160111/mk/build.mk
     183}}}
    179184In order to get ld and ld.gold to do what I want (link as much with `-pie` as possible), I created some wrapper scripts to eliminate `pie` from the list of arguments whenever `-r` or `-shared` is found. There is probably a better way to do this, perhaps making use of substitution parameters (`-S`), but this worked for now. Download the two wrapper scripts, [attachment:aarch64-linux-android-ld] and [attachment:aarch64-linux-android-ld.gold], and put them in `$PROJDIR`.
    180185
     
    186191mv $TOOLCHAIN/bin/aarch64-linux-android-ld.gold{,.orig}
    187192mv $PROJDIR/aarch64-linux-android-ld.gold $TOOLCHAIN/bin/aarch64-linux-android-ld.gold
    188 
    189 }}}
    190 
    191 My configure command got very long because I didn't trust it to find anything. Some of these options may be unnecessary.
     193mv $TOOLCHAIN/bin/opt{,.bak}
     194ln -s /usr/bin/opt $TOOLCHAIN/bin/opt
     195mv $TOOLCHAIN/bin/llc{,.bak}
     196ln -s /usr/bin/llc $TOOLCHAIN/bin/llc
     197}}}
     198
     199My configure command got very long because I didn't trust it to find anything. Some of these options may be unnecessary. I've said it a thousand times, and I'll say it again: I don't know what I'm doing.
    192200
    193201{{{
     
    214222}}}
    215223
    216 //CLANG
     224Assuming that completes correctly, we start the build. I used `-j5` to run five jobs at once, but you should tweak this to fit your processor's multitasking capabilities. I read somewhere not to exceed eight, though. This builds stage 1 and stage 2.
     225
     226{{{
     227cd $PROJDIR/ghc-8.0.0.20160111
     228make -j5
     229}}}
     230
     231If that works, then next we'll pack it up to move it to the tablet:
     232
     233{{{
     234cd $PROJDIR/ghc-8.0.0.20160111
     235make binary-dist
     236}}}
     237
     238That should produce `ghc-8.0.0.20160111-aarch64-unknown-linux-android.tar.bz2` in `$PROJDIR/ghc-8.0.0.20160111`.
     239
     240== Installing GHC ==
     241
     242Start up Termux on the tablet. I installed a huge list of software from their repo, most of which has nothing to do with GHC, but I'll list it below, just in case:
     243
     244{{{
     245apt, bash, bc, binutils, busybox,
     246bzip2, ca-certificates, clang, clang-dev, command-not-found,
     247coreutils, dash, diffutils, dnsutils, dpkg,
     248file, findutils, flex, fontconfig, freetype,
     249g++, gawk, gcc, git, glib,
     250gnupg, gnuplot, grep, gzip, harfbuzz,
     251ldns, less, libandroid-glob, libandroid-support, libandroid-support-dev,
     252libbz2, libcairo, libcurl, libffi, libgmp,
     253libgnustl, liblzma, libmpc, libmpfr, libpixman,
     254libpng, libuuid, libxml2, make, man,
     255ncurses, ndk-stl, ndk-sysroot, openssh, openssl,
     256pango, patch, pcre, perl, readline,
     257resolv-conf, sed, tar, termux-tools, vim,
     258vim-runtime, wget, xz-utils
     259}}}
     260
     261Now copy over your tarball, and extract it.
     262
     263{{{
     264cd
     265mkdir ghc
     266scp user@buildmachine:arm/ghc-8.0.0.20160111/ghc-*.bz2 ./ghc/
     267cd ghc
     268tar xvjf ghc-*.bz2
     269cd ghc-8.0.0.20160111
     270}}}
     271
     272Now things get a little questionable. Because this is Android, `/bin/sh` doesn't exist. We need to replace all references to it with the one Termux supplies:
     273
     274{{{
     275cd ~/ghc/ghc-8.0.0.20160111
     276grep -IlR /bin/sh . | xargs -L1 sed -i s?/bin/sh?`which sh`?
     277}}}
     278
     279Almost there, now let's try installing GHC:
     280
     281{{{
     282cd ~/ghc/ghc-8.0.0.20160111
     283# just FYI, the home directory in Termux is /data/data/com.termux/files/home
     284./configure --prefix=/data/data/com.termux/files/home/ghc
     285}}}
     286
     287And...! This is where the story ends, for now. I get the following error:
     288
     289{{{
     290checking for path to top of build tree... CANNOT LINK EXECUTABLE: "/data/data/com.termux/files/usr/lib/libandroid-support.so" is 32-bit instead of 64-bit
     291page record for 0x7fa2c78090 was not found (block_size=64)
     292configure: error: cannot determine current directory
     293}}}
     294
     295From what I can tell, all of the Termux packages (including shared libraries) are compiled as 32-bit. The next step would be to recompile them as 64-bit, which the Termux author appears to be working on.
     296
     297Another approach may be to forget PIC and PIE and just try statically linking the GHC binaries. I don't know if that will circumvent the 32-bit vs. 64-bit issue.
     298
     299If I come back to this project and make any more progress, I'll update this page.