M-HT
Very Active Member
These are the instructions I used to build a D crosscompiler - gdc (based on gcc).
I used information from these pages:
http://forum.dlang.org/thread/ji5lq7$9mt$1@digitalmars.com
https://github.com/D-Programming-GDC/GDC
http://gdcproject.org/wiki/Cross%20Compiler/crosstool-NG
http://www.crosstool-ng.org/
I tested it on Ubuntu 13.04 64-bit Server Edition and on Linux Mint Debian 64-bit Cinnamon Edition.
Tip: read the whole instructions before building it yourself.
First install some required packages:
sudo apt-get install build-essential libtool automake bison flex gperf texinfo gawk ncurses-dev libexpat1-dev python-dev
Then install crosstool-NG, which is used to build the crosscompiler.Since I wanted to use gcc 4.7.3 and the latest release only supports gcc 4.7.2, I used a development version from repositories.
cd
hg clone http://crosstool-ng.org/hg/crosstool-ng
cd crosstool-ng
./bootstrap
./configure --prefix="$HOME/opt"
make
make install
Next prepare and configure the crosscompiler:
In the prepared configuration change following items:
Then start building the crosscompiler:
It will first download required sources and then start compiling.Break the process after downloading all files (ctrl+c), because gdc needs to be added to the gcc sources.
First get gdc from repositories:
cd
mkdir -p gdc/dev
git clone https://github.com/D-Programming-GDC/GDC.git gdc/dev
cd gdc/dev
git checkout e63f8a7a5657684c0f2c3d2fd1a9c33eec0208c0
The commit I used is the last commit in gdc-4.7 branch before merging D 2.063.I also tried a later version, but when I tried compiling a program with it, the compile time was 2 times longer and the resulting executable was 30% larger.
Then modify these 3 files according to this pull request - https://github.com/D-Programming-Language/druntime/pull/521/files
libphobos/libdruntime/core/sys/posix/sys/stat.d
libphobos/libdruntime/core/sys/posix/ucontext.d
libphobos/libdruntime/etc/linux/memoryerror.d
After that also modify this file:
libphobos/libdruntime/gcc/deh.d
After these lines:
static if (UNWIND_PAD > 0)
byte[UNWIND_PAD] _pad;
add these lines:
To fix this bug backport the fix from this commit.Change these two files:
gcc/d/d-objfile.cc
gcc/d/dfrontend/expression.c
Only instead of adding these lines:
symtab_add_to_same_comdat_group ((symtab_node) thunk_node,
(symtab_node) funcn);
add this line:
Then unpack gcc 4.7.3 sources and add gdc to them:
To fix this bug apply the fix from this revision.Change the file:
gcc-4.7.3/gcc/config/arm/vfp.md
Next backup the original sources and pack the modified sources:
mv ~/src/gcc-4.7.3.tar.bz2 ~/src/gcc-4.7.3.tar.bz2-orig
cd ~/gdc
tar -hcjf ~/src/gcc-4.7.3.tar.bz2 gcc-4.7.3/
And finally build the crosscompiler:
If everything went allright, the resulting crosscompiler (c, c++, d) will be in this directory: ~/x-tools/arm-cortex_a8-linux-gnueabi
Because of following bug - https://bitbucket.org/goshawk/gdc/issue/120/fsection-anchors-broken-on-arm - you should compile you d programs with the parameter"-fsection-anchors" "-fno-section-anchors".
That's why in the next step recompile libdruntime and libphobos with this parameter.
Go into this directory: ~/toolchain/.build/arm-cortex_a8-linux-gnueabi/build/build-cc-final/arm-cortex_a8-linux-gnueabi/libphobos
In the following files add the parameter to the line that begins with "DFLAGS = ":
Makefile
libdruntime/Makefile
src/Makefile
Recompile the libraries:
cd ~/toolchain/.build/arm-cortex_a8-linux-gnueabi/build/build-cc-final/arm-cortex_a8-linux-gnueabi/libphobos
make clean
make
The recompiled libraries are:~/toolchain/.build/arm-cortex_a8-linux-gnueabi/build/build-cc-final/arm-cortex_a8-linux-gnueabi/libphobos/libdruntime/libgdruntime.a
~/toolchain/.build/arm-cortex_a8-linux-gnueabi/build/build-cc-final/arm-cortex_a8-linux-gnueabi/libphobos/src/libgphobos2.a
Put these files into the directory ~/x-tools/arm-cortex_a8-linux-gnueabi/arm-cortex_a8-linux-gnueabi/sysroot/lib
The directory probably doesn't have permissions for writing, so you'll have to add them.
Backup the original files if you want.
There are some other bugs in the crosscompiler.
I located and reported one of them - http://bugzilla.gdcproject.org/show_bug.cgi?id=72
The following bug is without fix - http://bugzilla.gdcproject.org/show_bug.cgi?id=74
To complete the toolchain, I adapted the script by Ivanovic to use my crosscompiler instead of downloading Sourcery CodeBench Lite.
Except for libraries mentioned in the page, I also needed to install this:
I used information from these pages:
http://forum.dlang.org/thread/ji5lq7$9mt$1@digitalmars.com
https://github.com/D-Programming-GDC/GDC
http://gdcproject.org/wiki/Cross%20Compiler/crosstool-NG
http://www.crosstool-ng.org/
I tested it on Ubuntu 13.04 64-bit Server Edition and on Linux Mint Debian 64-bit Cinnamon Edition.
Tip: read the whole instructions before building it yourself.
First install some required packages:
sudo apt-get install build-essential libtool automake bison flex gperf texinfo gawk ncurses-dev libexpat1-dev python-dev
Then install crosstool-NG, which is used to build the crosscompiler.Since I wanted to use gcc 4.7.3 and the latest release only supports gcc 4.7.2, I used a development version from repositories.
cd
hg clone http://crosstool-ng.org/hg/crosstool-ng
cd crosstool-ng
./bootstrap
./configure --prefix="$HOME/opt"
make
make install
Next prepare and configure the crosscompiler:
Code:
export PATH="${PATH}:${HOME}/opt/bin"
cd
mkdir src
mkdir toolchain
cd toolchain
ct-ng arm-cortex_a8-linux-gnueabi
ct-ng menuconfig
Code:
[*]Try features marked as EXPERIMENTAL
[ ] Render the toolchain read-only
(vfpv3) Use specific FPU
Floating point: (softfp (FPU))
Linux kernel version (3.2.44)
binutils version (2.21.53)
gcc version (4.7.3)
(d) Other languages (EXPERIMENTAL)
[*]Enable LTO
gdb version (7.4.1)
strace version (4.5.20)
PPL version (0.11.2)
CLooG version (0.15.11)
Code:
ct-ng build
First get gdc from repositories:
cd
mkdir -p gdc/dev
git clone https://github.com/D-Programming-GDC/GDC.git gdc/dev
cd gdc/dev
git checkout e63f8a7a5657684c0f2c3d2fd1a9c33eec0208c0
The commit I used is the last commit in gdc-4.7 branch before merging D 2.063.I also tried a later version, but when I tried compiling a program with it, the compile time was 2 times longer and the resulting executable was 30% larger.
Then modify these 3 files according to this pull request - https://github.com/D-Programming-Language/druntime/pull/521/files
libphobos/libdruntime/core/sys/posix/sys/stat.d
libphobos/libdruntime/core/sys/posix/ucontext.d
libphobos/libdruntime/etc/linux/memoryerror.d
After that also modify this file:
libphobos/libdruntime/gcc/deh.d
After these lines:
static if (UNWIND_PAD > 0)
byte[UNWIND_PAD] _pad;
add these lines:
Code:
version (GNU_ARM_EABI_Unwinder)
int pad_;
gcc/d/d-objfile.cc
gcc/d/dfrontend/expression.c
Only instead of adding these lines:
symtab_add_to_same_comdat_group ((symtab_node) thunk_node,
(symtab_node) funcn);
add this line:
Code:
cgraph_add_to_same_comdat_group (thunk_node, funcn);
Code:
cd ~/gdc
tar xjf ~/src/gcc-4.7.3.tar.bz2
cd dev
./update-gcc.sh ../gcc-4.7.3
gcc-4.7.3/gcc/config/arm/vfp.md
Next backup the original sources and pack the modified sources:
mv ~/src/gcc-4.7.3.tar.bz2 ~/src/gcc-4.7.3.tar.bz2-orig
cd ~/gdc
tar -hcjf ~/src/gcc-4.7.3.tar.bz2 gcc-4.7.3/
And finally build the crosscompiler:
Code:
cd ~/toolchain
ct-ng build
Because of following bug - https://bitbucket.org/goshawk/gdc/issue/120/fsection-anchors-broken-on-arm - you should compile you d programs with the parameter
That's why in the next step recompile libdruntime and libphobos with this parameter.
Go into this directory: ~/toolchain/.build/arm-cortex_a8-linux-gnueabi/build/build-cc-final/arm-cortex_a8-linux-gnueabi/libphobos
In the following files add the parameter to the line that begins with "DFLAGS = ":
Makefile
libdruntime/Makefile
src/Makefile
Recompile the libraries:
cd ~/toolchain/.build/arm-cortex_a8-linux-gnueabi/build/build-cc-final/arm-cortex_a8-linux-gnueabi/libphobos
make clean
make
The recompiled libraries are:~/toolchain/.build/arm-cortex_a8-linux-gnueabi/build/build-cc-final/arm-cortex_a8-linux-gnueabi/libphobos/libdruntime/libgdruntime.a
~/toolchain/.build/arm-cortex_a8-linux-gnueabi/build/build-cc-final/arm-cortex_a8-linux-gnueabi/libphobos/src/libgphobos2.a
Put these files into the directory ~/x-tools/arm-cortex_a8-linux-gnueabi/arm-cortex_a8-linux-gnueabi/sysroot/lib
The directory probably doesn't have permissions for writing, so you'll have to add them.
Backup the original files if you want.
There are some other bugs in the crosscompiler.
The following bug is without fix - http://bugzilla.gdcproject.org/show_bug.cgi?id=74
To complete the toolchain, I adapted the script by Ivanovic to use my crosscompiler instead of downloading Sourcery CodeBench Lite.
Except for libraries mentioned in the page, I also needed to install this:
Code:
sudo apt-get install libglib2.0-dev
Last edited by a moderator: