Skip to content

Conversation

@fanquake
Copy link
Member

@fanquake fanquake commented Jan 8, 2024

Rather than trying to sporadically rely on / override Autoconf default behaviour. Just always override (if unset), and always set the flags we want (which are the same as the Autoconf defaults).

Removes the need for duplicate code to clear (if not overridden) CXXFLAGS.

Fixes cases of "missing" -O2. i.e this PR when running a Valgrind CI job with changes here:

CXXFLAGS        =  -g -O2  -fdebug-prefix-map=$(abs_top_srcdir)=.  -Wstack-protector -fstack-protector-all -mbranch-protection=bti   -Werror  -fsanitize=fuzzer  -gdwarf-4

Fixes configure output to reflect actual compilation flag ordering, so it's useful.

Note that if we do still end up with a duplicate "-g -O2" when compiling, that has no effect, and I don't really thinks it's something worth trying to optimize.

@fanquake fanquake requested review from hebasto, sedited and theuni January 8, 2024 16:56
@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 8, 2024

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK TheCharlatan, hebasto, theuni

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 9, 2024

Guix builds (on x86_64)

File commit c2d04f1
(master)
commit 4f3bd6ff41e7e33aca3fb951aeac40187574e7f4
(master and this pull)
SHA256SUMS.part 4a9ccfd83cb2679a... e00bd10cf1c552ae...
*-aarch64-linux-gnu-debug.tar.gz 4731516310849a25... 6b6142d9edfb481f...
*-aarch64-linux-gnu.tar.gz acc376722c5008ac... 99182f119ce461e4...
*-arm-linux-gnueabihf-debug.tar.gz 27c0ac08bf1e52ec... e8cdae7984b3b71e...
*-arm-linux-gnueabihf.tar.gz f0b4d49bd27eab6f... bce7663712f05abd...
*-arm64-apple-darwin-unsigned.tar.gz aa5defd0392ff711... 6260b903586f1099...
*-arm64-apple-darwin-unsigned.zip 1f3782346e0788fb... 94bfbad8c61f8ed6...
*-arm64-apple-darwin.tar.gz 9158f185342766ec... 34b751095f3789f9...
*-powerpc64-linux-gnu-debug.tar.gz d319c0b5068715a4... d1631b63f16d6781...
*-powerpc64-linux-gnu.tar.gz cf5f1ca24dc9b0ea... ee9238587275333d...
*-powerpc64le-linux-gnu-debug.tar.gz 973602effdc471c7... c0c69fd5d9306991...
*-powerpc64le-linux-gnu.tar.gz 1ac53be19e8814c5... 9e4e26603055fd46...
*-riscv64-linux-gnu-debug.tar.gz b4ca3e5fd9e64c1f... 1cb05ed329bece2d...
*-riscv64-linux-gnu.tar.gz c9ac1a5744a91f9d... 0c0706cef8a27838...
*-x86_64-apple-darwin-unsigned.tar.gz a73b36e47baa7d35... ece0b6e6813d368a...
*-x86_64-apple-darwin-unsigned.zip c4ef03f6f0f9e966... fac30c20be157400...
*-x86_64-apple-darwin.tar.gz a02aa184f82f0486... fd58d8f1fafc9079...
*-x86_64-linux-gnu-debug.tar.gz 69ab336e5f461987... 6d2faee9f85cc86a...
*-x86_64-linux-gnu.tar.gz 93f83237256d1b88... c5282beaad43e3b0...
*.tar.gz c8c797f1406aceb4... e6a1b1736dbe879d...
guix_build.log e74fb88f9dbe8f8e... da7970b296d8170e...
guix_build.log.diff 5047bfe3bc2dfb58...

Copy link
Member

@theuni theuni left a comment

Choose a reason for hiding this comment

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

Concept ACK.

My only hesitation here was: can the user revert back to the default (no flag) behavior if desired. The gcc manpages answer this explicitly:

Level 0 produces no debug information at all. Thus, -g0 negates -g

and

-O0 Reduce compilation time and make debugging produce the expected results. This is the default.

So if the user uses: ./configure CXXFLAGS="-O0 -g0", the build should end up using:
-g -O2 ... -O0 -g0, which gets us back to the same behavior as if no flags were used at all.

@sedited
Copy link
Contributor

sedited commented Jan 9, 2024

Concept ACK

@fanquake fanquake force-pushed the core_cxxflags_always_O2 branch from 8d8855b to e86542e Compare January 10, 2024 13:57
This avoids cases of missing -O2, when *FLAGS has been overriden.
Removes the need for duplicate code to clear autoconf defaults.

Also, move CORE_CXXFLAGS before DEBUG_CXXFLAGS, so that -O2 is always
overriden if debugging etc.
This was being used to avoid a missing -O2. After the previous commits,
this is no-longer an issue.
@fanquake fanquake force-pushed the core_cxxflags_always_O2 branch from e86542e to 00c1e2a Compare January 16, 2024 09:51
@sedited
Copy link
Contributor

sedited commented Jan 17, 2024

Guix builds (x86):

c65c40452ea0c2485c8a17a4d79f4befd2f3f5b66af5281a7833842990a236be  guix-build-00c1e2aa4496/output/aarch64-linux-gnu/SHA256SUMS.part
c027a5f50f2b767a251953eded0cef07adf932f4905e5bd6cb1b19fd013a9f8d  guix-build-00c1e2aa4496/output/aarch64-linux-gnu/bitcoin-00c1e2aa4496-aarch64-linux-gnu-debug.tar.gz
2baa2e82b8af6171b7861e6487fb3c1a07f0b0637e1518fb047d9f0773922781  guix-build-00c1e2aa4496/output/aarch64-linux-gnu/bitcoin-00c1e2aa4496-aarch64-linux-gnu.tar.gz
7452fa6211244d1960795315a2a7292bb9c5ebb5510bfd18fea4f143dfe6f9a1  guix-build-00c1e2aa4496/output/arm-linux-gnueabihf/SHA256SUMS.part
a5160df4bcb278e0df00b2f0b5bfeacf3ab6621bab2e1e4a2dc9e49e8f04a9af  guix-build-00c1e2aa4496/output/arm-linux-gnueabihf/bitcoin-00c1e2aa4496-arm-linux-gnueabihf-debug.tar.gz
b5e7583cf0ac8915971d60abb60395f9edfd3879bf6e15464fc26bbb785e0f2a  guix-build-00c1e2aa4496/output/arm-linux-gnueabihf/bitcoin-00c1e2aa4496-arm-linux-gnueabihf.tar.gz
d89a4870514f1303c5411a4df273ebef942b6f5ab4d04b6f483c47a50ce4356f  guix-build-00c1e2aa4496/output/arm64-apple-darwin/SHA256SUMS.part
b1db6d50a08c8b96752a17cd12310d9103820cbb9edcfb24a4a103115c836c97  guix-build-00c1e2aa4496/output/arm64-apple-darwin/bitcoin-00c1e2aa4496-arm64-apple-darwin-unsigned.tar.gz
16c5657afd564f35cb10f3984ffe50a5235e322a7414a032f94a9de3121ec646  guix-build-00c1e2aa4496/output/arm64-apple-darwin/bitcoin-00c1e2aa4496-arm64-apple-darwin-unsigned.zip
81da4127cda60c8ceb72f99500e92e065c7390ab5803f67a2c3b707c146f5d36  guix-build-00c1e2aa4496/output/arm64-apple-darwin/bitcoin-00c1e2aa4496-arm64-apple-darwin.tar.gz
541ae4853167d1a7928f4bb52903dac4a5b6da439af27077db17a3c4e980b2e9  guix-build-00c1e2aa4496/output/dist-archive/bitcoin-00c1e2aa4496.tar.gz
f9499295b61858074a93e918b857d8c77b645f126b1c9ead4d20a3ca8fed3d3c  guix-build-00c1e2aa4496/output/powerpc64-linux-gnu/SHA256SUMS.part
3ef20afaa28b4382755e00f2f01d8b933e8c602c2bc0a0a50f5ad9a7c1b19012  guix-build-00c1e2aa4496/output/powerpc64-linux-gnu/bitcoin-00c1e2aa4496-powerpc64-linux-gnu-debug.tar.gz
e5caf85e5c02fbe2c21a65478155e225c0be07c3eec70862e9ba3578dfbb02a0  guix-build-00c1e2aa4496/output/powerpc64-linux-gnu/bitcoin-00c1e2aa4496-powerpc64-linux-gnu.tar.gz
abc4042178ac514479f1340b07f5c92fd557e9a5c2dc71f0fe8086d9bfecb233  guix-build-00c1e2aa4496/output/powerpc64le-linux-gnu/SHA256SUMS.part
2b0283f238e11025723d6f1a0d1af3fe3069d35d0968bfef9633cf5bd6dc24b0  guix-build-00c1e2aa4496/output/powerpc64le-linux-gnu/bitcoin-00c1e2aa4496-powerpc64le-linux-gnu-debug.tar.gz
14ce3c4ec2c5f6310faf9e700af667a1ea3a9ecdc5f3633a8fba5865cc32ce7f  guix-build-00c1e2aa4496/output/powerpc64le-linux-gnu/bitcoin-00c1e2aa4496-powerpc64le-linux-gnu.tar.gz
89b139b4c19a817c6bbf307692ebfbcbe558bae3146b99e524a11f5a6750c152  guix-build-00c1e2aa4496/output/riscv64-linux-gnu/SHA256SUMS.part
1b9f0041dea802693cf31198b06466841b036c0be358f9d3f8002ebf7468c18d  guix-build-00c1e2aa4496/output/riscv64-linux-gnu/bitcoin-00c1e2aa4496-riscv64-linux-gnu-debug.tar.gz
149438cc56f310448d9ee3e468352fae707080aeb5dbd36cfea24e7297866fdf  guix-build-00c1e2aa4496/output/riscv64-linux-gnu/bitcoin-00c1e2aa4496-riscv64-linux-gnu.tar.gz
321aadc287d74256d082379efd1061965293275ab683ae21a67d33a1f4975167  guix-build-00c1e2aa4496/output/x86_64-apple-darwin/SHA256SUMS.part
4e9f37bcfbe109392748473c6081fe2842e9c34aac0430dd8f34b17b5ea97e14  guix-build-00c1e2aa4496/output/x86_64-apple-darwin/bitcoin-00c1e2aa4496-x86_64-apple-darwin-unsigned.tar.gz
cc2a2e18ca8a9027d64269c2a4149b197d57147e607373cf410798a20b7b8b82  guix-build-00c1e2aa4496/output/x86_64-apple-darwin/bitcoin-00c1e2aa4496-x86_64-apple-darwin-unsigned.zip
06b945c60e51d89688bab5b8268ca763a094be75f9ee5927ed5c6c85d0d73e3c  guix-build-00c1e2aa4496/output/x86_64-apple-darwin/bitcoin-00c1e2aa4496-x86_64-apple-darwin.tar.gz
576f8bf1f3d554ae1e5c7a87c065fac80b703601bf7b02893fc47d26d5b8009c  guix-build-00c1e2aa4496/output/x86_64-linux-gnu/SHA256SUMS.part
adc8a1e5eda8b456cc1e6288468a732dc02724579b35c53869fbb028071ae839  guix-build-00c1e2aa4496/output/x86_64-linux-gnu/bitcoin-00c1e2aa4496-x86_64-linux-gnu-debug.tar.gz
e64f41c4bd2f5e364f59ef9540a3087bc3ad4f9c8699636b95615a53e8d5462b  guix-build-00c1e2aa4496/output/x86_64-linux-gnu/bitcoin-00c1e2aa4496-x86_64-linux-gnu.tar.gz
410c0435aa0d1df59e0ed829a8887edddc07802c3a2960588d02ddb153275f68  guix-build-00c1e2aa4496/output/x86_64-w64-mingw32/SHA256SUMS.part
ab4e1f86f21e945e8cafaa4b1f69dbde44abead331dd54df4212b460fa15ca3b  guix-build-00c1e2aa4496/output/x86_64-w64-mingw32/bitcoin-00c1e2aa4496-win64-debug.zip
9439627944b4865a891779892710d1bde4327a660837c2bd4d8251654038b4e4  guix-build-00c1e2aa4496/output/x86_64-w64-mingw32/bitcoin-00c1e2aa4496-win64-setup-unsigned.exe
cd3b8e43d2e9c57e0894a8b5a40696be3cfcf9462682a7aebd58d8889556d216  guix-build-00c1e2aa4496/output/x86_64-w64-mingw32/bitcoin-00c1e2aa4496-win64-unsigned.tar.gz
2b3bb6f1b4edcbdf6b798f976b1ef388b9dda86675d9b1fb5adbdb07d9b1dee7  guix-build-00c1e2aa4496/output/x86_64-w64-mingw32/bitcoin-00c1e2aa4496-win64.zip

@sedited
Copy link
Contributor

sedited commented Jan 17, 2024

Why not change the behavior around the CFLAGS as well? That seems a bit confusing to me; we now have one variable that always retains -g -O2 when overriding and another that does not.

EDIT: Looked this over a bit more and doesn't seem to be worth it. The CFLAGS are hardly used, and where they are used in secp, they get applied in essentially the same manner as here.

Copy link
Contributor

@sedited sedited left a comment

Choose a reason for hiding this comment

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

lgtm ACK 00c1e2a

@DrahtBot DrahtBot requested a review from theuni January 18, 2024 08:20
@hebasto
Copy link
Member

hebasto commented Jan 22, 2024

While always overriding Autotools' defaults, are there any particular reasons not using -O3 instead of -O2?

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 00c1e2a, I have reviewed the code and it looks OK. Also tested ci/test/00_setup_env_native_valgrind.sh.

@luke-jr
Copy link
Member

luke-jr commented Jan 23, 2024

While always overriding Autotools' defaults, are there any particular reasons not using -O3 instead of -O2?

AFAIK -O3 isn't safe.

@hebasto
Copy link
Member

hebasto commented Jan 23, 2024

While always overriding Autotools' defaults, are there any particular reasons not using -O3 instead of -O2?

AFAIK -O3 isn't safe.

How?

FWIW, -O3 is used by default in CMake for "Release" builds.

@theuni
Copy link
Member

theuni commented Jan 24, 2024

While always overriding Autotools' defaults, are there any particular reasons not using -O3 instead of -O2?

AFAIK -O3 isn't safe.

I remember these discussions almost 10 years ago when compilers (notably gcc) put aggressive and (iirc?) non-standards-compliant optimizations behind -O3. I'm guessing that's probably not the case anymore these days, but I do agree somewhat with @luke-jr that we'd need to investigate the safety of this before blindly changing.

Either way, it's out of scope for this PR :)

Copy link
Member

@theuni theuni left a comment

Choose a reason for hiding this comment

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

ACK 00c1e2a

Quickly tested with macos + depends, which I consider to be one of our wonkiest builds wrt flags. Looks correct to me with or without overridden CXXFLAGS.

I also think having CORE_CXXFLAGS come first generally makes more sense so that it's always override-able.

@fanquake fanquake merged commit 4ad83ef into bitcoin:master Jan 25, 2024
@fanquake fanquake deleted the core_cxxflags_always_O2 branch January 25, 2024 10:13
@bitcoin bitcoin locked and limited conversation to collaborators Jan 24, 2025
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.

6 participants