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

Fixed O3 replacement #1555

Merged
merged 1 commit into from
Jun 29, 2024
Merged

Conversation

EduMenges
Copy link
Contributor

@EduMenges EduMenges commented Jun 27, 2024

Old replacement of O3 in CMAKE_C_FLAGS_RELEASE skip spaces, which is problematic. For instance, if CMAKE_C_FLAGS_RELEASE = "-O3 -DFOO", regex will replace it with -O2-DFOO, which causes a compile error.

This patch changes this behavior, keeping whichever space exists between the flags.

If I may question, what is the rationale behind replacing O3 with O2? Changing the user's flags is a bad practice overall, and I don't see how this replacement is beneficial.

@real-or-random
Copy link
Contributor

cc @hebasto

Thanks for the PR.

If I may question, what is the rationale behind replacing O3 with O2? Changing the user's flags is a bad practice overall, and I don't see how this replacement is beneficial.

We strongly recommend -O2. It turns out that -O3 is often not faster for our code. Even if it is slightly faster, we believe that -O2 is the better trade-off between performance and the risk of miscompilations, which, for a cryptographic library, includes the compiler adding branches to code which was supposed to be constant-time to avoid timing side channels. That's why also why almost all of our testing and assurance goes into -O2.

But we believe that the user should have the last word, of course. We give you a variable SECP256K1_APPEND_CFLAGS (still called SECP256K1_LATE_CFLAGS in the latest release) to overrule any flag.

@EduMenges
Copy link
Contributor Author

Ok Tim, thanks for clarifying it.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 4692294.

Changing the user's flags is a bad practice overall...

This can be resolved by using CMAKE_USER_MAKE_RULES_OVERRIDE_C. Feel free to pick hebasto@90d8760 :)

CMakeLists.txt Outdated Show resolved Hide resolved
@hebasto
Copy link
Member

hebasto commented Jun 27, 2024

CI fails:

CMake Error at CMakeLists.txt:188 (string):
  string sub-command REGEX, mode REPLACE failed to compile regex "-O3(
  |$)*)".

gatleas17

This comment was marked as spam.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK b8fe333.

@real-or-random real-or-random merged commit a526937 into bitcoin-core:master Jun 29, 2024
116 checks passed
vmta added a commit to umkoin/umkoin that referenced this pull request Jul 3, 2024
a5269373f Merge bitcoin-core/secp256k1#1555: Fixed O3 replacement
b8fe33332 cmake: Fixed O3 replacement
4af241b32 Merge bitcoin-core/secp256k1#1535: build: Replace hardcoded "auto" value with default one
f473c959f Merge bitcoin-core/secp256k1#1543: cmake: Do not modify build types when integrating by downstream project
d403eea48 Merge bitcoin-core/secp256k1#1546: cmake: Rename `SECP256K1_LATE_CFLAGS` and switch to Bitcoin Core's approach
d7ae25ce6 Merge bitcoin-core/secp256k1#1550: fix: typos in secp256k1.c
0e2fadb20 fix: typos in secp256k1.c
69b2192ad Merge bitcoin-core/secp256k1#1545: cmake: Do not set `CTEST_TEST_TARGET_ALIAS`
5dd637f3c Merge bitcoin-core/secp256k1#1548: README: mention ellswift module
7454a5373 README: mention ellswift module
4706be2cd cmake: Reimplement `SECP256K1_APPEND_CFLAGS` using Bitcoin Core approach
c2764dbb9 cmake: Rename `SECP256K1_LATE_CFLAGS` to `SECP256K1_APPEND_CFLAGS`
f87a3589f cmake: Do not set `CTEST_TEST_TARGET_ALIAS`
158f9e5ea cmake: Do not modify build types when integrating by downstream project
35c0fdc86 Merge bitcoin-core/secp256k1#1529: cmake: Fix cache issue when integrating by downstream project
4392f0f71 Merge bitcoin-core/secp256k1#1533: tests: refactor: tidy up util functions (#1491)
bedffd53d Merge bitcoin-core/secp256k1#1488: ci: Add native macOS arm64 job
4b8d5eeac Merge bitcoin-core/secp256k1#1532: cmake: Disable eager MSan in ctime_tests
f55703ba4 autotools: Delete unneeded compiler test
396e88588 autotools: Align MSan checking code with CMake's implementation
abde59f52 cmake: Report more compiler details in summary
7abf979a4 cmake: Disable `ctime_tests` if build with `-fsanitize=memory`
4d9645bee cmake: Remove "AUTO" value of `SECP256K1_ECMULT_GEN_KB` option
a06805ee7 cmake: Remove "AUTO" value of `SECP256K1_ECMULT_WINDOW_SIZE` option
1791f6fce Merge bitcoin-core/secp256k1#1517: autotools: Disable eager MSan in ctime_tests
26b94ee92 autotools: Remove "auto" value of `--with-ecmult-gen-kb` option
122dbaeb3 autotools: Remove "auto" value of `--with-ecmult-window` option
e73f6f8fd tests: refactor: drop `secp256k1_` prefix from testrand.h functions
0ee7453a9 tests: refactor: add `testutil_` prefix to testutil.h functions
0c6bc76dc tests: refactor: move `random_` helpers from tests.c to testutil.h
0fef8479b tests: refactor: rename `random_field_element_magnitude` -> `random_fe_magnitude`
59db007f0 tests: refactor: rename `random_group_element_...` -> `random_ge_...`
ebfb82ee2 ci: Add job with -fsanitize-memory-param-retval
e1bef0961 configure: Move "experimental" warning to bottom
55e5d975d autotools: Disable eager MSan in ctime_tests
ec4c002fa cmake: Simplify `PROJECT_IS_TOP_LEVEL` emulation
cae9a7ad1 cmake: Do not set emulated PROJECT_IS_TOP_LEVEL as cache variable
218f0cc93 ci: Add native macOS arm64 job

git-subtree-dir: src/secp256k1
git-subtree-split: a5269373fa13ff845f654d81b90629dd78495641
josibake added a commit to josibake/bitcoin that referenced this pull request Jul 10, 2024
a31a105e6d ci: enable silentpayments module
ef597945b2 tests: add BIP-352 test vectors
1367b8da7e silentpayments: add benchmark for `scan_outputs`
c71791c629 silentpayments: add examples/silentpayments.c
88d24c3b09 silentpayments: receiving
a18f000686 silentpayments: recipient label support
30c4f29f2b silentpayments: sending
96f42bb756 tests: add harness, constants
72337d5b34 build: add skeleton for new silentpayments (BIP352) module
a5269373fa Merge bitcoin-core/secp256k1#1555: Fixed O3 replacement
b8fe33332b cmake: Fixed O3 replacement

git-subtree-dir: src/secp256k1
git-subtree-split: a31a105e6dd9446be7694226fac0e8e7bfafe300
josibake added a commit to josibake/bitcoin that referenced this pull request Jul 15, 2024
0c63b8b191 automagically regenerate if testvectors change
a61335f2e5 ci: enable silentpayments module
0b6827182d tests: add BIP-352 test vectors
1858c33c55 silentpayments: add benchmark for `scan_outputs`
816796300a silentpayments: add examples/silentpayments.c
c1f85840dc silentpayments: receiving
2fb3ca6efe silentpayments: recipient label support
605096d3f4 silentpayments: sending
35f91359b8 build: add skeleton for new silentpayments (BIP352) module
0055b86780 Merge bitcoin-core/secp256k1#1551: Add ellswift usage example
ea2d5f0f17 Merge bitcoin-core/secp256k1#1563: doc: Add convention for defaults
ca06e58b2c Merge bitcoin-core/secp256k1#1564: build, ci: Adjust the default size of the precomputed table for signing
e2af491263 ci: Switch to the new default value of the precomputed table for signing
d94a9273f8 build: Adjust the default size of the precomputed table for signing
fcc5d7381b Merge bitcoin-core/secp256k1#1565: cmake: Bump CMake minimum required version up to 3.16
9420eece24 cmake: Bump CMake minimum required version up to 3.16
16685649d2 doc: Add convention for defaults
a5269373fa Merge bitcoin-core/secp256k1#1555: Fixed O3 replacement
b8fe33332b cmake: Fixed O3 replacement
31f84595c4 Add ellswift usage example
fe4fbaa7f3 examples: fix case typos in secret clearing paragraphs (s/, Or/, or/)

git-subtree-dir: src/secp256k1
git-subtree-split: 0c63b8b1911ef1183f411a5e232165b543c668ea
josibake added a commit to josibake/bitcoin that referenced this pull request Jul 15, 2024
00b0cb19a9 docs: update README
54b8bc8ec6 ci: enable silentpayments module
96bd71fb8a tests: add BIP-352 test vectors
c30bc013fe silentpayments: add benchmark for `scan_outputs`
91b1b3365b silentpayments: add examples/silentpayments.c
b4475ea80c silentpayments: receiving
23c7aead63 silentpayments: recipient label support
79562d0cd1 silentpayments: sending
35f91359b8 build: add skeleton for new silentpayments (BIP352) module
0055b86780 Merge bitcoin-core/secp256k1#1551: Add ellswift usage example
ea2d5f0f17 Merge bitcoin-core/secp256k1#1563: doc: Add convention for defaults
ca06e58b2c Merge bitcoin-core/secp256k1#1564: build, ci: Adjust the default size of the precomputed table for signing
e2af491263 ci: Switch to the new default value of the precomputed table for signing
d94a9273f8 build: Adjust the default size of the precomputed table for signing
fcc5d7381b Merge bitcoin-core/secp256k1#1565: cmake: Bump CMake minimum required version up to 3.16
9420eece24 cmake: Bump CMake minimum required version up to 3.16
16685649d2 doc: Add convention for defaults
a5269373fa Merge bitcoin-core/secp256k1#1555: Fixed O3 replacement
b8fe33332b cmake: Fixed O3 replacement
31f84595c4 Add ellswift usage example
fe4fbaa7f3 examples: fix case typos in secret clearing paragraphs (s/, Or/, or/)

git-subtree-dir: src/secp256k1
git-subtree-split: 00b0cb19a97718dfaab70aa7505ff157f22a31bd
fanquake added a commit to fanquake/bitcoin that referenced this pull request Aug 2, 2024
642c885b61 Merge bitcoin-core/secp256k1#1575: release: prepare for 0.5.1
cdf08c1a2b Merge bitcoin-core/secp256k1#1576: doc: mention `needs-changelog` github label in release process
40d87b8e45 release: prepare for 0.5.1
5770226176 changelog: clarify CMake option
759bd4bbc8 doc: mention `needs-changelog` github label in release process
fded437c4c Merge bitcoin-core/secp256k1#1574: Fix compilation when extrakeys module isn't enabled
763d938cf0 ci: only enable extrakeys module when schnorrsig is enabled
af551ab9db tests: do not use functions from extrakeys module
0055b86780 Merge bitcoin-core/secp256k1#1551: Add ellswift usage example
ea2d5f0f17 Merge bitcoin-core/secp256k1#1563: doc: Add convention for defaults
ca06e58b2c Merge bitcoin-core/secp256k1#1564: build, ci: Adjust the default size of the precomputed table for signing
e2af491263 ci: Switch to the new default value of the precomputed table for signing
d94a9273f8 build: Adjust the default size of the precomputed table for signing
fcc5d7381b Merge bitcoin-core/secp256k1#1565: cmake: Bump CMake minimum required version up to 3.16
9420eece24 cmake: Bump CMake minimum required version up to 3.16
16685649d2 doc: Add convention for defaults
a5269373fa Merge bitcoin-core/secp256k1#1555: Fixed O3 replacement
b8fe33332b cmake: Fixed O3 replacement
31f84595c4 Add ellswift usage example
fe4fbaa7f3 examples: fix case typos in secret clearing paragraphs (s/, Or/, or/)

git-subtree-dir: src/secp256k1
git-subtree-split: 642c885b6102725e25623738529895a95addc4f4
fanquake added a commit to bitcoin/bitcoin that referenced this pull request Aug 6, 2024
9ec776a Revert "build: pass --with-ecmult-gen-kb=86 to secp256k1" (fanquake)
41797f8 Squashed 'src/secp256k1/' changes from 4af241b320..642c885b61 (fanquake)

Pull request description:

  Updates the libsecp256k1 subtree to bitcoin-core/secp256k1@642c885 (which is the tag for the [`v0.5.1` release](https://github.com/bitcoin-core/secp256k1/releases/tag/v0.5.1)).
  Includes a handful of changes:
  * bitcoin-core/secp256k1#1551
  * bitcoin-core/secp256k1#1555
  * bitcoin-core/secp256k1#1563
  * bitcoin-core/secp256k1#1564
  * bitcoin-core/secp256k1#1565
  * bitcoin-core/secp256k1#1574

  Reverts a057869 given secps default has changed (bitcoin-core/secp256k1#1563):
  > As a rule of thumb, the default values for configuration options should target standard desktop machines and align with Bitcoin Core's defaults, and the tests should mostly exercise the default configuration (see [#1549](bitcoin-core/secp256k1#1549 (comment))).

ACKs for top commit:
  hebasto:
    ACK 9ec776a, I've reproduced the subtree update locally with the zero diff with this PR branch.

Tree-SHA512: 903ca0ff12dcc32b6cd86aee84e19de09803d35a1ee006ce890f3761dd27f1e96fe70c7bb4c279416a96ee57c406c9627614900f0ca6f76674c0088a3d270cd2
vmta added a commit to umkoin/umkoin that referenced this pull request Sep 6, 2024
a5269373f Merge bitcoin-core/secp256k1#1555: Fixed O3 replacement
b8fe33332 cmake: Fixed O3 replacement
4af241b32 Merge bitcoin-core/secp256k1#1535: build: Replace hardcoded "auto" value with default one
f473c959f Merge bitcoin-core/secp256k1#1543: cmake: Do not modify build types when integrating by downstream project
d403eea48 Merge bitcoin-core/secp256k1#1546: cmake: Rename `SECP256K1_LATE_CFLAGS` and switch to Bitcoin Core's approach
d7ae25ce6 Merge bitcoin-core/secp256k1#1550: fix: typos in secp256k1.c
0e2fadb20 fix: typos in secp256k1.c
69b2192ad Merge bitcoin-core/secp256k1#1545: cmake: Do not set `CTEST_TEST_TARGET_ALIAS`
5dd637f3c Merge bitcoin-core/secp256k1#1548: README: mention ellswift module
7454a5373 README: mention ellswift module
4706be2cd cmake: Reimplement `SECP256K1_APPEND_CFLAGS` using Bitcoin Core approach
c2764dbb9 cmake: Rename `SECP256K1_LATE_CFLAGS` to `SECP256K1_APPEND_CFLAGS`
f87a3589f cmake: Do not set `CTEST_TEST_TARGET_ALIAS`
158f9e5ea cmake: Do not modify build types when integrating by downstream project
35c0fdc86 Merge bitcoin-core/secp256k1#1529: cmake: Fix cache issue when integrating by downstream project
4392f0f71 Merge bitcoin-core/secp256k1#1533: tests: refactor: tidy up util functions (#1491)
bedffd53d Merge bitcoin-core/secp256k1#1488: ci: Add native macOS arm64 job
4b8d5eeac Merge bitcoin-core/secp256k1#1532: cmake: Disable eager MSan in ctime_tests
f55703ba4 autotools: Delete unneeded compiler test
396e88588 autotools: Align MSan checking code with CMake's implementation
abde59f52 cmake: Report more compiler details in summary
7abf979a4 cmake: Disable `ctime_tests` if build with `-fsanitize=memory`
4d9645bee cmake: Remove "AUTO" value of `SECP256K1_ECMULT_GEN_KB` option
a06805ee7 cmake: Remove "AUTO" value of `SECP256K1_ECMULT_WINDOW_SIZE` option
1791f6fce Merge bitcoin-core/secp256k1#1517: autotools: Disable eager MSan in ctime_tests
26b94ee92 autotools: Remove "auto" value of `--with-ecmult-gen-kb` option
122dbaeb3 autotools: Remove "auto" value of `--with-ecmult-window` option
e73f6f8fd tests: refactor: drop `secp256k1_` prefix from testrand.h functions
0ee7453a9 tests: refactor: add `testutil_` prefix to testutil.h functions
0c6bc76dc tests: refactor: move `random_` helpers from tests.c to testutil.h
0fef8479b tests: refactor: rename `random_field_element_magnitude` -> `random_fe_magnitude`
59db007f0 tests: refactor: rename `random_group_element_...` -> `random_ge_...`
ebfb82ee2 ci: Add job with -fsanitize-memory-param-retval
e1bef0961 configure: Move "experimental" warning to bottom
55e5d975d autotools: Disable eager MSan in ctime_tests
ec4c002fa cmake: Simplify `PROJECT_IS_TOP_LEVEL` emulation
cae9a7ad1 cmake: Do not set emulated PROJECT_IS_TOP_LEVEL as cache variable
218f0cc93 ci: Add native macOS arm64 job

git-subtree-dir: src/secp256k1
git-subtree-split: a5269373fa13ff845f654d81b90629dd78495641
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants