GCC for x86_64 + newlib problems

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.
Post Reply
tarcisiofischer
Posts: 2
Joined: Thu Nov 01, 2012 1:56 pm

GCC for x86_64 + newlib problems

Post by tarcisiofischer »

Hello.
I'm new here in the forum.
I'm a computer science student from Brazil, trying to set up a x86_64 gcc with newlib, but having problems...

Some reference I'm using: First question:
What is the diference between x86_64-elf, x86_64-pc-none, x86_64-pc-linux and other TARGETs?
I'm using x86_64-elf, just because it was the first I saw (on http://wiki.osdev.org/GCC_Cross-Compiler).


The steps:
So, because I'm running ubuntu, GNU GMP and GNU MPFR are installed by apt-get:

Code: Select all

apt-get install libgmp3-dev
apt-get install libmpfr-dev
Then, I download the other necessary packages: Why those versions?
binutils-2.20.1a.tar.bz2 -> According to http://wiki.osdev.org/Cross-Compiler_Successful_Builds , binutils 2.20 works with GCC 4.4.3, so I tryied to take the nearest (binutils 2.20 is no longer available on http://ftp.gnu.org/gnu/binutils/).
gcc-core-4.4.4.tar.gz -> I'm using gcc 4.4.4 for IA32 on the OS I'm currently working with, so I wanted to keep versions
gcc-g++-4.4.4.tar.gz -> Compatibility with gcc-core 4.4.4
newlib-1.20.0.tar.gz -> latest one

And put all in my directory ~/gcc-src-try4/ (because the other 3 times didn't worked).
(ALL COMMANDS RUNNING AS ROOT)

Code: Select all

~/gcc-src-try4# export TARGET=x86_64-elf
# Since I'm trying to generate a gcc-4.4.4 for x86_64
~/gcc-src-try4# export PREFIX=/usr/local/x86_64
# The local where I want the gcc to install
~/gcc-src-try4# export PATH=$PATH:$PREFIX/bin
# For future use of the new compiler
================================================================================
Build binutils

Code: Select all

~/gcc-src-try4# tar -xvf binutils-2.20.1a.tar.bz2
~/gcc-src-try4# mkdir build-binutils
~/gcc-src-try4# cd build-binutils
~/gcc-src-try4/build-binutils# ../binutils-2.20.1/configure --target=$TARGET --prefix=$PREFIX | tee binutils-configure-log
~/gcc-src-try4/build-binutils# make all | tee binutils-make-all-log
~/gcc-src-try4/build-binutils# make install | tee binutils-make-install-log

================================================================================
Build gcc 4.4.4

Code: Select all

~/gcc-src-try4# tar -xvf gcc-core-4.4.4.tar.gz
~/gcc-src-try4# tar -xvf gcc-g++-4.4.4.tar.gz
~/gcc-src-try4# mkdir build-gcc
~/gcc-src-try4# cd build-gcc
~/gcc-src-try4/build-gcc# ../gcc-4.4.4/configure --target=$TARGET --prefix=$PREFIX --without-headers --with-newlib --disable-nls --enable-languages=c,c++ --program-prefix=x86_64- --disable-shared --with-gnu-as --with-gnu-ld --disable-threads
--target=$TARGET
Force compile to target=x86_64-elf

--prefix=$PREFIX
Force installation path /usr/local/x86_64

--without-headers
Tells GCC not to rely on any C library (standard or runtime) being present for the target.
(http://wiki.osdev.org/GCC_Cross-Compiler)

--with-newlib
Specifies that `newlib' is being used as the target C library. (http://gcc.gnu.org/install/configure.html)

--disable-nls
Disable Native Language Support (NLS)

--enable-languages=c,c++
The two languages I'll use with this GCC

--program-prefix=x86_64-
GCC program prefix (the result programs are: x86_64-gcc, x86_64-ld, x86_64-as, etc.)

--disable-shared
To build only static libraries (Because we will use GCC for OS development)

--with-gnu-as and --with-gnu-ld
Specify that the compiler should assume that the assembler / linker it finds is the GNU assembler / linker

--disable-threads
Specify that threading support should be disabled for the system. This is acctually the default, but I put just to make sure.

Code: Select all

~/gcc-src-try4/build-gcc# make all-gcc | tee gcc-make-all-gcc-log
~/gcc-src-try4/build-gcc# make install-gcc | tee gcc-make-install-gcc-log

================================================================================
Build newlib

Code: Select all

~/gcc-src-try4# tar -xvf newlib-1.20.0.tar.gz
~/gcc-src-try4# mkdir build-newlib
~/gcc-src-try4# cd build-newlib
~/gcc-src-try4/build-newlib# ../newlib-1.20.0/configure --target=$TARGET --prefix=$PREFIX
~/gcc-src-try4/build-newlib# make all | tee newlib-make-all-log
Errors:

Code: Select all

// ...
/bin/bash: x86_64-elf-cc: comando não encontrado
// ...
x86_64-elf-ar: ../argz/lib.a: No such file or directory
x86_64-elf-ar: ../stdlib/lib.a: No such file or directory
x86_64-elf-ar: ../ctype/lib.a: No such file or directory
x86_64-elf-ar: ../search/lib.a: No such file or directory
x86_64-elf-ar: ../stdio/lib.a: No such file or directory
x86_64-elf-ar: ../string/lib.a: No such file or directory
x86_64-elf-ar: ../signal/lib.a: No such file or directory
x86_64-elf-ar: ../time/lib.a: No such file or directory
x86_64-elf-ar: ../locale/lib.a: No such file or directory
x86_64-elf-ar: ../reent/lib.a: No such file or directory
x86_64-elf-ar: ../errno/lib.a: No such file or directory
x86_64-elf-ar: ../misc/lib.a: No such file or directory
x86_64-elf-ar: ../machine/lib.a: No such file or directory
x86_64-elf-ar: *.o: No such file or directory
Fix:

Code: Select all

ln -s x86_64-elf-gcc-4.4.4 x86_64-elf-cc
rm -rf build-newlib
mkdir build-newlib
cd build-newlib
../newlib-1.20.0/configure --target=$TARGET --prefix=$PREFIX
make all | tee newlib-make-all-log
make install | tee newlib-make-install-log

================================================================================
Build gcc again (Is this really necessary?)

Code: Select all

cd build-gcc
../gcc-4.4.4/configure --target=$TARGET --prefix=$PREFIX --without-headers --with-newlib --disable-nls --enable-languages=c,c++ --program-prefix=x86_64- --disable-shared --with-gnu-as --with-gnu-ld --disable-threads
make all | tee gcc-make-all-log

../../../gcc-4.4.4/libiberty/strsignal.c:554: error: conflicting types for 'psignal'
/usr/local/x86_64/x86_64-elf/include/signal.h:27: note: previous declaration of 'psignal' was here
make[2]: ** [strsignal.o] Erro 1
make[2]: Saindo do diretório `/home/tarcisio/workspace/gcc-src-try4/build-gcc/x86_64-elf/libiberty'
make[1]: ** [all-target-libiberty] Erro 2
make[1]: Saindo do diretório `/home/tarcisio/workspace/gcc-src-try4/build-gcc'
make: ** [all] Erro 2
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: GCC for x86_64 + newlib problems

Post by thepowersgang »

You're not quite following the wiki page correctly, the command is 'make all-gcc' not 'make all'
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply