lib: fix a compiler warning: unused GetDevURandom()#17563
lib: fix a compiler warning: unused GetDevURandom()#17563fanquake merged 1 commit intobitcoin:masterfrom
Conversation
|
What warning are you seeing, compiling for which OS? |
src/random.cpp
Outdated
There was a problem hiding this comment.
Concept ACK, but I think there's some redundancy in this experession: at the least, WIN32 will never be set if HAVE_GETENTROPY or HAVE_SYSCTL_ARND.
Edit: oh, that doesn't really help. I still think this is too complex an expression, would be good to have a NEED_DEVURANDOM_FALLBACK or such.
|
See also #13294 for earlier discussion on a similar change (which was eventually dropped from the PR) |
8d2d95d to
6120aa8
Compare
FreeBSD 12.1. @laanwj I agree that the "forest" of ifdef is totally unreadable. I changed the approach to mark the function as possibly unused. After all the compilers provide a way to do that exactly for cases like this. Once we are on C++17, we can use [[maybe_unused]] directly in the code. Before that some magic in src/attributes.h, similarly to |
|
Marking that unused would be a great way to hid an actual bug in the future. Would it be possible to #define a USEGETDEVURANDOM as part of the conditional compilation that makes it unused and ifndef the function out if it won't be used? |
Like what?
I don't think so. We have:
then we have to use the forest of ifdefs from the first iteration of this PR - replicate the same conditions as inside There are also other ways to silence this:
PS this seems to be causing a noise inversely proportional to the complexity of the change. |
|
Just for reference, the warning appears on freebsd 12: https://cirrus-ci.com/task/4881774827536384?command=make#L423 I have no opinion on whether it should be fixed or how. |
6120aa8 to
8a16b9d
Compare
|
Looks good to me now. I don't think the current construction can hide any bug:
ACK 8a16b9d448b90aa5a234dc326ebda45b99b363b7 |
8a16b9d to
ab25e34
Compare
|
Rebased to get appveyor green, its failure was not due to this PR. |
|
I've just opened #18364, which removes |
|
Yes! I will adjust this PR once #18364 makes it to the tree. Thanks! |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
f9f210d doc: fix GetTimeMicros() comment in random.cpp (fanquake) a889711 rand: remove getentropy() fallback for macOS < 10.12 (fanquake) Pull request description: We [no longer support macOS < 10.12](#17550) (our binaries will not run), so remove the fallback for when `getentropy()` wasn't available. From the manpage: ```bash HISTORY The getentropy() function appeared in OSX 10.12 ``` Note that compiling on macOS you'll see a new unused function warning: ```bash random.cpp:256:13: warning: unused function 'GetDevURandom' [-Wunused-function] static void GetDevURandom(unsigned char *ent32) ^ 1 warning generated. ``` This will likely be addressed as part of #17563. ACKs for top commit: vasild: ACK f9f210d (code review, not tested) elichai: utACK f9f210d practicalswift: ACK f9f210d -- patch looks correct laanwj: ACK f9f210d hebasto: ACK f9f210d, tested on macOS 10.13.6: compiled Tree-SHA512: 6bd2a721f23605a8bca0b7b51f42d628ebf92a18e74eb43194331ba745ee449223aff84119892781c40b188c70b75417447f4e390e3d9ac549292de2b1e8b308
ab25e34 to
0bbc4c7
Compare
|
Updated, now that #18364 is in. |
… 10.12 f9f210d doc: fix GetTimeMicros() comment in random.cpp (fanquake) a889711 rand: remove getentropy() fallback for macOS < 10.12 (fanquake) Pull request description: We [no longer support macOS < 10.12](bitcoin#17550) (our binaries will not run), so remove the fallback for when `getentropy()` wasn't available. From the manpage: ```bash HISTORY The getentropy() function appeared in OSX 10.12 ``` Note that compiling on macOS you'll see a new unused function warning: ```bash random.cpp:256:13: warning: unused function 'GetDevURandom' [-Wunused-function] static void GetDevURandom(unsigned char *ent32) ^ 1 warning generated. ``` This will likely be addressed as part of bitcoin#17563. ACKs for top commit: vasild: ACK f9f210d (code review, not tested) elichai: utACK f9f210d practicalswift: ACK f9f210d -- patch looks correct laanwj: ACK f9f210d hebasto: ACK f9f210d, tested on macOS 10.13.6: compiled Tree-SHA512: 6bd2a721f23605a8bca0b7b51f42d628ebf92a18e74eb43194331ba745ee449223aff84119892781c40b188c70b75417447f4e390e3d9ac549292de2b1e8b308
0bbc4c7 to
5d67234
Compare
src/random.cpp
Outdated
There was a problem hiding this comment.
I don't know if I like effectively duplicating the which-random-source-to-use logic in macro statements. It feels like this too risks overlooking things.
One possibility is adding a (void)GetDevURandom; line in the exact places where we know that no /dev/urandom is needed (but only there, so that it doesn't silence an unintended lack of invocation). Such a statement will also silence the warning, and since the method is static, if it's unused, it still won't be included in the object code.
There was a problem hiding this comment.
Ok, another ingenious way to silence this warning. The previous one did not gain traction for a few months, so lets see if this one flies. Updated the patch.
I confirm that the warning is gone and that the symbol is not included in the object code with -O1 or higher. It is included with -O0 or in the absence of any -O... option but this is fine.
``` random.cpp:255:13: error: unused function 'GetDevURandom' [-Werror,-Wunused-function] ``` Clang 9.0.0, FreeBSD 12.1 Silence by planting a dummy reference to the `GetDevURandom` symbol in the places where we don't call the function.
5d67234 to
ca2e474
Compare
|
I started working on a similar change to remove the warning on macOS, then remembered we had this PR. Will test shortly; if this is the way everyone is happy to solve the issue, let get this in. |
|
This can be silenced in a few different ways. I am fine with either one, as long as it gets fixed. @sipa, what do you think about the last incarnation of this patch? I changed it according to your suggestion at #17563 (comment) |
|
ACK ca2e474 -- increased signal to noise in compiler diagnostics is good |
|
utACK ca2e474 |
|
@fanquake Anything left to do here since your last comment? |
ca2e474 Fix a compiler warning: unused GetDevURandom() (Vasil Dimov) Pull request description: ~~Only define GetDevURandom() if it is going to be used.~~ Silence by planting a dummy reference to the `GetDevURandom` symbol in the places where we don't call the function. ACKs for top commit: practicalswift: ACK ca2e474 -- increased signal to noise in compiler diagnostics is good sipa: utACK ca2e474 hebasto: re-ACK ca2e474, tested on macOS 10.15.6 + llvm clang 10.0.0 Tree-SHA512: 03c98f00dad5d9a3c5c9f68553d72ad5489ec02f18b9769108a22003ec7be7819a731b1eab6a9f64dafb5be0efddccf6980de7e3bb90cd20d4f4d72f74124675
|
just wanna say thanks for this! that warning was annoying. |
… 10.12 f9f210d doc: fix GetTimeMicros() comment in random.cpp (fanquake) a889711 rand: remove getentropy() fallback for macOS < 10.12 (fanquake) Pull request description: We [no longer support macOS < 10.12](bitcoin#17550) (our binaries will not run), so remove the fallback for when `getentropy()` wasn't available. From the manpage: ```bash HISTORY The getentropy() function appeared in OSX 10.12 ``` Note that compiling on macOS you'll see a new unused function warning: ```bash random.cpp:256:13: warning: unused function 'GetDevURandom' [-Wunused-function] static void GetDevURandom(unsigned char *ent32) ^ 1 warning generated. ``` This will likely be addressed as part of bitcoin#17563. ACKs for top commit: vasild: ACK f9f210d (code review, not tested) elichai: utACK f9f210d practicalswift: ACK f9f210d -- patch looks correct laanwj: ACK f9f210d hebasto: ACK f9f210d, tested on macOS 10.13.6: compiled Tree-SHA512: 6bd2a721f23605a8bca0b7b51f42d628ebf92a18e74eb43194331ba745ee449223aff84119892781c40b188c70b75417447f4e390e3d9ac549292de2b1e8b308
ca2e474 Fix a compiler warning: unused GetDevURandom() (Vasil Dimov) Pull request description: ~~Only define GetDevURandom() if it is going to be used.~~ Silence by planting a dummy reference to the `GetDevURandom` symbol in the places where we don't call the function. ACKs for top commit: practicalswift: ACK ca2e474 -- increased signal to noise in compiler diagnostics is good sipa: utACK ca2e474 hebasto: re-ACK ca2e474, tested on macOS 10.15.6 + llvm clang 10.0.0 Tree-SHA512: 03c98f00dad5d9a3c5c9f68553d72ad5489ec02f18b9769108a22003ec7be7819a731b1eab6a9f64dafb5be0efddccf6980de7e3bb90cd20d4f4d72f74124675
ca2e474 Fix a compiler warning: unused GetDevURandom() (Vasil Dimov) Pull request description: ~~Only define GetDevURandom() if it is going to be used.~~ Silence by planting a dummy reference to the `GetDevURandom` symbol in the places where we don't call the function. ACKs for top commit: practicalswift: ACK ca2e474 -- increased signal to noise in compiler diagnostics is good sipa: utACK ca2e474 hebasto: re-ACK ca2e474, tested on macOS 10.15.6 + llvm clang 10.0.0 Tree-SHA512: 03c98f00dad5d9a3c5c9f68553d72ad5489ec02f18b9769108a22003ec7be7819a731b1eab6a9f64dafb5be0efddccf6980de7e3bb90cd20d4f4d72f74124675
Summary: > ``` > random.cpp:255:13: error: unused function 'GetDevURandom' [-Werror,-Wunused-function] > > ``` > > Clang 9.0.0, FreeBSD 12.1 > > Silence by planting a dummy reference to the `GetDevURandom` symbol > in the places where we don't call the function. We see the same warnings in our CI logs. This is a backport of [[bitcoin/bitcoin#17563 | core#17563]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D10090
Only define GetDevURandom() if it is going to be used.Silence by planting a dummy reference to the
GetDevURandomsymbolin the places where we don't call the function.