6 pgcc Building libc-4.6.27

Contents of this section

Now we have the ELF compiler/assembler/linker. We need an ELF C library. This step will build the libc-4.6.27 in static/shared/debug/profile versions.

6.1 Try it now! Preparing libc-4.6.27 for compilation

Unpacking the archive


cd /usr/src
tar xfvz libc-4.6.27.tar.gz
cd libc-linux

Configuring the libc-4.6.27


./configure

Values correct (y/n) [y] ? n
Build 386, 486 or m68k library code (486 default) 4/3/m [4] ?
The target platform [i486-linux] ?
The target OS [linux] ?
Build targets (static/shared default) s/a [a] ?
Root path to i486-linux related files [/usr] ?
Bin path to gcc [/usr/bin] ? 
The gcc version [2.6.2] ?
Fast build/save space (fast default) f/s [f] ?
GNU `make' executable [make] ?
Root path to installation dirs [/] ?
Build a NYS libc from nys* (y default)  y/n [n] ?
Values correct (y/n) [y] ?

Edit Makeconfig


vi Makeconfig

at line 368 you should find:


PIC_OPT_CFLAGS= -fPIC -O1 -funroll-loops -fomit-frame-pointer

change it to:


PIC_OPT_CFLAGS= -fPIC -D__PIC__ -O1 -funroll-loops -fomit-frame-pointer

we need to define __PIC__ because the syscall?() macros are different for PIC and !PIC code.

at line 327 you should find:


REALCC  =gcc-elf -V $(GCCVERSION) -b $(TARGET_MACHINE) \

change it to:


REALCC  =gcc-elf \

we do not need the -V -b switches because gcc-elf should use the right binaries and -V -b confuses the compiler.

Edit elf/Makefile


vi elf/Makefile

at line 29 you can find:


if [ "1" = "1" ]; then \

change it to:


if [ "0" = "1" ]; then \

to make use of the linker directly and not through gcc-elf, because sadly gcc-elf do not support the -shared switch.

Edit elf/d-link/libdl/Makefile


vi elf/d-link/libdl/Makefile

at line 29 you should find:


ELF_LDFLAGS=--shared -nostdlib # using GNU ld

change it to:


ELF_LDFLAGS=-Wl,-shared -nostdlib # using GNU ld

to pass the -shared switch directly to the linker, see above.

Edit elf/d-link/readelflib1.c

This is important because the ld-linux.so (ELF shlib loader) must know that the standard ELF shlib path is /lib/elf/ and not /lib/

At line 122 you should find:


pnt1 = "/lib/";

change it to:


pnt1 = "/lib/elf/";

Edit sysdeps/linux/i386/gmon/gmon.c

This change is needed if you want to use the profile option with gcc-2.6.2 (see the Note in section bgcc )

at line 50 you should find:


extern void mcount(); /* asm ("mcount"); */

change it to:


extern void _mcount(); /* asm ("_mcount"); */

at line 221 you should find:


mcount()

change it to:


_mcount()

6.2 Try it now! Compiling libc-4.6.27

Now it is time to compile the libc-4.6.27. My suggestion is to launch the compilation and then go to sleep or something like that because it takes a LOT of time, ( If you have better things to do other than sleep, your time is not lost doing such nice things :)

do


nohup make ELF=true &

(for those who use the zsh now they should do a 'disown %1')

now you can logout/exit/ctrl-d

6.3 Try it now! Installing libc-4.6.27

To install the ELF libraries do:


make install.elf

and it is done!

Now you can delete the libc-linux:


cd /usr/src
rm -rf libc-linux

6.4 Try the Whole Thing!


cd /tmp

edit a file called p.c:


vi p.c

[start]
main()
{
printf("prova\n");
}
[end]

now try to compile the file to use the shared ELF library:


gcc-elf -O -v p.c -o p

'file p' should say:


p: ELF 32-bit LSB executable i386 (386 and up) Version 1

run './p' and you should see the output 'prova'

repeat the above operations to check the static/debug/profile with these command lines:


gcc-elf -static -O -v p.c -o p
gcc-elf -g -v p.c -o p
gcc-elf -p -v p.c -o p
gcc-elf -pg -v p.c -o p

launch the './p' for every compilation to check that p is right.

If you cannot see the output 'prova', you have done something wrong: Make sure you have executed all the commands described in this HOWTO and if you find some error, please let me know.

If this last test is passed, you have succeeded installing the bootstrap ELF dev. sys.

Next Chapter, Previous Chapter

Table of contents of this chapter, General table of contents

Top of the document, Beginning of this Chapter