build toolchain

Programming, for all ages and all languages.
Post Reply
teodori
Member
Member
Posts: 103
Joined: Wed Nov 14, 2012 4:55 pm

build toolchain

Post by teodori »

Hello, I want to build a toolchain to build my os and its bootloader. I need to build a flat binary executable to be placed into the mbr and after. I don't know what target to choose. Can anyone help me? I saw:

Code: Select all

TARGET=x86_64-pc-elf
TARGET=x86_64-pc-linux
And this doesn't work:

Code: Select all

x86_64
x86_64-pc-none
I don't know whate the two fields behind the x86_64 are:

Code: Select all

x86_64-*-*
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: build toolchain

Post by Combuster »

"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: build toolchain

Post by sortie »

@Combuster:

Please do not link to that particular wiki article. It's entirely obsolete for modern GCC versions and I have it scheduled for deletion at some point. I see that you are aware of this on the talk page - I also fail to see why this article is relevant. For all intents and purposes, that tutorial has been replaced by the standard gcc cross-compiler tutorial: http://wiki.osdev.org/GCC_Cross-Compiler

@teodori:

Simply use the cross-compiler tutorial above as the other tutorial is irrelevant for you (unless you use ancient GCC versions, in which case you should stop using ancient GCC versions). Anyways, with that cleared up, what you are confused about is the GNU platform triplets:

Code: Select all

machine-vendor-operating_system
This is an important part of the GNU build system. Every platform which code will run on or be cross-compiled to is described by such a platform. For instance, my operating systen is:

Code: Select all

x86_64-whatever-sortix
Notice how the vendor field is irrelevant in most cases. You can leave it out in most cases, where it would default to 'pc' (for 32-bit x86 platforms) or simply 'unknown'. Indeed, in almost all cases, my platform triplet is simply:

Code: Select all

x86_64-sortix
This is naturally expanded by the ./configure scripts to add a -unknown in the middle, which makes it unambiguous. Notice how GNU/Linux systems have a fourth field in the platform triplet:

Code: Select all

x86_64-unknown-linux-gnu
So it's not always really a platform triplet, even after ./configure has made it unambiguous.

So what platform triplet are you? Well, the vendor field doesn't really matter, so we'll just leave that out. How about the the operating system field then? Well, your operating system / boot loader is not Linux so that would be the wrong choice. How about 'none'? Well, I'm not even sure that's a real target and you are not 'none'. Indeed, the best pick for a bare generic target is actually 'elf'. This is a well-tested target that produces ELF executables. This doesn't matter for you if you use flat binaries, though, so elf is a fine choice. You can perhaps select 'coff' instead if that exists, but if it does, that setting is less tested than 'elf'. So yeah:

Code: Select all

x86_64-elf
This is the best platform triplet for you.
teodori
Member
Member
Posts: 103
Joined: Wed Nov 14, 2012 4:55 pm

Re: build toolchain

Post by teodori »

@sortie

thank you :-) that is what I needed. My bootloader loads an ELF.
teodori
Member
Member
Posts: 103
Joined: Wed Nov 14, 2012 4:55 pm

Re: build toolchain

Post by teodori »

binutils compiled without problems, but gcc doesn't.

Code: Select all

checking whether -lc should be explicitly linked in... yes
checking dynamic linker characteristics... no
checking how to hardcode library paths into programs... immediate
checking for shl_load... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
make[1]: *** [configure-target-libstdc++-v3] Error 1
make[1]: Leaving directory `/home/serge/Downloads/gcc-build'
make: *** [all] Error 2
I did this:
http://wiki.osdev.org/GCC_Cross-Compiler
teodori
Member
Member
Posts: 103
Joined: Wed Nov 14, 2012 4:55 pm

Re: build toolchain

Post by teodori »

sorry my bad I messed up, I did a simple make insteed of:

Code: Select all

make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
But now I am not sure of my data sizes, I use intXY_t, how are the typdefs for ints?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: build toolchain

Post by Combuster »

sortie wrote:@Combuster:

Please do not link to that particular wiki article. It's entirely obsolete for modern GCC versions and I have it scheduled for deletion at some point. I see that you are aware of this on the talk page - I also fail to see why this article is relevant. For all intents and purposes, that tutorial has been replaced by the standard gcc cross-compiler tutorial: http://wiki.osdev.org/GCC_Cross-Compiler
Yet it is the one place on the wiki that states exactly what TARGET to use for an 64-bit crosscompiler, even if it's also a written redirect to the generic GCC cross-compiler page in the same paragraph.

Basically, the OP's question would be answered within the introduction of the article linked, but not in the article you're suggesting as its replacement, so you certainly have some things to clean up before you go as far as deleting it :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: build toolchain

Post by sortie »

teodori wrote:But now I am not sure of my data sizes, I use intXY_t, how are the typdefs for ints?
You can quote simply use the <stdint.h> API. It's a freestanding header, so it works automatically. If you are passing -nostdinc currently, delete that option as it's silly, and then can use all the compiler headers. All the headers that you can manage to use with your cross-compiler is meant for you to use, anything else will fail.
Combuster wrote:Basically, the OP's question would be answered within the introduction of the article linked, but not in the article you're suggesting as its replacement, so you certainly have some things to clean up before you go as far as deleting it :wink:
Hmm, you're right. I think the better solution is to write an article on GNU Host Triplets and link to that (or include it) from GCC Cross-Compiler. I can perhaps base that on my above explanation.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: build toolchain

Post by sortie »

I wrote an article on this subject: http://wiki.osdev.org/Host_Triplet

Hopefully it should answer the OP's question and address Combuster's concerns.
teodori
Member
Member
Posts: 103
Joined: Wed Nov 14, 2012 4:55 pm

Re: build toolchain

Post by teodori »

Ok my toolchaine works here are the configs

Code: Select all

tar -xJf binutils-2.24.tar.xz
mkdir binutils-build
cd binutils-build
../binutils-2.24/configure --target=x86_64-pc-elf --prefix="$HOME/opt" --disable-nls --disable-doc
make -j 1
make install

tar -xJf gmp-5.1.3.tar.xz
mv gmp-5.1.3 gmp
tar -xJf mpc-1.0.1.tar.xz
mv mpc-1.0.1 mpc
tar -xJf mpfr-3.1.2.tar.xz
mv mpfr-3.1.2 mpfr

tar -xJf gcc-4.8.2.tar.xz
mv gmp gcc-4.8.2/
mv mpc gcc-4.8.2/
mv mpfr gcc-4.8.2/
mkdir gcc-build
cd gcc-build
../gcc-4.8.2/configure --target=x86_64-pc-elf --prefix="$HOME/opt" --disable-nls --disable-doc --enable-languages=c,c++ --without-headers
make all-gcc -j 1
make all-target-libgcc -j 1
make install-gcc
make install-target-libgcc
Post Reply