Error Message "undefined symbol __sync_fetch_and_add_4"

Last edited on

Symptom

When trying to test an application with a build from sources the startup via squishserver fails with the following error on the ARM platform:

/path/to/aut: symbol lookup error: /path/to/squish/lib/libsquishqtpre.so:
   undefined symbol: __sync_fetch_and_add_4

Possible Cause and Suggested Solution

The symbol __sync_fetch_and_add (and others) are only implemented in the static libgcc library. When linking Squish's libraries against the shared gcc_s library these symbols will be missing. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46563 for a discussion of the problem.

A quick workaround can be achieved by patching Squish's build scripts to have -lgcc added to the link commands for each library. A more convenient and permanent fix for this toolchain problem: replace the libgcc_s.so symlink with a linker script (plain text file) with the following content:

/* GNU ld script
   Use the shared library, but some functions are only in
   the static library.  */
GROUP ( libgcc_s.so.1 libgcc.a )

This will make the linker pull in both the shared and static library when creating the binaries.