Cross compiler step one`

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
billcu
Posts: 17
Joined: Tue Aug 26, 2014 9:12 pm

Cross compiler step one`

Post 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.
User avatar
nielsd
Member
Member
Posts: 31
Joined: Sun Apr 05, 2015 3:15 pm

Re: Cross compiler step one`

Post 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.
osdev project, goal is to run wasm as userspace: https://github.com/kwast-os/kwast
billcu
Posts: 17
Joined: Tue Aug 26, 2014 9:12 pm

Re: Cross compiler step one`

Post 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?
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: Cross compiler step one`

Post 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
Plagiarize. Plagiarize. Let not one line escape thine eyes...
billcu
Posts: 17
Joined: Tue Aug 26, 2014 9:12 pm

Re: Cross compiler step one`

Post 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.
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: Cross compiler step one`

Post by dchapiesky »

sorry - missed i686 -- but still full os specific compiler is worth it
Plagiarize. Plagiarize. Let not one line escape thine eyes...
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

Re: Cross compiler step one`

Post 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
User avatar
~
Member
Member
Posts: 1227
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Cross compiler step one`

Post 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
YouTube:
http://youtube.com/@AltComp126

My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... ip?viasf=1
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: Cross compiler step one`

Post 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....
Plagiarize. Plagiarize. Let not one line escape thine eyes...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Cross compiler step one`

Post 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
Every good solution is obvious once you've found it.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Cross compiler step one`

Post 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.
Learn to read.
User avatar
dchapiesky
Member
Member
Posts: 204
Joined: Sun Dec 25, 2016 1:54 am
Libera.chat IRC: dchapiesky

Re: Cross compiler step one`

Post 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....
Plagiarize. Plagiarize. Let not one line escape thine eyes...
User avatar
matt11235
Member
Member
Posts: 286
Joined: Tue Aug 02, 2016 1:52 pm
Location: East Riding of Yorkshire, UK

Re: Cross compiler step one`

Post 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?
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum
billcu
Posts: 17
Joined: Tue Aug 26, 2014 9:12 pm

Re: Cross compiler step one`

Post 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?
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: Cross compiler step one`

Post 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.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Post Reply