April 27, 2015
Am Mon, 27 Apr 2015 07:56:02 +0200
schrieb Iain Buclaw via Digitalmars-d <digitalmars-d@puremagic.com>:

> On 26 April 2015 at 22:41, Jens Bauer via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> > On Sunday, 26 April 2015 at 18:23:47 UTC, Martin Nowak wrote:
> >>
> >> On 04/26/2015 07:29 PM, Jens Bauer wrote:
> >>>
> >>> Unfortunately, I have not been able to build with multilib yet, so my setup cannot build code for Cortex-M0; it keeps stuffing Cortex-M3 and Cortex-M4 instructions in there.
> >>
> >>
> >> The wiki says to disable multilib
> >>
> >> (http://wiki.dlang.org/Bare_Metal_ARM_Cortex-M_GDC_Cross_Compiler#Build_GCC),
> >> what's the problem?
> >
> >
> > The problem is that I cannot have a single compiler, which compiles
> > for these architectures:
> > ARM7TDMI
> > Cortex-M0
> > Cortex-M3
> > Cortex-M4
> >
> > Using a Cortex-M3 or Cortex-M4 compiler to build code for a Cortex-M0, will insert 32-bit instructions randomly (most code is 16-bit, though, so parts of it gets it right). As soon as the microcontroller tries to run a 32-bit instruction, it will crash.
> >
> > -In order to build code for Cortex-M0 or Cortex-M0+, I will have to
> > rebuild the compiler.
> > The alternative is to build 5 different compilers. I don't want
> > that either.
> >
> > ...
> >
> > The reason I cannot build GDC with multilib, is that I get a
> > compile-error when building the final GCC+GDC.
> > Building GCC alone without GDC gives me no such error.
> > -So if I want to have multilib support, I will have to be without
> > GDC.
> 
> Where exactly does it error?
> 
> I can't think of a sole reason why gdc/libphobos would throw an error in multilib builds, so it must be something collateral (libstdc++) ?
> 
> Regards
> Iain.

It might be libbacktrace related. I saw errors building AVR32 multilibs caused by libbacktrace: We pull in libbacktrace even if druntime/phobos are disabled with --disable-libphobos.


Possible fix: gcc/d/config-lang.in

 compilers="cc1d\$(exeext)"

-target_libs="target-libphobos target-zlib target-libbacktrace"
+if eval test x\${enable_libphobos} "=" xno ; then
+    target_libs=""
+else
+    target_libs="target-libphobos target-zlib target-libbacktrace"
+fi

 # The D frontend is written in C++, so we need to build the C++
 # compiler during stage 1.
April 27, 2015
Am Mon, 27 Apr 2015 07:55:09 +0000
schrieb "Martin Nowak" <code@dawg.eu>:

> On Monday, 27 April 2015 at 05:30:55 UTC, Timo Sintonen wrote:
> > One of the biggest issues has been the multilib build. If it is solved now we are one step closer to be able to build binaries.
> 
> Great, I tried to find out how GDC binaries are build, but couldn't find any script.

Since 2.066 the binaries on gdcproject.org are built with crosstool-NG (and an additional D script) in a docker container. I wanted to publish this some time ago but I still need to write the documentation and right now I'm kinda busy with other stuff...
April 27, 2015
On 27 April 2015 at 19:25, Johannes Pfau via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> Am Mon, 27 Apr 2015 07:55:09 +0000
> schrieb "Martin Nowak" <code@dawg.eu>:
>
>> On Monday, 27 April 2015 at 05:30:55 UTC, Timo Sintonen wrote:
>> > One of the biggest issues has been the multilib build. If it is solved now we are one step closer to be able to build binaries.
>>
>> Great, I tried to find out how GDC binaries are build, but couldn't find any script.
>
> Since 2.066 the binaries on gdcproject.org are built with crosstool-NG (and an additional D script) in a docker container. I wanted to publish this some time ago but I still need to write the documentation and right now I'm kinda busy with other stuff...

Which reminds me, I've dabbled with docker, but again, there are too many things for one person to busy oneself with...

https://registry.hub.docker.com/u/ibuclaw/gdc/

I'd like to get back to gdb support, but people keep on pushing out releases at the wrong time. :-P

Iain
April 27, 2015
On Monday, 27 April 2015 at 13:16:10 UTC, Iain Buclaw wrote:
> On 27 April 2015 at 15:05, Jens Bauer via Digitalmars-d
{snip}
>> As you see, config.h, libstdc++ and multilib are all present in this chunk.
>
> Try building with --disable-libstdcxx as in the suggestion from Timo.

Unfortunately, it still fails:
---8<-----8<-----8<-----

config.status: creating Makefile
config.status: creating scripts/testsuite_flags
config.status: creating scripts/extract_symvers
config.status: creating doc/xsl/customization.xsl
config.status: creating include/Makefile
Adding multilib support to include/Makefile in /Users/jens/toolchain/Source/gcc/libstdc++-v3
with_multisubdir=thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16
config.status: creating libsupc++/Makefile
Adding multilib support to libsupc++/Makefile in /Users/jens/toolchain/Source/gcc/libstdc++-v3
with_multisubdir=thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16
config.status: creating python/Makefile
Adding multilib support to python/Makefile in /Users/jens/toolchain/Source/gcc/libstdc++-v3
with_multisubdir=thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16
config.status: creating src/Makefile
Adding multilib support to src/Makefile in /Users/jens/toolchain/Source/gcc/libstdc++-v3
with_multisubdir=thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16
config.status: creating src/c++98/Makefile
Adding multilib support to src/c++98/Makefile in /Users/jens/toolchain/Source/gcc/libstdc++-v3
with_multisubdir=thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16
config.status: creating src/c++11/Makefile
Adding multilib support to src/c++11/Makefile in /Users/jens/toolchain/Source/gcc/libstdc++-v3
with_multisubdir=thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16
config.status: creating doc/Makefile
Adding multilib support to doc/Makefile in /Users/jens/toolchain/Source/gcc/libstdc++-v3
with_multisubdir=thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16
config.status: creating po/Makefile
Adding multilib support to po/Makefile in /Users/jens/toolchain/Source/gcc/libstdc++-v3
with_multisubdir=thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16
config.status: creating testsuite/Makefile
Adding multilib support to testsuite/Makefile in /Users/jens/toolchain/Source/gcc/libstdc++-v3
with_multisubdir=thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16
config.status: creating config.h
config.status: executing default-1 commands
Adding multilib support to Makefile in /Users/jens/toolchain/Source/gcc/libstdc++-v3
with_multisubdir=thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16
config.status: executing libtool commands
config.status: executing include/gstdint.h commands
config.status: executing generate-headers commands
echo timestamp > stamp-pb
echo timestamp > stamp-host
echo 0 > stamp-namespace-version
echo 1 > stamp-visibility
echo 1 > stamp-extern-template
sed -e '/^#pragma/b' \
	    -e '/^#/s/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_][ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*\)/_GLIBCXX_\1/g' \
	    -e 's/_GLIBCXX_SUPPORTS_WEAK/__GXX_WEAK__/g' \
	    -e 's/_GLIBCXX___MINGW32_GLIBCXX___/__MINGW32__/g' \
	    -e 's,^#include "\(.*\)",#include <bits/\1>,g' \
	    < /Users/jens/toolchain/Source/gcc/libstdc++-v3/../libgcc/gthr.h > arm-none-eabi/bits/gthr.h
sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
	    -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCXX_\1/g' \
	    < /Users/jens/toolchain/Source/gcc/libstdc++-v3/../libgcc/gthr-single.h > arm-none-eabi/bits/gthr-single.h
sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
	    -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCXX_\1/g' \
	    -e 's/SUPPORTS_WEAK/__GXX_WEAK__/g' \
	    -e 's/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*USE_WEAK\)/_GLIBCXX_\1/g' \
	    < /Users/jens/toolchain/Source/gcc/libstdc++-v3/../libgcc/gthr-posix.h > arm-none-eabi/bits/gthr-posix.h
sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
	    -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCXX_\1/g' \
	    -e 's/SUPPORTS_WEAK/__GXX_WEAK__/g' \
	    -e 's/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*USE_WEAK\)/_GLIBCXX_\1/g' \
	    -e 's,^#include "\(.*\)",#include <bits/\1>,g' \
	    < /Users/jens/toolchain/Source/gcc/libstdc++-v3/../libgcc/gthr-single.h > arm-none-eabi/bits/gthr-default.h
config.status: executing libtool commands
config.status: executing include/gstdint.h commands
config.status: executing generate-headers commands
echo timestamp > stamp-pb
echo timestamp > stamp-host
echo 0 > stamp-namespace-version
echo 1 > stamp-visibility
echo 1 > stamp-extern-template
sed -e '/^#pragma/b' \
	    -e '/^#/s/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_][ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*\)/_GLIBCXX_\1/g' \
	    -e 's/_GLIBCXX_SUPPORTS_WEAK/__GXX_WEAK__/g' \
	    -e 's/_GLIBCXX___MINGW32_GLIBCXX___/__MINGW32__/g' \
	    -e 's,^#include "\(.*\)",#include <bits/\1>,g' \
	    < /Users/jens/toolchain/Source/gcc/libstdc++-v3/../libgcc/gthr.h > arm-none-eabi/bits/gthr.h
sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
	    -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCXX_\1/g' \
	    < /Users/jens/toolchain/Source/gcc/libstdc++-v3/../libgcc/gthr-single.h > arm-none-eabi/bits/gthr-single.h
sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
	    -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCXX_\1/g' \
	    -e 's/SUPPORTS_WEAK/__GXX_WEAK__/g' \
	    -e 's/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*USE_WEAK\)/_GLIBCXX_\1/g' \
	    < /Users/jens/toolchain/Source/gcc/libstdc++-v3/../libgcc/gthr-posix.h > arm-none-eabi/bits/gthr-posix.h
sed -e 's/\(UNUSED\)/_GLIBCXX_\1/g' \
	    -e 's/\(GCC[ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*_H\)/_GLIBCXX_\1/g' \
	    -e 's/SUPPORTS_WEAK/__GXX_WEAK__/g' \
	    -e 's/\([ABCDEFGHIJKLMNOPQRSTUVWXYZ_]*USE_WEAK\)/_GLIBCXX_\1/g' \
	    -e 's,^#include "\(.*\)",#include <bits/\1>,g' \
	    < /Users/jens/toolchain/Source/gcc/libstdc++-v3/../libgcc/gthr-single.h > arm-none-eabi/bits/gthr-default.h
make: *** [all] Error 2
--->8----->8----->8-----
(Sorry for the delay, I ran the wrong build-script at first - building GCC twice takes approximately 100 minutes)
April 28, 2015
On Monday, 27 April 2015 at 05:19:52 UTC, Timo Sintonen wrote:

>
> I have also tried for years to build a working multilib without success. Now I think I have been able to get all versions to work. I welcome everyone to test and report if this works.
>
> The build script:
> ../gcc/configure --disable-bootstrap \
> --enable-languages=c,d  --disable-nls --target=arm-eabi \
> --without-headers  --with-newlib --without-isl --without-cloog \
> --disable-libphobos --disable-libstdcxx --disable-libbacktrace\
> --enable-multilib
>
> And I replace the whole gcc/config/arm/t-arm-elf with this:
> MULTILIB_OPTIONS  += mcpu=cortex-m0/mcpu=cortex-m3/mcpu=cortex-m4
>  mfloat-abi=hard mfpu=fpv4-sp-d16
> MULTILIB_DIRNAMES += cortex-m0 cortex-m3 cortex-m4
> MULTILIB_REQUIRED += mcpu=cortex-m0
> MULTILIB_REQUIRED += mcpu=cortex-m3
> MULTILIB_REQUIRED += mcpu=cortex-m4 #/mfloat-abi=hard  #/mfpu=fpv4-sp-d16
> MULTILIB_EXTRA_OPTS += mthumb
>
>
> This will build m0 and m3 with soft float and m4 with hard float. I have used gdc head + gcc 6 head from about a week ago. It may be possible this will work with gcc 5.1 release + gdc 5  and I hope somebody will test this.
>
> Please note: This is the first time ever I have suceeded. This will not work with any gcc before april. An older gcc will not build m4 or it may even not pass configuring.
>

Given the other replies in this thread, this looks promising.  However, I went to give it a test today, and found out my host PC's distribution (Arch Linux) hasn't yet released GCC 5.1; it's still in testing.

So, I'm going to refrain from testing until the Arch Linux package gets officially released.  My current builds don't use startup files, libgcc, or any of the other toolchain libs, and I only using Cortex-M4F cores, so I'm not sure if my tests will prove much of anything, other than successful compilation.

Nevertheless, when GCC 5.1 is official released for my distribution, I'll give it a test (if it's not too late by then).

If you suspect it might work for GCC 4.9.2, I'll give it a try.

Mike
April 28, 2015
On Monday, 27 April 2015 at 05:19:52 UTC, Timo Sintonen wrote:
> The build script:
> ../gcc/configure --disable-bootstrap \
> --enable-languages=c,d  --disable-nls --target=arm-eabi \
> --without-headers  --with-newlib --without-isl --without-cloog \
> --disable-libphobos --disable-libstdcxx --disable-libbacktrace\
> --enable-multilib

You probably didn't mean to have the backslash right next to --disable-libbacktrace.
This results in the following switch:

--disable-libbacktrace--enable-multilib

... which makes it build alright. (multilib is enabled by default).
If adding a space before --enable-multilib, then I get a build error; a part of cc1 seem to require libbacktrace.

Thus I believe removing --disable-libbacktrace would be OK to do.

I'm still in the process of building/modifying, so it'll take a while before I report my best results.
So far, it looks like GCC-4.9.2 can be built with multilib if using --disable-bootstrap.
April 28, 2015
On Tuesday, 28 April 2015 at 00:34:42 UTC, Mike wrote:
>
> Given the other replies in this thread, this looks promising.  However, I went to give it a test today, and found out my host PC's distribution (Arch Linux) hasn't yet released GCC 5.1; it's still in testing.

You don't have to wait for an Arch Linux release of GCC 5.1, because you're going to build it yourself anyway, right ?
-It can be downloaded from ftp.gnu.org/gnu/gcc/gcc-5.1.0/gcc-5.1.0.tar.bz2

> If you suspect it might work for GCC 4.9.2, I'll give it a try.

I'm currently experimenting with building on 4.9.2; I expect to have a good build later today.
April 28, 2015
On Tuesday, 28 April 2015 at 02:12:11 UTC, Jens Bauer wrote:
> On Tuesday, 28 April 2015 at 00:34:42 UTC, Mike wrote:
>>
>> Given the other replies in this thread, this looks promising.  However, I went to give it a test today, and found out my host PC's distribution (Arch Linux) hasn't yet released GCC 5.1; it's still in testing.
>
> You don't have to wait for an Arch Linux release of GCC 5.1, because you're going to build it yourself anyway, right ?
> -It can be downloaded from ftp.gnu.org/gnu/gcc/gcc-5.1.0/gcc-5.1.0.tar.bz2

I always thought we needed to build our cross-compilers with the same version as the host in order to have confidence in the build.  Correct me if I'm wrong.

Mike

April 28, 2015
On Tuesday, 28 April 2015 at 00:34:42 UTC, Mike wrote:

>> The build script:
>> ../gcc/configure --disable-bootstrap \
>> --enable-languages=c,d  --disable-nls --target=arm-eabi \
>> --without-headers  --with-newlib --without-isl --without-cloog \
>> --disable-libphobos --disable-libstdcxx --disable-libbacktrace\
>> --enable-multilib
>>
>> And I replace the whole gcc/config/arm/t-arm-elf with this:
>> MULTILIB_OPTIONS  += mcpu=cortex-m0/mcpu=cortex-m3/mcpu=cortex-m4
>> mfloat-abi=hard mfpu=fpv4-sp-d16
>> MULTILIB_DIRNAMES += cortex-m0 cortex-m3 cortex-m4
>> MULTILIB_REQUIRED += mcpu=cortex-m0
>> MULTILIB_REQUIRED += mcpu=cortex-m3
>> MULTILIB_REQUIRED += mcpu=cortex-m4 #/mfloat-abi=hard  #/mfpu=fpv4-sp-d16
>> MULTILIB_EXTRA_OPTS += mthumb
>>
[...]
>
> If you suspect it might work for GCC 4.9.2, I'll give it a try.

I tested this script generating an arm-none-eabil 4.9.2 cross-compiler with a 4.9.2 host.  My build script is here:  https://github.com/JinShil/arm-none-eabi-gdc

The lib dir looks like this:
lib
└── gcc
    └── arm-none-eabi
        └── 4.9.2
            ├── cortex-m0
            ├── cortex-m3
            ├── cortex-m4
            ├── include
            ├── include-fixed
            ├── install-tools
            │   └── include
            └── plugin
                └── include
                    ├── ada
                    │   └── gcc-interface
                    ├── c-family
                    ├── config
                    │   └── arm
                    ├── cp
                    ├── d
                    ├── java
                    └── objc

The "cortex-m{x}" folder have the following files:
crtbegin.o  crtend.o  crti.o  crtn.o  libgcc.a  libgcov.a

I haven't tried to compile anything yet though.  Again, none of my software uses these binaries.

Mike

April 28, 2015
On Tuesday, 28 April 2015 at 02:18:29 UTC, Mike wrote:
> On Tuesday, 28 April 2015 at 02:12:11 UTC, Jens Bauer wrote:
>> On Tuesday, 28 April 2015 at 00:34:42 UTC, Mike wrote:
>>>
>>> Given the other replies in this thread, this looks promising.
>>>  However, I went to give it a test today, and found out my host PC's distribution (Arch Linux) hasn't yet released GCC 5.1; it's still in testing.
>>
>> You don't have to wait for an Arch Linux release of GCC 5.1, because you're going to build it yourself anyway, right ?
>> -It can be downloaded from ftp.gnu.org/gnu/gcc/gcc-5.1.0/gcc-5.1.0.tar.bz2
>
> I always thought we needed to build our cross-compilers with the same version as the host in order to have confidence in the build.  Correct me if I'm wrong.
>
> Mike

It has always been recommended that the gcc used should be as close as possible to the gcc being compiled. This was very important in gcc 2.8 time. 2.7 could not compile anything after 2.8. I think they are more stable now and the previous release may always be used to compile the last release.

It is important that we first test with the original sources. Packages may have modified them which may cause issues. It is also important that the system is totally clean from previous installation. I have tried to build in a vm but it has always failed with something like 32/64 bit issue in system headers.

I will put a sample build script in gdc list.