Undefined refers to the `__sync_val_compare_and_swap_4 'error when compiling using gcc 4.1.1 and 4.2.0 for the target of Sparc v8

Using crosstool scripts that I built under Cygwin the following gcc-4.1.1 and 4.2.0 compilers 20061024 (preview) for the Sparc architecture:

$ ./sparc-unknown-linux-gnu-gcc -v
Using built-in specs.
Target: sparc-unknown-linux-gnu
Configured with: /crosstool-0.43/build/sparc-unknown-linux-gnu/gcc-4.1.1-glibc-2.3.6/gcc-4.1.1/configure --target=sparc-unknown-linux-gnu --host=i686-host_pc-cygwin --prefix=/opt/crosstool/gcc-4.1.1-glibc-2.3.6/sparc-unknown-linux-gnu --with-headers=/opt/crosstool/gcc-4.1.1-glibc-2.3.6/sparc-unknown-linux-gnu/sparc-unknown-linux-gnu/include --with-local-prefix=/opt/crosstool/gcc-4.1.1-glibc-2.3.6/sparc-unknown-linux-gnu/sparc-unknown-linux-gnu --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 4.1.1

and

$ ./sparc-unknown-linux-gnu-gcc -v
Using built-in specs.
Target: sparc-unknown-linux-gnu
Configured with: /crosstool-0.43/build/sparc-unknown-linux-gnu/gcc-4.2-20061024-                           glibc-2.3.6/gcc-4.2-20061024/configure --target=sparc-unknown-linux-gnu --host=i                           686-host_pc-cygwin --prefix=/opt/crosstool/gcc-4.2-20061024-glibc-2.3.6/sparc-un                           known-linux-gnu --with-headers=/opt/crosstool/gcc-4.2-20061024-glibc-2.3.6/sparc                           -unknown-linux-gnu/sparc-unknown-linux-gnu/include --with-local-prefix=/opt/cros                           stool/gcc-4.2-20061024-glibc-2.3.6/sparc-unknown-linux-gnu/sparc-unknown-linux-g                           nu --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atex                           it --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 4.2.0 20061024 (prerelease)

I need it so that I can use the Atomic-Builtins-__sync_val_compare_and_swap related function in my programs that supports whith 4.1. * gcc version.

I am trying to compile simple C code:

long cmpxchg( long* value, long comp_val, long new_val )
{
    return __sync_val_compare_and_swap( value, comp_val, new_val );
}

int main()
{
    return 0;
}

But I have the following error: (on both compilers):

$ ./sparc-unknown-linux-gnu-gcc test_cas.c -o test_cas
/tmp/ccREXHsP.o: In function `cmpxchg':
test_cas.c:(.text+0x24): undefined reference to `__sync_val_compare_and_swap_4'
collect2: ld returned 1 exit status

? , ? , Sparc (SPARC v8) ? - ( ).

+3
5

: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html __sync_val_compare_and_swap ( ). . , , , __sync_val_compare_and_swap_4 , , , libgcc_s ( -lgcc_s ).

+6

NodeJS ( V8) ARMv5.

, GCC , , "-lgcc_s" .

Google (http://vincesoft.blogspot.fr/2012/04/how-to-solve-undefined-reference-to.html), :

GCC, , , .

, , , .

, .

+2

on Android, I was able to solve the problem with the following flags LOCAL_CFLAGS + = -O3 -fopenmp LOCAL_LDFLAGS + = -O3 -fopenmp -lgcc -latomic -lgomp

0
source

For me, the above error meant "you are using the gcc / mingw cross-compiler, so -march = native does not work" (I think). See fooobar.com/questions/49323 / ... (basically you can bypass it manually by specifying the -march parameter).

0
source

Source: https://habr.com/ru/post/1677400/


All Articles