Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented May 6, 2019

The gcc compiler creates "optimized" code (-finline-small-functions) that modifies in a second time after it has been initialized with random bits.

Working around the bug can be achieved in different ways: Moving in into a new const array, rearranging the loop to break the optimization, or moving the array into the outer scope, ...

This fix is needed to release 0.18.1 on 32 bit platforms, thus needs backport.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348
Fixes #14580

@luke-jr
Copy link
Member

luke-jr commented May 6, 2019

Wouldn't it be better to just add -fno-inline-small-functions when a broken compiler version is detected? (Isn't this bug liable to affect other random bits of code?)

@laanwj
Copy link
Member

laanwj commented May 6, 2019

Wouldn't it be better to just add -fno-inline-small-functions when a broken compiler version is detected? (Isn't this bug liable to affect other random bits of code?)

The one doesn't rule out the other, though I would personally feel more comfortable with that solution. It's unclear to me what else this bug might potentially affect.

@practicalswift
Copy link
Contributor

practicalswift commented May 6, 2019

Concept ACK on working around the GCC issue but I agree with @luke-jr and @laanwj that introducing -fno-inline-small-functions would be good.

I think we should add -fno-inline-small-functions when building with GCC and keep the code unchanged: that way we will notice if -fno-inline-small-functions is removed prematurely in the future (that is: before these GCC versions have died out).

@maflcko
Copy link
Member Author

maflcko commented May 6, 2019

Ok, marking up for grabs for someone to change the build system.

@maflcko maflcko removed this from the 0.18.1 milestone May 6, 2019
@gmaxwell
Copy link
Contributor

gmaxwell commented May 7, 2019

I would expect -fno-inline-small-functions to be devastating for performance and I also believe would not completely work around the bug. I believe -fstack-reuse=none would be a more correct, and less impacting, workaround.

@luke-jr
Copy link
Member

luke-jr commented May 7, 2019

I wonder if there's a reliable compile test we could have configure run to detect the actual bug?

@maflcko
Copy link
Member Author

maflcko commented May 7, 2019

The test case from the gcc bug wouldn't work? And if disabling fstack-reuse isn't too expensive, we might just do it unconditionally?

@sipa
Copy link
Member

sipa commented May 7, 2019

I would also expect that -fstack-reuse=none has less impact than -fno-inline-small-functions, but benchmarks would be nice.

I'll PR the reproduction bug as a unit test.

@gmaxwell
Copy link
Contributor

gmaxwell commented May 7, 2019

stack-reuse=none also has the advantage of turning some lifetime management bugs into less-bugs (which is AFAICT why the option exists). I would expect it to increase stack usage, which right now we're not currently particularly careful with.

@gmaxwell
Copy link
Contributor

gmaxwell commented May 7, 2019

@luke-jr on reliability, I think we'd be better off detecting versions than trying to use the test case. Unfortunately, it's unclear what versions this will be fixed in: (so far) it appears that this is actually hard for GCC to fix without severely gimping optimization.

FWIW, the test case does not fail on PPC but I am moderately confident that bug exists there (it might be just that the larger redzone on PPC results in a different stack layout).

@laanwj
Copy link
Member

laanwj commented May 8, 2019

Yes, -fstack-reuse=none would be better. Could do it unconditionally for gcc, at least for now. Then when there are versions that patch it, add exceptions.

@maflcko
Copy link
Member Author

maflcko commented May 8, 2019

Thanks everyone for the input, closing in favour of

@maflcko maflcko closed this May 8, 2019
@maflcko maflcko deleted the 1905-gccBugWorkaround branch May 8, 2019 18:22
maflcko pushed a commit that referenced this pull request May 16, 2019
faf38bc build with -fstack-reuse=none (MarcoFalke)

Pull request description:

  All versions of gcc that we commonly use for building are subject to bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348. To work around that, set `-fstack-reuse=none` for all builds. See #15959 (comment)

  This option does not exist for clang https://clang.llvm.org/docs/ClangCommandLineReference.html#target-independent-compilation-options, but it does for gcc https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html

ACKs for commit faf38b:

Tree-SHA512: f5597583402d31ea7b89ac358a6f4a537bbb82a1dde2bd41bac65ee0fd88c7af75ee4c24c6b8eed6b139bf4dbf07ab2987f8fc30fb3eab179cd2d753a8a2a47d
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 1, 2021
faf38bc build with -fstack-reuse=none (MarcoFalke)

Pull request description:

  All versions of gcc that we commonly use for building are subject to bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348. To work around that, set `-fstack-reuse=none` for all builds. See bitcoin#15959 (comment)

  This option does not exist for clang https://clang.llvm.org/docs/ClangCommandLineReference.html#target-independent-compilation-options, but it does for gcc https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html

ACKs for commit faf38b:

Tree-SHA512: f5597583402d31ea7b89ac358a6f4a537bbb82a1dde2bd41bac65ee0fd88c7af75ee4c24c6b8eed6b139bf4dbf07ab2987f8fc30fb3eab179cd2d753a8a2a47d
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 10, 2021
faf38bc build with -fstack-reuse=none (MarcoFalke)

Pull request description:

  All versions of gcc that we commonly use for building are subject to bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348. To work around that, set `-fstack-reuse=none` for all builds. See bitcoin#15959 (comment)

  This option does not exist for clang https://clang.llvm.org/docs/ClangCommandLineReference.html#target-independent-compilation-options, but it does for gcc https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html

ACKs for commit faf38b:

Tree-SHA512: f5597583402d31ea7b89ac358a6f4a537bbb82a1dde2bd41bac65ee0fd88c7af75ee4c24c6b8eed6b139bf4dbf07ab2987f8fc30fb3eab179cd2d753a8a2a47d
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 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.

32-bit test failure: test/crypto_tests.cpp(561): error: in "crypto_tests/sha256d64": check memcmp(out1, out2, 32 * i) == 0 has failed

6 participants