GCC
Contents
How to get ld to output trace information when invoked within GCC
gcc -Wl,-t -D_REENTRANT test.c -g -L/usr/lib/nptl -lpthread --static
The italicized text above, -Wl, -t, tells gcc to pass the -t flag to the linker. This results in trace information from 'ld' to be output.
Finding the links to a particular symbol
gcc -Wl,-trace-symbol=__pthread_mutex_lock -D_REENTRANT test.c -g -L/usr/lib/nptl -lpthread --static
The -trace-symbol= option can be stacked as follows:
gcc -Wl,-trace-symbol=__pthread_mutex_lock,-trace-symbol=__pthread_mutex_lock -D_REENTRANT test.c -g -L/usr/lib/nptl -lpthread --static
This will give the following example output:
user@host:~/19371> gcc -Wl,-trace-symbol=__register_frame_info_bases,-trace-symbol=__pthread_mutex_lock -D_REENTRANT test.c -g -L/usr/lib/nptl -lpthread --static /usr/lib/nptl/libpthread.a(pthread_mutex_lock.o): definition of __pthread_mutex_lock /usr/lib/gcc-lib/powerpc-suse-linux/3.3.3/libgcc_eh.a(unwind-dw2-fde-glibc.o): definition of __register_frame_info_bases /usr/lib/nptl/libc.a(dl-open.o): reference to __pthread_mutex_lock /usr/lib/nptl/libc.a(dl-close.o): reference to __pthread_mutex_lock /usr/lib/nptl/libc.a(dl-iteratephdr.o): reference to __pthread_mutex_lock /usr/lib/nptl/libc.a(dl-lookup.o): reference to __pthread_mutex_lock /usr/lib/nptl/libc.a(dl-fini.o): reference to __pthread_mutex_lock /usr/lib/nptl/libc.a(dl-addr.o): reference to __pthread_mutex_lock /usr/lib/nptl/libc.a(sdlsym.o): reference to __pthread_mutex_lock /usr/lib/nptl/libc.a(sdlvsym.o): reference to __pthread_mutex_lock
Using GCC -save-temps to extract files from libraries
The gcc invocation flag -save-temps can be used to gather intermediary post-preprocessor output of gcc prior to building or linking.
The output is .i files and .s files. The .i files are fully expanded source files which include macro expansions, and data type definitions.
GCC -save-temps example
In this edxample I want to extract three functions from GLIBC math library to be able to build them standalone and test them without having to rebuild GLIBC entirely. I still want to link to the rest of the GLIBC functions in the math library.
The three functions I want are ieee754_pow(), ieee754_exp(), and ieee754_log().
The source files we're interested are in the GLIBC source tree at:
/home/$user/toolchain/glibc/glibc-2.4-20060208/sysdeps/ieee754/dbl-64/e_pow.c /home/$user/toolchain/glibc/glibc-2.4-20060208/sysdeps/ieee754/dbl-64/e_exp.c /home/$user/toolchain/glibc/glibc-2.4-20060208/sysdeps/ieee754/dbl-64/e_log.c
In order to successfully extract the files we'll need to do a full GLIBC build first and then use the 'make' step output for the desired files as the basis for our extraction. For info on building GLIBC reference http://devpit.org/wiki/GLIBC.
We'll take for granted that we have a completed successfull build (64-bit in this case) in the following directory:
/home/$user/toolchain/builds/build64-24x-20060208
We know that the 'make' process output the compilation invocation output to a file called '__makeout' because we told it to do so:
/home/$user/toolchain/builds/build64-24x-20060208/__makeout
include extern printf
make sure to #include <stdio.h> in your 'test.c' file.
Check out a particular GCC revision from the subversion repository
svn co --revision=113421 http://gcc.gnu.org/svn/gcc/trunk gcc-4.2-20060502