Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix getentropy import check on osx #15103

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
5 participants
@jameshilliard
Copy link
Contributor

commented Jan 4, 2019

This should hopefully fix #15100.

@jameshilliard jameshilliard force-pushed the jameshilliard:getentropy-weak branch 10 times, most recently Jan 4, 2019

@jameshilliard jameshilliard changed the title declare getentropy weak import on osx fix getentropy import check on osx Jan 4, 2019

@jameshilliard jameshilliard force-pushed the jameshilliard:getentropy-weak branch Jan 4, 2019

@jameshilliard

This comment has been minimized.

Copy link
Contributor Author

commented Jan 4, 2019

@DesWurstes Could you build and test this on OSX 10.10 to verify it works as expected, I only have a 10.14 system.

@DesWurstes

This comment has been minimized.

Copy link
Contributor

commented Jan 4, 2019

On my slow computer, I only have Clang 3. I'll install brew, CLT, dependencies and build and test Bitcoin Core. Thus I need 24 hours to test it.

@jameshilliard

This comment has been minimized.

Copy link
Contributor Author

commented Jan 4, 2019

@DesWurstes is it just your 10.10 system that's slow or your 10.14 as well? This should only need to be built on 10.14(but tested on 10.10 of course) since the build system disables getentropy for older SDK's.

@DesWurstes

This comment has been minimized.

Copy link
Contributor

commented Jan 4, 2019

10.10 only. I've verified that this works on 10.10 when compiled with 10.14:

#include <stdio.h>
#include <sys/random.h>
extern int getentropy(void* buffer, size_t size) __attribute__((weak_import));

<<The same main function>>

Is compiling on 10.14 and running on 10.10 enough?

EDIT: Just the snippet.

EDIT: Will test tomorrow.

@jameshilliard

This comment has been minimized.

Copy link
Contributor Author

commented Jan 4, 2019

Is compiling on 10.14 and running on 10.10 enough?

Should be since HAVE_GETENTROPY_RAND shouldn't get defined on 10.10. Did you verify bitcoin core itself works or just the test snippet?

@DesWurstes

This comment has been minimized.

Copy link
Contributor

commented Jan 5, 2019

I can't test it. It needs too much work.
Meanwhile:

  1. Please rename NULL to nullptr. It doesn't change anything, hence we should comply with style guide.

  2. It should check if attribute weak_import is supported by the compiler, and use it if so.

  3. I looked at the header file and noticed that it has extern "C". Please change the prototype to extern "C" int getentropy(void *buffer, size_t size) __attribute__((weak_import));.

Show resolved Hide resolved src/random.cpp Outdated

@jameshilliard jameshilliard force-pushed the jameshilliard:getentropy-weak branch Jan 5, 2019

@jameshilliard

This comment has been minimized.

Copy link
Contributor Author

commented Jan 5, 2019

It should check if attribute weak_import is supported by the compiler, and use it if so.

Does that need to be a configure check?

@practicalswift

This comment has been minimized.

Copy link
Member

commented Jan 5, 2019

@jameshilliard

#ifdef __has_cpp_attribute
#  if __has_cpp_attribute(weak_import)
…
#  endif
#endif

See https://github.com/bitcoin/bitcoin/blob/master/src/attributes.h as an example.

Could that be of any help? :-)

@jameshilliard

This comment has been minimized.

Copy link
Contributor Author

commented Jan 5, 2019

Could that be of any help? :-)

Doesn't seem to detect it correctly.

@jameshilliard

This comment has been minimized.

Copy link
Contributor Author

commented Jan 5, 2019

Do we actually need to add a check there? Unknown attributes only generate warnings right?

@DesWurstes

This comment has been minimized.

Copy link
Contributor

commented Jan 6, 2019

If it is not supported, getentropy should be avoided and it should default to urandom.

__has cpp attributes is only for [[something]] attributes, with brackets.

@practicalswift

This comment has been minimized.

Copy link
Member

commented Jan 6, 2019

@DesWurstes Oh, of course. Sorry for the brain fart. Thanks!

@jameshilliard jameshilliard force-pushed the jameshilliard:getentropy-weak branch to 31d0853 Jan 9, 2019

@jameshilliard

This comment has been minimized.

Copy link
Contributor Author

commented Jan 9, 2019

I added a configure check for weak_import, would be good if someone could test against an OSX compiler without support for __attribute__((weak_import)), I'm not sure where to find one myself.

@fanquake fanquake requested a review from theuni Jan 10, 2019

@laanwj

This comment has been minimized.

Copy link
Member

commented Jan 14, 2019

utACK 31d0853

@jameshilliard jameshilliard force-pushed the jameshilliard:getentropy-weak branch from 31d0853 to a7c7fee Jan 19, 2019

@jameshilliard jameshilliard referenced this pull request Jan 19, 2019

Closed

Getentropy fixes #2

@DesWurstes

This comment has been minimized.

Copy link
Contributor

commented Jan 20, 2019

utACK a7c7fee

Core members, please ACK or merge this before 0.18, or Core won't run on older Macs than 10.12.

@jameshilliard

This comment has been minimized.

Copy link
Contributor Author

commented Jan 20, 2019

Core won't run on older Macs than 10.12.

Is xcode for gitian being bumped to at least version 8 for 0.18? The current xcode version being used AFAIK doesn't have getentropy support so gitian builds would not have the getentropy feature compiled in at all.

@laanwj

This comment has been minimized.

Copy link
Member

commented Jan 24, 2019

Is xcode for gitian being bumped to at least version 8 for 0.18? The current xcode version being used AFAIK doesn't have getentropy support so gitian builds would not have the getentropy feature compiled in at all.

I don't think this needs to block this PR? I mean, getentropy should be handled correctly for user builds, or when the SDK version for gitian is bumped in the future.

@jameshilliard

This comment has been minimized.

Copy link
Contributor Author

commented Jan 24, 2019

I don't think this needs to block this PR?

Yes, it's not something that would block this PR.

@jameshilliard

This comment has been minimized.

Copy link
Contributor Author

commented Feb 28, 2019

Anything holding this up?

@practicalswift

This comment has been minimized.

Copy link
Member

commented Mar 15, 2019

FWIW: I've verified that a disassembly of the bitcoind binary built on a Ubuntu 18.04 machine with this patch applied is identical to a disassembly of the bitcoind binary built against master (as expected).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.