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

build: warn on potentially uninitialized reads #18843

Merged
merged 1 commit into from
May 6, 2020

Conversation

vasild
Copy link
Contributor

@vasild vasild commented May 1, 2020

  • Enable conditional-uninitialized warning class to show potentially uninitialized
    reads.

  • Fix the sole such warning in Bitcoin Core in GetRdRand(): r1 would be
    set to 0 on rdrand failure, so initializing it to 0 is a non-functional
    change.

@brakmic
Copy link
Contributor

brakmic commented May 1, 2020

Code review ACK

@practicalswift
Copy link
Contributor

Concept ACK

@DrahtBot
Copy link
Contributor

DrahtBot commented May 1, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@fanquake
Copy link
Member

fanquake commented May 2, 2020

Please don't bundle unrelated changes like fe466a4 into a PR like this.

r1 would be set to 0 on rdrand failure, so initializing it to 0 is a non-functional change.

Can you at least link to documentation that says this is the case.

@vasild vasild force-pushed the enable_Wconditional-uninitialized branch from d1fa090 to 23faed0 Compare May 3, 2020 14:43
@vasild
Copy link
Contributor Author

vasild commented May 3, 2020

Please don't bundle unrelated changes like fe466a4 into a PR like this.

Sorry for that. I considered it would be ok as long as it is a separate commit and the main change in this PR steps on top of it. Now I submitted that dedup as a separate PR at #18857, removed it from this PR and made this PR to use the old AX_CHECK_COMPILE_FLAG() so that there is no dependency between the two PRs and either one can be merged first. As a result they conflict but it is trivial to resolve - once one of them gets merged (if that happens!) I will adjust the other one.

r1 would be set to 0 on rdrand failure, so initializing it to 0 is a non-functional change.

Can you at least link to documentation that says this is the case.

Done in the commit message:

From "Intel 64 and IA-32 ArchitecturesSoftware Developer's Manual" [1],
page 1711: "CF=1 indicates that the data in the destination is valid.
Otherwise CF=0 and the data in the destination operand will be returned
as zeros for the specified width."

[1] https://software.intel.com/sites/default/files/managed/39/c5/325462-sdm-vol-1-2abcd-3abcd.pdf

Thanks for looking into this!

src/random.cpp Show resolved Hide resolved
Enable -Wconditional-uninitialized to warn on potentially uninitialized
reads.

Fix the sole such warning in Bitcoin Core in GetRdRand(): r1 would be
set to 0 on rdrand failure, so initializing it to 0 is a non-functional
change.

From "Intel 64 and IA-32 ArchitecturesSoftware Developer's Manual" [1],
page 1711: "CF=1 indicates that the data in the destination is valid.
Otherwise CF=0 and the data in the destination operand will be returned
as zeros for the specified width."

[1] https://software.intel.com/sites/default/files/managed/39/c5/325462-sdm-vol-1-2abcd-3abcd.pdf
@vasild vasild force-pushed the enable_Wconditional-uninitialized branch from 23faed0 to 71f183a Compare May 3, 2020 15:22
@vasild
Copy link
Contributor Author

vasild commented May 3, 2020

It would be more readable to use _rdrand64_step() from immintrin.h or __builtin_ia32_rdrand64_step() instead of __asm__ volatile (".byte 0x48, 0x0f, 0xc7, 0xf0; setc %1" : "=a"(r1), "=q"(ok) :: "cc"); reference.

Out of the scope of this PR.

@sipa
Copy link
Member

sipa commented May 3, 2020

@vasild The annoying part about using intrinsics is that they require moving the code to a separate module and compiling it separately. That's because in order to get access to _rdrand64_step(), you need to compile with -mrdrnd, which makes the compiler assume that rdrand is available throughout the entire module (which could in theory cause the compiler to emit such instructions even in cases where it's running on a system that doesn't have that instruction).

@practicalswift
Copy link
Contributor

ACK 71f183a

@laanwj
Copy link
Member

laanwj commented May 6, 2020

ACK 71f183a

@laanwj laanwj merged commit 6621be5 into bitcoin:master May 6, 2020
@vasild vasild deleted the enable_Wconditional-uninitialized branch May 6, 2020 12:10
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 12, 2020
71f183a build: warn on potentially uninitialized reads (Vasil Dimov)

Pull request description:

  * Enable `conditional-uninitialized` warning class to show potentially uninitialized
  reads.

  * Fix the sole such warning in Bitcoin Core in `GetRdRand()`: `r1` would be
  set to `0` on `rdrand` failure, so initializing it to `0` is a non-functional
  change.

ACKs for top commit:
  practicalswift:
    ACK 71f183a
  laanwj:
    ACK 71f183a

Tree-SHA512: 2c1d8caacd86424b16a9d92e5df19e0bedb51ae111eecad7e3bfa46447bc88e5fff1f32dacf6c4a28257ebb3d87e79f80f074ce2c523ce08b1a0c0a67ab44204
ComputerCraftr pushed a commit to ComputerCraftr/bitcoin that referenced this pull request Jun 10, 2020
71f183a build: warn on potentially uninitialized reads (Vasil Dimov)

Pull request description:

  * Enable `conditional-uninitialized` warning class to show potentially uninitialized
  reads.

  * Fix the sole such warning in Bitcoin Core in `GetRdRand()`: `r1` would be
  set to `0` on `rdrand` failure, so initializing it to `0` is a non-functional
  change.

ACKs for top commit:
  practicalswift:
    ACK 71f183a
  laanwj:
    ACK 71f183a

Tree-SHA512: 2c1d8caacd86424b16a9d92e5df19e0bedb51ae111eecad7e3bfa46447bc88e5fff1f32dacf6c4a28257ebb3d87e79f80f074ce2c523ce08b1a0c0a67ab44204
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Apr 8, 2021
Summary:
> Enable -Wconditional-uninitialized to warn on potentially uninitialized reads.
>
> Fix the sole such warning in Bitcoin Core in GetRdRand(): r1 would be
> set to 0 on rdrand failure, so initializing it to 0 is a non-functional
> change.
>
> From "Intel 64 and IA-32 ArchitecturesSoftware Developer's Manual" [1],
> page 1711: "CF=1 indicates that the data in the destination is valid.
> Otherwise CF=0 and the data in the destination operand will be returned
> as zeros for the specified width."
>
> [1] https://software.intel.com/sites/default/files/managed/39/c5/325462-sdm-vol-1-2abcd-3abcd.pdf

This is a backport of Core [[bitcoin/bitcoin#18843 | PR18843]]

Test Plan:
```
cmake .. -GNinja \
    -DCMAKE_C_COMPILER=clang  \
    -DCMAKE_CXX_COMPILER=clang++ \
    -DENABLE_CLANG_TIDY=ON \
    -DCMAKE_C_FLAGS="-Werror"
ninja all check-all
```

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9110
kwvg added a commit to kwvg/dash that referenced this pull request Jun 17, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Jun 17, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Jun 17, 2021
UdjinM6 added a commit to dashpay/dash that referenced this pull request Jun 23, 2021
ogabrielides added a commit to ogabrielides/dash that referenced this pull request Sep 15, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
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.

None yet

8 participants