Archive for December, 2006

dircmp for Linux

Wednesday, December 27th, 2006

Former Unix programmers are probably familiar with the dircmp command for comparing two directories. Early versions of Linux didn’t have anything like it which was frustrating. In later versions of Linux, you can use the diff command to recursively compare directories.  It’s not exaclty like dircmp, but close enough:

diff -q -r . /otherDir

gdb forking processes

Friday, December 15th, 2006

It can be real frustrating to debug a process with gdb only to have it fork and the child fails. You get left with a process that doesn’t matter. Solving this problem is very easy, you just need to “follow the child”:

set follow-fork-mode child

gcov build problem: hidden symbol ‘__gcov_init’ and final link failed: Nonrepresentable section on output

Monday, December 11th, 2006

One of our clients had a project that included C for embedded systems, Java, and C++ thrown in (mostly for unit testing). One of the tasks was to investigate code coverage tools for the C portion which led us to gcov (see gcov(1)). During the build for gcov, we encountered the following link errors:

/usr/bin/ld: obj/Test_function: hidden symbol `__gcov_init’ in /usr/lib/gcc/i386-redhat-linux/3.4.5/libgcov.a(_gcov.o) is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status

This occurred when the C++ was being linked to our application’s shared libs.

After some investigation, the solution came via the gcc(1) description for -shared option:

… For predictable results, you must also specify the same
set of options that were used to generate code (-fpic, -fPIC, or
model suboptions)…

The gcov parameters in this case are -fprofile-arcs and -ftest-coverage. These parameters were added with the -fPIC option for gcc -shared for the shared libraries. Then the code was able to link and run properly.