Page 1 of 2

Cross compiler step one`

Posted: Tue Jan 31, 2017 1:58 pm
by billcu
I am still a little confused on what gcc or binutils compilation options to build for the i686-elf target. I have 6.3 gcc and 2.27 binutils and I think they're the latest. I am in a linux x64 enviornment but bare bones wants i686-elf. I am considering,

--enable-multilib, i686-elf --disable-nls --without-headers

Now do I need -ffreestanding ?

I am not sure what that's for.

Re: Cross compiler step one`

Posted: Tue Jan 31, 2017 3:02 pm
by nielsd
If you are building a crosscompiler for your kernel, you are not providing a standard C library and you are also not providing include headers (as you can see in your configure command). So you don't need to provide -ffreestanding.

Re: Cross compiler step one`

Posted: Tue Jan 31, 2017 3:10 pm
by billcu
ndke wrote:If you are building a crosscompiler for your kernel, you are not providing a standard C library and you are also not providing include headers (as you can see in your configure command). So you don't need to provide -ffreestanding.
Ok so not providing the C library is what I want to do. What about this libgcc library. It's not a standard C library but you don't want it for kernel creation either do you?

Re: Cross compiler step one`

Posted: Tue Jan 31, 2017 3:12 pm
by dchapiesky
x86_64 kernel - don't forget

Code: Select all

 -mno-red-zone 
libgcc multilib --- http://wiki.osdev.org/Libgcc_without_red_zone

libgcc is almost required for kernel depending on what code you write... http://wiki.osdev.org/Libgcc

In my case, it was preferable to go the full distance for a full cross compiler with sysroot

http://wiki.osdev.org/OS_Specific_Toolchain

It worth learning the options for configuring binutils and gcc

Re: Cross compiler step one`

Posted: Tue Jan 31, 2017 3:24 pm
by billcu
dchapiesky wrote:x86_64 kernel - don't forget

Code: Select all

 -mno-red-zone 
libgcc multilib --- http://wiki.osdev.org/Libgcc_without_red_zone

libgcc is almost required for kernel depending on what code you write... http://wiki.osdev.org/Libgcc

In my case, it was preferable to go the full distance for a full cross compiler with sysroot

http://wiki.osdev.org/OS_Specific_Toolchain

It worth learning the options for configuring binutils and gcc
What do you mean "x86_64 kernel..." That is my host environment yeah but I want to build a 32 bit kernel for a 32 bit OS.

Re: Cross compiler step one`

Posted: Tue Jan 31, 2017 3:31 pm
by dchapiesky
sorry - missed i686 -- but still full os specific compiler is worth it

Re: Cross compiler step one`

Posted: Tue Jan 31, 2017 10:27 pm
by FallenAvatar
Are you building a cross compiler to build your kernel? In which case see http://wiki.osdev.org/GCC_Cross-Compiler
If you are trying to build (on your host platform) a compiler that will compile programs to run on your OS, see http://wiki.osdev.org/OS_Specific_Toolchain

- Monk

Re: Cross compiler step one`

Posted: Thu Feb 02, 2017 2:55 pm
by ~
I made a video that shows how to compile a cross compiler for your custom OS kernel step by step.

If you watch it and repeat everything you see done to make the compile, or if you watch it and then repeat, then you will be able to understand how to build your cross compiler:

OSDev.org Tutorial: Build an i686-elf Cross Compiler under 64-bit Ubuntu Desktop 16.04.1

Re: Cross compiler step one`

Posted: Thu Feb 02, 2017 3:57 pm
by dchapiesky
~ wrote:I made a video that shows how to compile a cross compiler for your custom OS kernel step by step.

4 hours 51 minutes... sounds about right... will let play while I work.... can we get a transcript :wink:

either way your effort is acknowledged and appreciated.... =D>

Now start work on x86_64, arm, ppc, sparc, and z80....

Re: Cross compiler step one`

Posted: Mon Feb 06, 2017 2:23 am
by Solar
~ wrote:I made a video...
...of written and annotated instructions, where people get explanations of every twist and turn involved in the process, and turned it into a five-hour video of "watch the compiler output"?

Unedited?

#-o

Re: Cross compiler step one`

Posted: Mon Feb 06, 2017 4:22 am
by dozniak
Solar wrote:and turned it into a five-hour video of "watch the compiler output"?
Well, it's probably too slow machine; usually compiling full gnu toolchain fits into 1 hour, compiling LLVM into 1 hour and then some.

Re: Cross compiler step one`

Posted: Mon Feb 06, 2017 7:54 am
by dchapiesky
3.2ghz 2 core I3 with hyperthreading does a gcc 6.3 bootstrap compiler/cross compiler/newlib/cross compiler w/sysroot in 25 minutes....

Re: Cross compiler step one`

Posted: Mon Feb 06, 2017 10:16 am
by matt11235
dchapiesky wrote:3.2ghz 2 core I3 with hyperthreading does a gcc 6.3 bootstrap compiler/cross compiler/newlib/cross compiler w/sysroot in 25 minutes....
I'm sure it should be faster than that? Are you passing j4 or j5 to make?

Re: Cross compiler step one`

Posted: Mon Feb 06, 2017 11:37 am
by billcu
Well the makefile broke on me. I am using gcc-6.0.3. I build with my compiler this "isl" library, gmp, mpc, mpfr that gcc needs. The binaries I put together in a directory called 'build'. With the compiler it said no linking allowed after GCC_NO_EXECUTABLES so what's that mean. Is there a linker switch somewhere that needs turned off? I compiled with the 'configure' script these options,

--with-gmp=
--with-isl=
--with=mpc=
--with-mpfr=

To tell the compiler where they are. I also used,

--enable-languages=c --enable-multilib --without-headers --prefix=/mnt --disable-nls i686-elf

What have I left out or do I need?

Re: Cross compiler step one`

Posted: Mon Feb 06, 2017 11:59 am
by Schol-R-LEA
Let's dig a bit deeper here. Please start by telling us the development host environment - you have mentioned that it is an x86-64 CPU, but not the OS it is running under. If you could also post (or link to a repo of) the makefile and linker script, that would help as well.

Mind you, I mean the makefile and linker script for the cross-compiler build, not the one you would use for building the OS image from the cross-compiler. I have this suspicion that there is a bit of confusion there, in that it sounds as if your makefile is set to build an ELF32 file for the cross-compiler, which would not be the correct course of action if it is hosted on a 64-bit OS (and especially so if it is a host OS that doesn't use ELF as its executable format, such as Windows or MacOS). The cross-compiler might be set to target a 32-bit ELF, but the cross-compiler itself would run in the native executable format and bit width of the development host.