Skip to content

Conversation

@ajtowns
Copy link
Contributor

@ajtowns ajtowns commented Aug 23, 2016

Add a configure check to use libatomic for std::atomic operations if needed.

Per https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_concurrency.html "Some uses of std::atomic also require linking to libatomic." This has been observed to be necessary when building with gcc on Debian's mips and mipsel architectures.

@sipa
Copy link
Member

sipa commented Aug 26, 2016

Concept ACK

@luke-jr
Copy link
Member

luke-jr commented Aug 27, 2016

Concept ACK, but I wonder if we should try to link with -latomic first, in case linking without it merely fails at runtime (or worse, works without providing the atomic guarantees).

@laanwj
Copy link
Member

laanwj commented Aug 30, 2016

Hm, you have a point @luke-jr but I also like the approach of trying -latomic only when necessary. This will make sure that no spurious library is linked that happens to be called 'atomic' on completely unrelated platforms/compilers, and that the configure log clearly states why a certain library is linked.

without it merely fails at runtime (or worse, works without providing the atomic guarantees).

That would be really messed-up. Linking a library or not should not affect program behavior in itself (that's determined during compile time), and missing symbols give an error at link time.
(Maybe something could be concocted with ELF weak symbols that gives this kind of behavior, even making it dependent on the link order, but bleh)

@laanwj
Copy link
Member

laanwj commented Aug 30, 2016

utACK 878faac

@luke-jr
Copy link
Member

luke-jr commented Aug 31, 2016

I agree, it would indeed be messed-up, but wasn't that almost exactly what happened in CVE-2012-1910?

@theuni
Copy link
Member

theuni commented Aug 31, 2016

Assuming we're only doing link tests, is an AC_SEARCH_LIBS not enough here?

@laanwj
Copy link
Member

laanwj commented Aug 31, 2016

I agree, it would indeed be messed-up, but wasn't that almost exactly what happened in CVE-2012-1910?

IIRC there the problem was linking the wrong library, not forgetting to link a library.

@laanwj
Copy link
Member

laanwj commented Sep 9, 2016

Assuming we're only doing link tests, is an AC_SEARCH_LIBS not enough here?

I think the problem is that it is unspecified which symbols are exported. The requirement is that the atomic library is linked when c++11 atomics are used. How these relate to ELF-level symbols is probably an implementation detail that may change over time.

@luke-jr
Copy link
Member

luke-jr commented Sep 9, 2016

main is always exported ;)

@laanwj
Copy link
Member

laanwj commented Sep 9, 2016

I mean these symbols exported by atomic library:

libbitcoin_server.a(libbitcoin_server_a-main.o): In function `std::__atomic_base<long long>::store(long long, std::memory_order)':
/usr/include/c++/6/bits/atomic_base.h:374: undefined reference to `__atomic_store_8'
libbitcoin_server.a(libbitcoin_server_a-main.o): In function `std::__atomic_base<long long>::load(std::memory_order) const':
/usr/include/c++/6/bits/atomic_base.h:396: undefined reference to `__atomic_load_8'
/usr/include/c++/6/bits/atomic_base.h:396: undefined reference to `__atomic_load_8'
libbitcoin_server.a(libbitcoin_server_a-main.o): In function `std::__atomic_base<long long>::store(long
...

Would be easy enough to check for one of them using AC_SEARCH_LIBS, but I think the test in this pull is fine and less dependent on implementation details.

@laanwj
Copy link
Member

laanwj commented Sep 9, 2016

ACK 878faac, reproduced with a mipsel-unknown-linux-gnu toolchain (gcc 5.3.0) built with crosstool-ng.
Without this patch it fails, with this patch it proceeds. Haven't tested the executable, but it's a clear step forward at least.

@laanwj laanwj merged commit 878faac into bitcoin:master Sep 9, 2016
laanwj added a commit that referenced this pull request Sep 9, 2016
878faac Add configure check for -latomic (Anthony Towns)
luke-jr pushed a commit to luke-jr/bitcoin that referenced this pull request Sep 21, 2016
@luke-jr
Copy link
Member

luke-jr commented Sep 21, 2016

Ugh, this m4 code is GPL licensed at best... checking with upstream if we can get MIT license on it.

@ajtowns
Copy link
Contributor Author

ajtowns commented Sep 22, 2016

@laanwj
Copy link
Member

laanwj commented Sep 26, 2016

This was backported in #8772, removing tag

sickpig referenced this pull request in sickpig/BitcoinUnlimited Oct 19, 2017
878faac Add configure check for -latomic (Anthony Towns)
schinzelh pushed a commit to dashpay/dash that referenced this pull request Oct 23, 2017
zkbot added a commit to zcash/zcash that referenced this pull request Dec 1, 2017
Build system improvements

Includes commits cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6978
  - Only the first commit (second is for QT)
- bitcoin/bitcoin#7059
- bitcoin/bitcoin#7603
  - Only the first commit (the rest are for QT)
- bitcoin/bitcoin#7954
- bitcoin/bitcoin#8314
  - Only the second commit (first is for QT)
- bitcoin/bitcoin#8504
  - Only the first commit (second was undoing something we didn't have)
- bitcoin/bitcoin#8520
- bitcoin/bitcoin#8563
- bitcoin/bitcoin#8249
- bitcoin/bitcoin#9156
- bitcoin/bitcoin#9831
- bitcoin/bitcoin#9789
- bitcoin/bitcoin#10766

Part of #2074.
zkbot added a commit to zcash/zcash that referenced this pull request Dec 15, 2017
Build system improvements

Includes commits cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6978
  - Only the first commit (second is for QT)
- bitcoin/bitcoin#7059
- bitcoin/bitcoin#7603
  - Only the first commit (without the `BITCOIN_QT_BIN` variable; the rest are for QT)
- bitcoin/bitcoin#7954
- bitcoin/bitcoin#8314
  - Only the second commit (first is for QT)
- bitcoin/bitcoin#8504
  - Only the first commit (second was undoing something we didn't have)
- bitcoin/bitcoin#8520
- bitcoin/bitcoin#8563
- bitcoin/bitcoin#8249
- bitcoin/bitcoin#9156
- bitcoin/bitcoin#9831
- bitcoin/bitcoin#9789
- bitcoin/bitcoin#10766

Part of #2074.
codablock pushed a commit to codablock/dash that referenced this pull request Jan 9, 2018
878faac Add configure check for -latomic (Anthony Towns)
codablock pushed a commit to codablock/dash that referenced this pull request Jan 9, 2018
878faac Add configure check for -latomic (Anthony Towns)
kotodev pushed a commit to koto-dev/koto.old that referenced this pull request Jan 25, 2018
Build system improvements

Includes commits cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6978
  - Only the first commit (second is for QT)
- bitcoin/bitcoin#7059
- bitcoin/bitcoin#7603
  - Only the first commit (without the `BITCOIN_QT_BIN` variable; the rest are for QT)
- bitcoin/bitcoin#7954
- bitcoin/bitcoin#8314
  - Only the second commit (first is for QT)
- bitcoin/bitcoin#8504
  - Only the first commit (second was undoing something we didn't have)
- bitcoin/bitcoin#8520
- bitcoin/bitcoin#8563
- bitcoin/bitcoin#8249
- bitcoin/bitcoin#9156
- bitcoin/bitcoin#9831
- bitcoin/bitcoin#9789
- bitcoin/bitcoin#10766

Part of #2074.
renium9 added a commit to koto-dev/koto.old that referenced this pull request Feb 6, 2018
Build system improvements

Includes commits cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6978
  - Only the first commit (second is for QT)
- bitcoin/bitcoin#7059
- bitcoin/bitcoin#7603
  - Only the first commit (without the `BITCOIN_QT_BIN` variable; the rest are for QT)
- bitcoin/bitcoin#7954
- bitcoin/bitcoin#8314
  - Only the second commit (first is for QT)
- bitcoin/bitcoin#8504
  - Only the first commit (second was undoing something we didn't have)
- bitcoin/bitcoin#8520
- bitcoin/bitcoin#8563
- bitcoin/bitcoin#8249
- bitcoin/bitcoin#9156
- bitcoin/bitcoin#9831
- bitcoin/bitcoin#9789
- bitcoin/bitcoin#10766

Part of #2074.

# Conflicts:
#	configure.ac
#	src/Makefile.am
#	src/Makefile.gtest.include
#	src/Makefile.test.include
#	zcutil/build.sh
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants