Compilation error _ sync_bool_compare_and_swap_4

Source: Internet
Author: User

For fast transmission of large files, you need to investigate bit torrent and download opentracker.
The following error occurs during libowfat Compilation:
T. o: In function 'main ':
T. c :(. text + 0x76): undefined reference to '_ sync_bool_compare_and_swap_4'
T. c :(. text + 0xa2): undefined reference to '_ sync_bool_compare_and_swap_4'
Collect2: ld returned 1 exit status
Make: *** [t] Error 1
This function cannot be defined. It is a function used in t. c.
After reading a few lines above, the compilation command that throws this error is:
Gcc-c t. c-pipe-W-Wall-O2-fomit-frame-pointer-D_REENTRANT-I.

In file encoded ded from t. c: 25:
Iarray. h: 5: 2: warning: # warning do not use this yet. It may look thread-safe but it is not!
In file encoded ded from t. c: 27:
CAS. h: In function 'compare _ and_swap ':
CAS. h: 31: warning: no return statement in function returning non-void
CAS. h: In function 'atomic _ add_return ':
CAS. h: 61: warning: no return statement in function returning non-void
T. c: In function 'main ':
T. c: 50: warning: unused parameter 'argc'
T. c: 50: warning: unused parameter 'argv'
Gcc-g-o t. o libowfat. a 'cat libsocket '-lpthread

I opened t. c and looked at it. I found that t. c code is very short and there are only a few dozen lines. The error is caused by the function call:
Printf ("% u/n", compare_and_swap (& x, 26, 17 ));
Printf ("% u/n", compare_and_swap (& x, 23,17 ));

The source code was not found with _ sync_bool_compare_and_swap_4. You searched in the source code:
[Whb @ jcwkyl libowfat] $ grep sync_bool_compare_and_swap *

CAS. h: _ sync_bool_compare_and_swap (x, oldval, newval );
Binary file t. o matches

It is defined in the CAS. h file.
CAS. hfile is also very short, and the relevant code can be seen at once:
# If defined (_ INTEL_COMPILER) | (_ GNUC _> 4) | (_ GNUC _ = 4) & (_ GNUC_MINOR _> = 1 ))
# Define USE_BUILTINS
# Endif

/* If (* x = oldval) {* x = newval; return 1;} else return 0 ;*/
Static inline int compare_and_swap (volatile size_t * x, size_t oldval, size_t newval ){
# Ifdef USE_BUILTINS
_ Sync_bool_compare_and_swap (x, oldval, newval );
# Elif defined (_ i386 __)
Char result;
 
Asm volatile ("lock; cmpxchgl % 3, % 0; setz % 1": "= m" (* x), "= q"
(Result): "m" (* x), "r" (newval), "a" (oldval): "memory ");
Return result;
# Elif defined (_ x86_64 __)
Char result;
 
Asm volatile ("lock; cmpxchgq % 3, % 0; setz % 1": "= m" (* x), "= q"
(Result): "m" (* x), "r" (newval), "a" (oldval): "memory ");
Return result;
# Else
# Error architecture not supported and GCC too old, edit cas. h
# Endif
}

Obviously, because use_builtins macro is defined, compare_and_swap calls _ sync_bool_compare_and_swap (x, oldval, newval );
Remove this macro and replace it with _ i386 __. it should be okay. Let's take a look at the source files referenced by CAS. h.

[WHB @ jcwkyl libowfat] $ grep cas. H *

Cas. h: # error architecture not supported and GCC too old, edit cas. h
Cas. h: # error architecture not supported and GCC too old, edit cas. h
Cas. h: # error architecture not supported and GCC too old, edit cas. h
Cas. h: # error architecture not supported and GCC too old, edit cas. h
Cas. h: # error architecture not supported and GCC too old, edit cas. h
Gnumakefile: havesigio. h cas. h
Makefile: iarray. h cas. h io_internal.h haveepoll. h havekqueue. h havedevpoll. h/
Makefile: havesigio. h cas. h
T. C: # include "CAs. H"

Fortunately, only one t. c file references this file. Therefore, you can boldly modify CAS. h:
Static inline int compare_and_swap (volatile size_t * x, size_t oldval, size_t newval ){
# Undef USE_BUILTINS

# Ifndef _ i386 __

# Define _ i386 __

# Define jcwkyl

# Endif

# Ifdef USE_BUILTINS
_ Sync_bool_compare_and_swap (x, oldval, newval );
# Elif defined (_ i386 __)
Char result;
 
Asm volatile ("lock; cmpxchgl % 3, % 0; setz % 1": "= m" (* x), "= q"
(Result): "m" (* x), "r" (newval), "a" (oldval): "memory ");

# Ifdef jcwkyl

# Undef _ i386 __

# Endif

# Define USE_BUILTINS

Return result;
# Elif defined (_ x86_64 __)
Char result;
 
Asm volatile ("lock; cmpxchgq % 3, % 0; setz % 1": "= m" (* x), "= q"
(Result): "m" (* x), "r" (newval), "a" (oldval): "memory ");
Return result;
# Else
# Error architecture not supported and gcc too old, edit CAS. h
# Endif
}
The highlighted part is the newly added code. This time make has no error.
Later, opentracker successfully made.

Google will find the cause and solution of this error. The solution is to pass the-march = i133 parameter to gcc. Refer:

Http://stackoverflow.com/questions/2118992/how-do-i-use-gcc-builtin-sync-bool-compare-and-swap-in-g-on-macosx

Http://bugs.gentoo.org/show_bug.cgi? Id = 199904

Http://dev.ryzom.com/issues/899

Http://www.linuxquestions.org/questions/linux-from-scratch-13/glibc-1st-pass-wont-compile-possibly-i486-related-704580/

...
Use opentracker to download an object using bitorrent:
[Root @ jcwkyl opentracker] #./opentracker

Use ctorrent to create a torrent file:
[Whb @ jcwkyl Desktop] $ ctorrent-t-u http: // 10.60.56.90: 6969/announce-s test. torrent 10.1.1.14.5976.pdf

Create hash table: 1/1
Create metainfo file test. torrent successful.
[Whb @ jcwkyl Desktop] $ ctorrent-x test. torrent

META INFO
Announce: http: // 10.60.56.90: 6969/announce
Created On: Wed Dec 15 19:32:21 2010
Pieelength: 262144
Created with: Enhanced-CTorrent/dnh3.3.2
FILES INFO
<1> 10.1.1.14.5976.pdf [1, 90160]
Total: 0 MB

Use ftp to download the torrent file to a client. Then download the package from the client:
[Root @ server ~] # Ctorrent test. torrent

META INFO
Announce: http: // 10.60.56.90: 6969/announce
Created On: Wed Dec 15 19:32:21 2010
Pieelength: 262144
Created with: Enhanced-CTorrent/dnh3.3.2
FILES INFO
<1> 10.1.1.14.5976.pdf [1, 90160]
Total: 0 MB
Creating file "10.1.1.14.5976.pdf"
Listening on 0.0.0.0: 2706
Press 'H' or '? 'For help (display/control client options ).
|
0/0/1 [0/1/0] 0 MB, 0 MB | K/s | K
E: 0, 1

Download complete.
Total time used: 0 minutes.
Seed for others 72 hours
-0/0/2 [1/1/1] 0 MB, 0 MB | K/s | k e:
At the same time, make a kind on the original machine:
[Whb @ jcwkyl Desktop] $ ctorrent test. torrent

META INFO
Announce: http: // 10.60.56.90: 6969/announce
Created On: Wed Dec 15 19:32:21 2010
Pieelength: 262144
Created with: Enhanced-CTorrent/dnh3.3.2
FILES INFO
<1> 10.1.1.14.5976.pdf [1, 90160]
Total: 0 MB
Warn, couldn't set bit field refer file "test. torrent. bf": No such file or directory
This is normal if you are seeding.
Listening on 0.0.0.0: 2706
Press 'H' or '? 'For help (display/control client options ).
Checking completed.
FILES INFO
<1> 10.1.1.14.5976.pdf [90160] 1/1 (100%)
Total: 0 MB
-
0/0/1 [1/1/1] 0 MB, 0 MB | K/s | k e:
Connecting

Seed for others 72 hours

The file is successfully downloaded.
Open your browser and enter:
Http: // 10.60.56.90: 6969/stats? Mode = everything

You can view all torrent files and upload and download information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.