Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
How build a compiler targeting i686-elf or x86_64-elf that is hosted on Windows. Setting up a Linux compiler is simple, but development on Windows is a whimsical idea of mine. Also, I would prefer to not use Cygwin as I find it too bloated. The current compilation settings are as follows:
$ gcc --version
gcc (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
MinGW + MSYS is an option, and as it addresses the native Windows API instead of a POSIX emulation layer, results in a slightly faster toolchain. Some software packages will not build properly under MSYS as they were not designed for use with Windows. As far as this tutorial is concerned, everything that applies to Cygwin also applies to MSYS unless otherwise specified. Make sure you install the C and C++ compilers, and the MSYS Basic System.
Do I just download the source tarballs as prescribed here and use those to compile GCC?
Yes- the important part is the target platform, since MSYS is already capable of building and running GCC in general.
Just FYI, though, your current GCC (x86_64-pc-msys) does not "address the native Windows API instead of a POSIX emulation layer." MSYS is basically a stripped-down Cygwin, and the -msys variants of the toolchain use the same emulation layer in the binaries they output. If you want to bypass that layer in your cross compiler you'll want to build it with a -mingw variant, like x86_64-w64-mingw32 (kind of a confusing triple, neither the w64 nor mingw32 mean 32 or 64 bit- w64 is a fork of mingw that supports 64 bit, and Win32 is still called that in 64 bit mode).
Ah, I grok it now. MinGW GCC is a compiler that targets Windows, but it can be built to run on other platforms. Similarly, GCC has many targets (of interest are i686-elf, x86_64-elf, or even arm-none-eabi) and can be built on platforms that offer the proper environment to run it.
Thank you.
Also, MSYS2 offers better options for portability as I am not always on my main computer.
To be clear about the Cygwin/MSYS2/MinGW thing though, the -mingw targets are available from MSYS2's package manager as well. It has toolchains that target both the Cygwin-fork compatibility layer and that target plain Win32 (but still using the Itanium ABI).
On a related note, does the assembler target matter? Or would the vanilla NASM build work? The way I learned it was the build process was (simplified) as follows:
GCC uses its own assembler and the target there is taken care of alongside the compiler's when you build a cross toolchain. NASM just needs to give you object files that your cross linker understands, which probably means ELF. Vanilla NASM can do that- it helps that it doesn't need to worry about calling conventions like the compiler does.
Another option would be to use GCC's assembler, gas. It defaults to AT&T syntax and some things are done a bit differently than NASM, but it's guaranteed to work with your cross compiler no matter what architecture you target and it's one less build dependency. Overall it's not a terrible idea- Linux uses it, for example.
So deleted and reextracted my gcc folder, ran pacman -S {gmp,mpfr,mpc}-devel to ensure that I had those, and tried compiling gcc. It compiles for a few minutes and then complains.
[ -f stage_final ] || echo stage3 > stage_final
make[1]: Entering directory '/home/Harley/src/build-gcc'
make[2]: Entering directory '/home/Harley/src/build-gcc'
make[3]: Entering directory '/home/Harley/src/build-gcc'
rm -f stage_current
make[3]: Leaving directory '/home/Harley/src/build-gcc'
make[2]: Leaving directory '/home/Harley/src/build-gcc'
make[2]: Entering directory '/home/Harley/src/build-gcc'
make[3]: Entering directory '/home/Harley/src/build-gcc/libiberty'
make[4]: Entering directory '/home/Harley/src/build-gcc/libiberty/testsuite'
make[4]: Nothing to be done for 'all'.
make[4]: Leaving directory '/home/Harley/src/build-gcc/libiberty/testsuite'
make[3]: Leaving directory '/home/Harley/src/build-gcc/libiberty'
make[3]: Entering directory '/home/Harley/src/build-gcc/lto-plugin'
make all-am
make[4]: Entering directory '/home/Harley/src/build-gcc/lto-plugin'
make[4]: Leaving directory '/home/Harley/src/build-gcc/lto-plugin'
make[3]: Leaving directory '/home/Harley/src/build-gcc/lto-plugin'
Configuring stage 1 in ./gcc
configure: loading cache ./config.cache
checking build system type... x86_64-pc-msys
checking host system type... x86_64-pc-msys
checking target system type... x86_64-pc-msys
checking LIBRARY_PATH variable... ok
checking GCC_EXEC_PREFIX variable... ok
checking whether to place generated files in the source directory... no
checking whether a default linker was specified... no
checking whether a default assembler was specified... no
checking for x86_64-pc-msys-gcc... gcc
checking for C compiler default output file name... a.exe
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... .exe
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for x86_64-pc-msys-gnatbind... no
checking for x86_64-pc-msys-gnatmake... no
checking whether compiler driver understands Ada... no
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking how to run the C preprocessor... gcc -E
checking for inline... inline
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking size of void *... 8
checking size of short... 2
checking size of int... 4
checking size of long... 8
checking for long long... yes
checking size of long long... 8
checking for int8_t... yes
checking for int16_t... yes
checking for int32_t... yes
checking for int64_t... yes
checking for long long int... yes
checking for intmax_t... yes
checking for intptr_t... yes
checking for uint8_t... yes
checking for uint16_t... yes
checking for uint32_t... yes
checking for uint64_t... yes
checking for unsigned long long int... yes
checking for uintmax_t... yes
checking for uintptr_t... yes
checking for int64_t underlying type... long
checking whether gcc supports -W... yes
checking whether gcc supports -Wall... yes
checking whether gcc supports -Wnarrowing... yes
checking whether gcc supports -Wwrite-strings... yes
checking whether gcc supports -Wcast-qual... yes
checking whether gcc supports -Wformat... yes
checking whether gcc supports -Wstrict-prototypes... yes
checking whether gcc supports -Wmissing-prototypes... yes
checking whether gcc supports -Wmissing-format-attribute... yes
checking whether gcc supports -Woverloaded-virtual... yes
checking whether gcc supports -Wold-style-definition... yes
checking whether gcc supports -Wc++-compat... yes
checking whether gcc supports -pedantic -Wlong-long -Wvariadic-macros -Woverlength-strings... yes
checking whether gcc supports -fno-exceptions... yes
checking whether gcc supports -fno-rtti... yes
checking whether gcc supports -fasynchronous-unwind-tables... yes
checking valgrind.h usability... no
checking valgrind.h presence... no
checking for valgrind.h... no
checking for VALGRIND_DISCARD in <valgrind/memcheck.h>... no
checking for VALGRIND_DISCARD in <memcheck.h>... no
checking for multiarch configuration... auto
checking whether make sets $(MAKE)... yes
checking for gawk... gawk
checking whether ln -s works... yes
checking whether ln works... yes
checking for x86_64-pc-msys-ranlib... ranlib
checking for a BSD compatible install... /usr/bin/install -c
checking for cmp's capabilities... slowcompare
checking for mktemp... yes
checking for makeinfo... makeinfo --split-size=5000000 --split-size=5000000
checking for modern makeinfo... yes
checking for recent Pod::Man... yes
checking for flex... flex
checking for bison... bison
checking for nm... nm
checking for ar... ar
checking for sphinx-build... texinfo
checking for ANSI C header files... (cached) yes
checking whether time.h and sys/time.h may both be included... yes
checking whether string.h and strings.h may both be included... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking whether termios.h defines TIOCGWINSZ... yes
checking for limits.h... yes
checking for stddef.h... yes
checking for string.h... (cached) yes
checking for strings.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for time.h... yes
checking for iconv.h... yes
checking for fcntl.h... yes
checking for ftw.h... yes
checking for unistd.h... (cached) yes
checking for sys/file.h... yes
checking for sys/time.h... yes
checking for sys/mman.h... yes
checking for sys/resource.h... yes
checking for sys/param.h... yes
checking for sys/times.h... yes
checking for sys/stat.h... (cached) yes
checking for direct.h... no
checking for malloc.h... yes
checking for langinfo.h... yes
checking for ldfcn.h... no
checking for locale.h... yes
checking for wchar.h... yes
checking for thread.h... no
checking for pthread.h... yes
checking for CHAR_BIT... yes
checking whether byte ordering is bigendian... no
checking how to run the C++ preprocessor... g++ -E
checking for unordered_map... no
checking for tr1/unordered_map... yes
checking for ext/hash_map... yes
checking dependency style of g++... gcc3
checking for collect2 libraries... none required
checking for library containing exc_resume... no
checking for library containing kstat_open... no
checking for library containing ldexp... none required
checking for inttypes.h... yes
checking for times... yes
checking for clock... yes
checking for kill... yes
checking for getrlimit... yes
checking for setrlimit... yes
checking for atoll... yes
checking for atoq... no
checking for popen... yes
checking for sysconf... yes
checking for strsignal... yes
checking for getrusage... yes
checking for nl_langinfo... yes
checking for gettimeofday... yes
checking for mbstowcs... yes
checking for wcswidth... yes
checking for mmap... yes
checking for setlocale... yes
checking for clearerr_unlocked... yes
checking for feof_unlocked... yes
checking for ferror_unlocked... yes
checking for fflush_unlocked... yes
checking for fgetc_unlocked... yes
checking for fgets_unlocked... yes
checking for fileno_unlocked... yes
checking for fprintf_unlocked... no
checking for fputc_unlocked... yes
checking for fputs_unlocked... yes
checking for fread_unlocked... yes
checking for fwrite_unlocked... yes
checking for getchar_unlocked... yes
checking for getc_unlocked... yes
checking for putchar_unlocked... yes
checking for putc_unlocked... yes
checking for madvise... yes
checking whether mbstowcs works... yes
checking for ssize_t... yes
checking for caddr_t... yes
checking for sys/mman.h... (cached) yes
checking for mmap... (cached) yes
checking whether read-only mmap of a plain file works... yes
checking whether mmap from /dev/zero works... yes
checking for MAP_ANON(YMOUS)... yes
checking whether mmap with MAP_ANON(YMOUS) works... yes
checking for pid_t... yes
checking for vfork.h... no
checking for fork... yes
checking for vfork... yes
checking for working fork... yes
checking for working vfork... (cached) yes
checking for ld used by GCC... /usr/lib/gcc/x86_64-pc-msys/4.9.2/../../../../x86_64-pc-msys/bin/ld.exe
checking if the linker (/usr/lib/gcc/x86_64-pc-msys/4.9.2/../../../../x86_64-pc-msys/bin/ld.exe) is GNU ld... yes
checking for shared library run path origin... done
checking for iconv... yes
checking how to link with libiconv... -liconv
checking for iconv declaration... install-shextern size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
checking for LC_MESSAGES... yes
checking for nl_langinfo and CODESET... yes
checking whether getenv is declared... yes
checking whether atol is declared... yes
checking whether asprintf is declared... yes
checking whether sbrk is declared... yes
checking whether abort is declared... yes
checking whether atof is declared... yes
checking whether getcwd is declared... yes
checking whether getwd is declared... yes
checking whether stpcpy is declared... yes
checking whether strnlen is declared... yes
checking whether strsignal is declared... yes
checking whether strstr is declared... yes
checking whether strverscmp is declared... no
checking whether strtol is declared... yes
checking whether strtoul is declared... yes
checking whether strtoll is declared... yes
checking whether strtoull is declared... yes
checking whether errno is declared... yes
checking whether snprintf is declared... yes
checking whether vsnprintf is declared... yes
checking whether vasprintf is declared... yes
checking whether malloc is declared... yes
checking whether realloc is declared... yes
checking whether calloc is declared... yes
checking whether free is declared... yes
checking whether basename is declared... yes
checking whether getopt is declared... no
checking whether clock is declared... yes
checking whether getpagesize is declared... yes
checking whether ffs is declared... yes
checking whether clearerr_unlocked is declared... yes
checking whether feof_unlocked is declared... yes
checking whether ferror_unlocked is declared... yes
checking whether fflush_unlocked is declared... yes
checking whether fgetc_unlocked is declared... yes
checking whether fgets_unlocked is declared... yes
checking whether fileno_unlocked is declared... yes
checking whether fprintf_unlocked is declared... no
checking whether fputc_unlocked is declared... yes
checking whether fputs_unlocked is declared... yes
checking whether fread_unlocked is declared... yes
checking whether fwrite_unlocked is declared... yes
checking whether getchar_unlocked is declared... yes
checking whether getc_unlocked is declared... yes
checking whether putchar_unlocked is declared... yes
checking whether putc_unlocked is declared... yes
checking whether getrlimit is declared... yes
checking whether setrlimit is declared... yes
checking whether getrusage is declared... yes
checking whether ldgetname is declared... no
checking whether times is declared... yes
checking whether sigaltstack is declared... yes
checking whether madvise is declared... yes
checking for struct tms... yes
checking for clock_t... yes
checking for F_SETLKW... yes
checking if mkdir takes one argument... no
Makefile:4154: recipe for target 'configure-stage1-gcc' failed
make[2]: Leaving directory '/home/Harley/src/build-gcc'
Makefile:17846: recipe for target 'stage1-bubble' failed
make[1]: Leaving directory '/home/Harley/src/build-gcc'
Makefile:895: recipe for target 'all' failed
WARNING: liblto_plugin.la is static, not copying to ../gcc/liblto_plugin.la
configure: WARNING: decimal float is not supported for this target, ignored
configure: WARNING: fixed-point is not supported for this target, ignored
*** Configuration x86_64-pc-msys not supported
make[2]: *** [configure-stage1-gcc] Error 1
make[1]: *** [stage1-bubble] Error 2
make: *** [all] Error 2