Gnu Toolchain/GLIBC/Debugging GLIBC
Contents
Authors
This page was originally created by Ryan S. Arnold aka RandomTask.
Saving the GLIBC configure script output
When you configure a GLIBC build make sure to save the output by tacking ' 2>&1 | tee _configure' onto the end of the configure line, e.g.
CC='/opt/toolchain/bin/gcc -m32' \ CXX='/opt/toolchain/bin/g++ -m32' \ CXXFLAGS='-O2 -g' \ CFLAGS='-mlong-double-128 -O2 -g' \ /home/$USER/toolchain/toolchain-1.0-5/src/libc/configure --build=powerpc-linux \ --host=powerpc-linux --prefix=/opt/toolchain --with-headers=/opt/toolchain/include \ --enable-add-ons=dfp,nptl --with-tls --with-__thread --enable-shared \ --without-cvs 2>&1 | tee _configure
Likewise do the same with your make, make check, and make install output.
GLIBC search path
The _configure output we saved above stores the GLIBC search path. This order is indicative of how files are chosen when a Makefile indicates that a target is to be built or a #include indicates that a header file is to be included. Later parts of this tutorial will investigate how to co-opt this search path to insert new directories using Implies files.
checking sysdep dirs... sysdeps/powerpc/powerpc32/elf sysdeps/powerpc/elf sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu sysdeps/powerpc/powerpc32/fpu dfp/sysdeps/unix/sysv/linux/powerpc/powerpc32 nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32 sysdeps/unix/sysv/linux/powerpc/powerpc32 dfp/sysdeps/unix/sysv/linux/powerpc nptl/sysdeps/unix/sysv/linux/powerpc sysdeps/unix/sysv/linux/powerpc sysdeps/ieee754/ldbl-128ibm sysdeps/ieee754/ldbl-opt dfp/sysdeps/unix/sysv/linux dfp/sysdeps/dfp dfp/sysdeps/dfp/math dfp/sysdeps/dfp/math/bits dfp/sysdeps/dfp/stdio-common dfp/sysdeps/dfp/stdlib dfp/sysdeps/dfp/wcsmbs dfp/sysdeps/ieee754r dfp/sysdeps/ieee754r/d32 dfp/sysdeps/ieee754r/d64 dfp/sysdeps/ieee754r/d128 nptl/sysdeps/unix/sysv/linux nptl/sysdeps/pthread sysdeps/pthread sysdeps/unix/sysv/linux sysdeps/gnu sysdeps/unix/common sysdeps/unix/mman sysdeps/unix/inet dfp/sysdeps/unix/sysv nptl/sysdeps/unix/sysv sysdeps/unix/sysv sysdeps/unix/powerpc dfp/sysdeps/unix nptl/sysdeps/unix sysdeps/unix sysdeps/posix dfp/sysdeps/powerpc/powerpc32 sysdeps/powerpc/powerpc32 sysdeps/wordsize-32 sysdeps/powerpc/fpu dfp/sysdeps/powerpc nptl/sysdeps/powerpc sysdeps/powerpc sysdeps/ieee754/dbl-64 sysdeps/ieee754/flt-32 sysdeps/ieee754 sysdeps/generic/elf sysdeps/generic
To view each sysdep directory on a single line, use:
grep config-sysdirs config.make | tr " " "\n"
GLIBC Search Path Debugging
If you're having problems determining one of the following you can use some special compiler flags to help you evaluate the problematic areas:
- which symbols are being defined for a particular C file
- how a macro is being expanded
- if a particular file is pulled in from the search path
In your aforementioned _make output locate the compiler invocation for the problematic .c file, e.g.:
/opt/toolchain/bin/gcc -m32 ../dfp/sysdeps/ieee754r/d32/nexttowardd32.c -c \ -std=gnu99 -O2 -Wall -Winline -Wwrite-strings -fmerge-all-constants -g \ -mlong-double-128 -mnew-mnemonics -Wstrict-prototypes -D__STDC_WANT_DEC_FP__=1 \ -mlong-double-128 -I../include \ -I/home/$USER/toolchain/toolchain-1.0-5/build/glibc32/dfp \ -I/home/$USER/toolchain/toolchain-1.0-5/build/glibc32 \ -I../sysdeps/powerpc/powerpc32/elf -I../sysdeps/powerpc/elf \ -I../sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu \ -I../sysdeps/powerpc/powerpc32/fpu \ -I../dfp/sysdeps/unix/sysv/linux/powerpc/powerpc32 \ -I../nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32 \ -I../sysdeps/unix/sysv/linux/powerpc/powerpc32 \ -I../dfp/sysdeps/unix/sysv/linux/powerpc \ -I../nptl/sysdeps/unix/sysv/linux/powerpc -I../sysdeps/unix/sysv/linux/powerpc \ -I../sysdeps/ieee754/ldbl-128ibm -I../sysdeps/ieee754/ldbl-opt \ -I../dfp/sysdeps/unix/sysv/linux -I../dfp/sysdeps/dfp \ -I../dfp/sysdeps/dfp/math -I../dfp/sysdeps/dfp/math/bits \ -I../dfp/sysdeps/dfp/stdio-common -I../dfp/sysdeps/dfp/stdlib \ -I../dfp/sysdeps/dfp/wcsmbs -I../dfp/sysdeps/ieee754r \ -I../dfp/sysdeps/ieee754r/d32 -I../dfp/sysdeps/ieee754r/d64 \ -I../dfp/sysdeps/ieee754r/d128 -I../nptl/sysdeps/unix/sysv/linux \ -I../nptl/sysdeps/pthread -I../sysdeps/pthread -I../sysdeps/unix/sysv/linux \ -I../sysdeps/gnu -I../sysdeps/unix/common -I../sysdeps/unix/mman \ -I../sysdeps/unix/inet -I../dfp/sysdeps/unix/sysv -I../nptl/sysdeps/unix/sysv \ -I../sysdeps/unix/sysv -I../sysdeps/unix/powerpc -I../dfp/sysdeps/unix \ -I../nptl/sysdeps/unix -I../sysdeps/unix -I../sysdeps/posix \ -I../dfp/sysdeps/powerpc/powerpc32 -I../sysdeps/powerpc/powerpc32 \ -I../sysdeps/wordsize-32 -I../sysdeps/powerpc/fpu -I../dfp/sysdeps/powerpc \ -I../nptl/sysdeps/powerpc -I../sysdeps/powerpc -I../sysdeps/ieee754/dbl-64 \ -I../sysdeps/ieee754/flt-32 -I../sysdeps/ieee754 -I../sysdeps/generic/elf \ -I../sysdeps/generic -I../dfp -I../nptl -I.. -I../libio -I. -nostdinc \ -isystem /home/opt/toolchain/bin/../lib/gcc/powerpc64-linux/4.1.2/include \ -isystem /opt/toolchain/include -D_LIBC_REENTRANT -include \ ../include/libc-symbols.h -DNOT_IN_libc=1 -DIS_IN_libdfp=1 \ -o /home/$USER/toolchain/toolchain-1.0-5/build/glibc32/dfp/nexttowardd32.o \ -MD -MP -MF /home/$USER/toolchain/toolchain-1.0-5/build/glibc32/dfp/nexttowardd32.o.dt \ -MT /home/$USER/toolchain/toolchain-1.0-5/build/glibc32/dfp/nexttowardd32.o
From this point in the _make output file search backward for the first match of 'Entering directory', e.g:
make[2]: Entering directory `/home/$USER/toolchain/toolchain-1.0-5/src/glibc/dfp'
Remember this directory path, we'll be using it later for our source directory path.
What we're going to do is invoke the compiler with the '-dD -E' or '-save-temps' flags. This will require copying the build fragment just referenced into a shell script and changing some of the compilation parameters:
- Compiler flags (paraphrased from the GCC manual page)
- -dD
- "Dump all macro definitions, at the end of preprocessing, in addition to normal output."
- -E
- "If this options is used, then the linker is not run, and object file names should not be used as arguments."
- -save-temps
- "Store the usual 'temporary' intermediate files permanently; place them in the current directory and name them based on the source file. Thus, compiling foo.c with -c -save-temps would produce files foo.i and foo.s, as well as foo.o. This creates a preprocessed foo.i output file even though the compiler now normally uses an integrated preprocessor."
Using the -dD and -E compiler flags
For the '-dD -E' invocation the compiler will replace the output file, indicated with the '-o' flag with the intermediary output so this means we'll replace the '-o' indicated file with our own '_nexttoward32.out'.
Create a shell script in the build directory that looks like the following and use the source directory we identified earlier for the SRCDIR variable:
#!/bin/bash CURDIR="`pwd`" SRCDIR="/home/$USER/toolchain/toolchain-1.0-5/src/libc/dfp" pushd ./ > devnull # change directory to the glibc source directory cd $SRCDIR # rebuild the component as an intermediary compiler output file /opt/toolchain/bin/gcc -m32 -dD -E ../dfp/sysdeps/ieee754r/d32/nexttowardd32.c -c \ -std=gnu99 -O2 -Wall -Winline -Wwrite-strings -fmerge-all-constants -g \ -mlong-double-128 -mnew-mnemonics -Wstrict-prototypes -D__STDC_WANT_DEC_FP__=1 \ -mlong-double-128 -I../include \ -I/home/$USER/toolchain/toolchain-1.0-5/build/glibc32/dfp \ -I/home/$USER/toolchain/toolchain-1.0-5/build/glibc32 \ -I../sysdeps/powerpc/powerpc32/elf -I../sysdeps/powerpc/elf \ -I../sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu \ -I../sysdeps/powerpc/powerpc32/fpu \ -I../dfp/sysdeps/unix/sysv/linux/powerpc/powerpc32 \ -I../nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32 \ -I../sysdeps/unix/sysv/linux/powerpc/powerpc32 \ -I../dfp/sysdeps/unix/sysv/linux/powerpc \ -I../nptl/sysdeps/unix/sysv/linux/powerpc -I../sysdeps/unix/sysv/linux/powerpc \ -I../sysdeps/ieee754/ldbl-128ibm -I../sysdeps/ieee754/ldbl-opt \ -I../dfp/sysdeps/unix/sysv/linux -I../dfp/sysdeps/dfp \ -I../dfp/sysdeps/dfp/math -I../dfp/sysdeps/dfp/math/bits \ -I../dfp/sysdeps/dfp/stdio-common -I../dfp/sysdeps/dfp/stdlib \ -I../dfp/sysdeps/dfp/wcsmbs -I../dfp/sysdeps/ieee754r \ -I../dfp/sysdeps/ieee754r/d32 -I../dfp/sysdeps/ieee754r/d64 \ -I../dfp/sysdeps/ieee754r/d128 -I../nptl/sysdeps/unix/sysv/linux \ -I../nptl/sysdeps/pthread -I../sysdeps/pthread -I../sysdeps/unix/sysv/linux \ -I../sysdeps/gnu -I../sysdeps/unix/common -I../sysdeps/unix/mman \ -I../sysdeps/unix/inet -I../dfp/sysdeps/unix/sysv -I../nptl/sysdeps/unix/sysv \ -I../sysdeps/unix/sysv -I../sysdeps/unix/powerpc -I../dfp/sysdeps/unix \ -I../nptl/sysdeps/unix -I../sysdeps/unix -I../sysdeps/posix \ -I../dfp/sysdeps/powerpc/powerpc32 -I../sysdeps/powerpc/powerpc32 \ -I../sysdeps/wordsize-32 -I../sysdeps/powerpc/fpu -I../dfp/sysdeps/powerpc \ -I../nptl/sysdeps/powerpc -I../sysdeps/powerpc -I../sysdeps/ieee754/dbl-64 \ -I../sysdeps/ieee754/flt-32 -I../sysdeps/ieee754 -I../sysdeps/generic/elf \ -I../sysdeps/generic -I../dfp -I../nptl -I.. -I../libio -I. -nostdinc \ -isystem /home/opt/toolchain/bin/../lib/gcc/powerpc64-linux/4.1.2/include \ -isystem /opt/toolchain/include -D_LIBC_REENTRANT -include \ ../include/libc-symbols.h -DNOT_IN_libc=1 -DIS_IN_libdfp=1 \ -o $CURDIR/_nexttowardd32.out echo "Output in $CURDIR/_nexttowardd32.out" popd > /dev/null
Using the -save-temps compiler flag
For the '-save-temps' invocation the compiler will not replace the output file indicated with the '-o' flag so leave the original '-o' directives in place. As indicated by the GCC manual page the intermediary output will be placed into a '.i' in the original source directory. Additionally there will be a '.s' assembler file as well.
Create a shell script in the build directory that looks like this:
#!/bin/bash CURDIR="`pwd`" SRCDIR="/home/$USER/toolchain/toolchain-1.0-5/src/libc/dfp" pushd ./ > devnull # change directory to the glibc source directory cd $SRCDIR # rebuild the component as an intermediary compiler output file /opt/toolchain/bin/gcc -m32 -save-temps ../dfp/sysdeps/ieee754r/d32/nexttowardd32.c -c \ -std=gnu99 -O2 -Wall -Winline -Wwrite-strings -fmerge-all-constants -g \ -mlong-double-128 -mnew-mnemonics -Wstrict-prototypes -D__STDC_WANT_DEC_FP__=1 \ -mlong-double-128 -I../include \ -I/home/$USER/toolchain/toolchain-1.0-5/build/glibc32/dfp \ -I/home/$USER/toolchain/toolchain-1.0-5/build/glibc32 \ -I../sysdeps/powerpc/powerpc32/elf -I../sysdeps/powerpc/elf \ -I../sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu \ -I../sysdeps/powerpc/powerpc32/fpu \ -I../dfp/sysdeps/unix/sysv/linux/powerpc/powerpc32 \ -I../nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32 \ -I../sysdeps/unix/sysv/linux/powerpc/powerpc32 \ -I../dfp/sysdeps/unix/sysv/linux/powerpc \ -I../nptl/sysdeps/unix/sysv/linux/powerpc -I../sysdeps/unix/sysv/linux/powerpc \ -I../sysdeps/ieee754/ldbl-128ibm -I../sysdeps/ieee754/ldbl-opt \ -I../dfp/sysdeps/unix/sysv/linux -I../dfp/sysdeps/dfp \ -I../dfp/sysdeps/dfp/math -I../dfp/sysdeps/dfp/math/bits \ -I../dfp/sysdeps/dfp/stdio-common -I../dfp/sysdeps/dfp/stdlib \ -I../dfp/sysdeps/dfp/wcsmbs -I../dfp/sysdeps/ieee754r \ -I../dfp/sysdeps/ieee754r/d32 -I../dfp/sysdeps/ieee754r/d64 \ -I../dfp/sysdeps/ieee754r/d128 -I../nptl/sysdeps/unix/sysv/linux \ -I../nptl/sysdeps/pthread -I../sysdeps/pthread -I../sysdeps/unix/sysv/linux \ -I../sysdeps/gnu -I../sysdeps/unix/common -I../sysdeps/unix/mman \ -I../sysdeps/unix/inet -I../dfp/sysdeps/unix/sysv -I../nptl/sysdeps/unix/sysv \ -I../sysdeps/unix/sysv -I../sysdeps/unix/powerpc -I../dfp/sysdeps/unix \ -I../nptl/sysdeps/unix -I../sysdeps/unix -I../sysdeps/posix \ -I../dfp/sysdeps/powerpc/powerpc32 -I../sysdeps/powerpc/powerpc32 \ -I../sysdeps/wordsize-32 -I../sysdeps/powerpc/fpu -I../dfp/sysdeps/powerpc \ -I../nptl/sysdeps/powerpc -I../sysdeps/powerpc -I../sysdeps/ieee754/dbl-64 \ -I../sysdeps/ieee754/flt-32 -I../sysdeps/ieee754 -I../sysdeps/generic/elf \ -I../sysdeps/generic -I../dfp -I../nptl -I.. -I../libio -I. -nostdinc \ -isystem /home/opt/toolchain/bin/../lib/gcc/powerpc64-linux/4.1.2/include \ -isystem /opt/toolchain/include -D_LIBC_REENTRANT -include \ ../include/libc-symbols.h -DNOT_IN_libc=1 -DIS_IN_libdfp=1 \ -o /home/$USER/toolchain/toolchain-1.0-5/build/glibc32/dfp/nexttowardd32.o \ -MD -MP -MF /home/$USER/toolchain/toolchain-1.0-5/build/glibc32/dfp/nexttowardd32.o.dt \ -MT /home/$USER/toolchain/toolchain-1.0-5/build/glibc32/dfp/nexttowardd32.o popd > /dev/null echo "Output in $SRCDIR/nexttowardd32.i"