Skip to content

Conversation

fanquake
Copy link
Member

Rather than invasively patching GCC, given we have binutils 2.38 available, we can patch it to flip the default for
-muse-unaligned-vector-move.

A 1 line binutils patch, is much more maintainable than the ~300 line patch into GCC. It's also a slight inprovement in regards to patching out ualigned instructions in the release binaries. For comparison:
Master:

objdump -D bin/*.exe | rg "vmova|vmovdqa|vmovaps|vmovapd|vmovdqa64|vmovdqa32" 
141b8be20: c5 f8 28 1a                 	vmovaps	(%rdx), %xmm3
1420564b3: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)
1403060f3: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)
140792b13: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)
140cb0693: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)
1415ea0f3: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)

This PR:

objdump -D bin/*.exe | rg "vmova|vmovdqa|vmovaps|vmovapd|vmovdqa64|vmovdqa32"
141b8be20: c5 f8 28 1a                 	vmovaps	(%rdx), %xmm3
1420564b3: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)
1403060f3: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)
140792b13: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)
140cb0693: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)

Rather than invasively patching GCC. Given we have binutils 2.38
available, we can patch it to flip the default for
`-muse-unaligned-vector-move`.
@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 10, 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 laanwj
Concept ACK hebasto, theuni

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

@willcl-ark
Copy link
Member

Will this close #28413 ?

@fanquake
Copy link
Member Author

Will this close #28413 ?

Not quite, we don't yet have a check. I'd still like to add one, but given we've still got occurances, we'd currently have to add exceptions in some way.

@hebasto
Copy link
Member

hebasto commented Apr 10, 2024

Concept ACK.

@DrahtBot
Copy link
Contributor

Guix builds (on x86_64)

File commit 3f6a6da
(master)
commit 6dfee95
(master and this pull)
SHA256SUMS.part d5aaa93554d4820d... 6ea962be116fefc0...
*-aarch64-linux-gnu-debug.tar.gz 08e8bbba94777556... 938917e0f7d1d08b...
*-aarch64-linux-gnu.tar.gz 749cf5ff444fabe9... f74a5b9c90c52a3e...
*-arm-linux-gnueabihf-debug.tar.gz b93daca0edcd78ad... 6b758bc6dd65c9b9...
*-arm-linux-gnueabihf.tar.gz bccd9690ed40b22d... cee37bd5a203cebf...
*-arm64-apple-darwin-unsigned.tar.gz fd02e2548e0f1518... bb0f5c0f8b5f6a8e...
*-arm64-apple-darwin-unsigned.zip f1f7c3e990bedb80... fa9c6f5f86c5eb5e...
*-arm64-apple-darwin.tar.gz 44db61fa0d635786... 68b5f5da0d168eeb...
*-powerpc64-linux-gnu-debug.tar.gz ad5bb151cedfa33c... 1919e8e0dcd95aaf...
*-powerpc64-linux-gnu.tar.gz 77ed970ee0d8cc3c... a062cae464528194...
*-riscv64-linux-gnu-debug.tar.gz 4f8a96197351c941... 4be0e49990652167...
*-riscv64-linux-gnu.tar.gz cf4025104b87c312... 7c9a5ff6c6f4e62d...
*-x86_64-apple-darwin-unsigned.tar.gz ac20abdf695deb92... 5ff13a8f0bc3dee0...
*-x86_64-apple-darwin-unsigned.zip 95fce23c931cd999... 52a9e920c8a59704...
*-x86_64-apple-darwin.tar.gz b08e9359b9d83b46... e13ab9d1cb6fdc6e...
*-x86_64-linux-gnu-debug.tar.gz efa0ecb4fc85f75d... 0867644507c37a5a...
*-x86_64-linux-gnu.tar.gz a1963261f8540280... 5e4ad9b118f54c8a...
*.tar.gz 7809f81ee0abf78c... f988dd20d8ac92ef...
guix_build.log 919854cf11856935... 5cd528cd8927416a...
guix_build.log.diff 235af24648504dfa...

@hebasto
Copy link
Member

hebasto commented Apr 11, 2024

My Guix builds:

x86_64
07f97e7479e5a7e1baae091ed74839e9b7be118d0504a8b334c4add8e13c78cc  guix-build-a0dc2ebcda9e/output/aarch64-linux-gnu/SHA256SUMS.part
ee4ab82a42c802dfa1e455e6badb6a49e819c77f03fcaf3568656faa5f69dce4  guix-build-a0dc2ebcda9e/output/aarch64-linux-gnu/bitcoin-a0dc2ebcda9e-aarch64-linux-gnu-debug.tar.gz
f405a168ea3aa2b3a230664381babb406b03680404ebb89e1638f07efa872520  guix-build-a0dc2ebcda9e/output/aarch64-linux-gnu/bitcoin-a0dc2ebcda9e-aarch64-linux-gnu.tar.gz
98c203bb0d8c6a2568160e5fe78982ed7903236ca1d3e4bb795dc20456abeb2c  guix-build-a0dc2ebcda9e/output/arm-linux-gnueabihf/SHA256SUMS.part
8fb565e3352621c69829d3f79b43b3e8b49f62b25495032286eab379731c891a  guix-build-a0dc2ebcda9e/output/arm-linux-gnueabihf/bitcoin-a0dc2ebcda9e-arm-linux-gnueabihf-debug.tar.gz
d04f8d9776afe64fc2981315f1095536c51c7b839be194ee11292cb7f8267854  guix-build-a0dc2ebcda9e/output/arm-linux-gnueabihf/bitcoin-a0dc2ebcda9e-arm-linux-gnueabihf.tar.gz
0063adcf7b45e0e2f1100259383d3d49cd9d0ba1cacf6ff2fce77138805eac0c  guix-build-a0dc2ebcda9e/output/arm64-apple-darwin/SHA256SUMS.part
63029d80ace5e99d6b63dce2f769eafc89add6abe655a887cdb97b3af78e5044  guix-build-a0dc2ebcda9e/output/arm64-apple-darwin/bitcoin-a0dc2ebcda9e-arm64-apple-darwin-unsigned.tar.gz
4f55f46abf8215bff70cff23e9801540e8c2e96244ac897e256bc9561cd4c399  guix-build-a0dc2ebcda9e/output/arm64-apple-darwin/bitcoin-a0dc2ebcda9e-arm64-apple-darwin-unsigned.zip
79749cabf2a63d1c63adbb234fc1e5c0fc16ab585ab16db9cae44457804e8091  guix-build-a0dc2ebcda9e/output/arm64-apple-darwin/bitcoin-a0dc2ebcda9e-arm64-apple-darwin.tar.gz
44e8563638e45987d3d907c0edd53b523b6eee14185e4792cd80bef919625ae4  guix-build-a0dc2ebcda9e/output/dist-archive/bitcoin-a0dc2ebcda9e.tar.gz
8bbb9d79772dfc106b93c4a0842aaa6c48a91271373a970feabefcde504dea78  guix-build-a0dc2ebcda9e/output/powerpc64-linux-gnu/SHA256SUMS.part
c9ea05121871d00764551019429a9e0bef57b4d5a0f46e306f10d905bf50d0c7  guix-build-a0dc2ebcda9e/output/powerpc64-linux-gnu/bitcoin-a0dc2ebcda9e-powerpc64-linux-gnu-debug.tar.gz
90344694399225e88f0654018044e3cdc50693e7dec892ec149af130aab5fb9c  guix-build-a0dc2ebcda9e/output/powerpc64-linux-gnu/bitcoin-a0dc2ebcda9e-powerpc64-linux-gnu.tar.gz
46f008134e0972120e82ea940815ff32349fca0b292455dba4379359445a962c  guix-build-a0dc2ebcda9e/output/riscv64-linux-gnu/SHA256SUMS.part
13c646cea9a8ab44c3942e17ddc6bad348dfb6877092cdb95cc320fc6d02763a  guix-build-a0dc2ebcda9e/output/riscv64-linux-gnu/bitcoin-a0dc2ebcda9e-riscv64-linux-gnu-debug.tar.gz
257f749cd33f01cd271fdbd8e802c66bda83886c98bc89d4fc6045afe02d55a4  guix-build-a0dc2ebcda9e/output/riscv64-linux-gnu/bitcoin-a0dc2ebcda9e-riscv64-linux-gnu.tar.gz
5c1cef450825cbe691a1207cad686bb5cf742a2195cb5da6cdad981a62ff4ac7  guix-build-a0dc2ebcda9e/output/x86_64-apple-darwin/SHA256SUMS.part
bed99cb39f148b057daaeb0420691c9fd22c735013ef4adc415755656e48ddc2  guix-build-a0dc2ebcda9e/output/x86_64-apple-darwin/bitcoin-a0dc2ebcda9e-x86_64-apple-darwin-unsigned.tar.gz
eef9064c217b030651422d0684338e7c920978deed2c3e36da7509d8f5322a8a  guix-build-a0dc2ebcda9e/output/x86_64-apple-darwin/bitcoin-a0dc2ebcda9e-x86_64-apple-darwin-unsigned.zip
2e23e0f4282691a075609ee80022a2262de90a0e5ed88bc3fd7957589643b3f2  guix-build-a0dc2ebcda9e/output/x86_64-apple-darwin/bitcoin-a0dc2ebcda9e-x86_64-apple-darwin.tar.gz
a6c26a0e1abab26bfbfdb48de72be0245c468b0fb2c25bcd7ec67a3e861acf8c  guix-build-a0dc2ebcda9e/output/x86_64-linux-gnu/SHA256SUMS.part
971acc92bcfe937a96a27a5129f9382077c8a89320f7506cd147c9fa14937980  guix-build-a0dc2ebcda9e/output/x86_64-linux-gnu/bitcoin-a0dc2ebcda9e-x86_64-linux-gnu-debug.tar.gz
50c5bbe2a6987cb9bd4f71bb29fdbc1ac593d82a0213c5a198ff7b4d566305f4  guix-build-a0dc2ebcda9e/output/x86_64-linux-gnu/bitcoin-a0dc2ebcda9e-x86_64-linux-gnu.tar.gz
697e56a1c3a7d3c71eabc7104ed3e8d0241352778c9cda046278824a732c77e0  guix-build-a0dc2ebcda9e/output/x86_64-w64-mingw32/SHA256SUMS.part
4011c8ef9948f871ccf40b9ecfec164c6eb5d4af5d94f23bb71bb30c75ca0841  guix-build-a0dc2ebcda9e/output/x86_64-w64-mingw32/bitcoin-a0dc2ebcda9e-win64-debug.zip
c7bf3a072f959791ad6b0cfbd600624f60e06d1fe39c8524560ed047b3d923b7  guix-build-a0dc2ebcda9e/output/x86_64-w64-mingw32/bitcoin-a0dc2ebcda9e-win64-setup-unsigned.exe
3b40301fe84b7ae65b357ffd5329b589f25f84a071affeea1f37652c8f636f3d  guix-build-a0dc2ebcda9e/output/x86_64-w64-mingw32/bitcoin-a0dc2ebcda9e-win64-unsigned.tar.gz
401e8b433f8a5bc6be0bbcc3b237860aad635ae9e2473a7df03bfaebfc365969  guix-build-a0dc2ebcda9e/output/x86_64-w64-mingw32/bitcoin-a0dc2ebcda9e-win64.zip

Author: fanquake <fanquake@gmail.com>
Date: Wed Apr 10 12:15:52 2024 +0200

build: turn on -muse-unaligned-vector-move by default
Copy link
Member

Choose a reason for hiding this comment

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

i think i'm missing something: if this is a build flag, is a patch really needed? Or is this more of a defense-in-depth approach to prevent accidentally forgetting it.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's so we build the whole world / toolchain / depends etc with this option.

@laanwj
Copy link
Member

laanwj commented Apr 11, 2024

Concept ACK, will test

@theuni
Copy link
Member

theuni commented Apr 11, 2024

Concept ACK, looks like a strict improvement.

@laanwj
Copy link
Member

laanwj commented Apr 15, 2024

objdump -D bin/*.exe | rg "vmova|vmovdqa|vmovaps|vmovapd|vmovdqa64|vmovdqa32" 
141b8be20: c5 f8 28 1a                 	vmovaps	(%rdx), %xmm3
1420564b3: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)
1403060f3: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)
140792b13: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)
140cb0693: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)
1415ea0f3: c5 79 29 36                 	vmovapd	%xmm14, (%rsi)> 

i've re-read about the issue and from what i understand these are actually fine-the stack alignment problem is about 32 byte (>=256 bit) alignment. And xmm registers are 16-byte aligned. It would be a problem if ymm or zmm. If so, our check in #28413 could skip these.

@laanwj
Copy link
Member

laanwj commented Apr 16, 2024

  • I get the same output (for windows) as @hebasto
  • I've checked the resulting binaries for instructions that enforce aligned memory accesses, and didn't find any dangerous ones

Code review ACK a0dc2eb

@DrahtBot DrahtBot requested review from hebasto and theuni April 16, 2024 08:20
@fanquake fanquake merged commit 3b70ce2 into bitcoin:master Apr 17, 2024
@fanquake fanquake deleted the guix_patch_binutils_not_gcc branch April 17, 2024 11:22
kwvg added a commit to kwvg/dash that referenced this pull request Nov 4, 2024
kwvg added a commit to kwvg/dash that referenced this pull request Nov 5, 2024
kwvg added a commit to kwvg/dash that referenced this pull request Nov 10, 2024
PastaPastaPasta added a commit to dashpay/dash that referenced this pull request Nov 12, 2024
, bitcoin#28786, bitcoin#29078, bitcoin#27897, bitcoin#29651, bitcoin#29695, bitcoin#29673, bitcoin#29828, bitcoin#29846, bitcoin#30231, bitcoin#30438, partial bitcoin#30511 (guix backports: part 5)

91b7ef8 merge bitcoin#30438: build Linux GCC with --enable-cet (Kittywhiskers Van Gogh)
cfc6cba partial bitcoin#30511: GCC 12 consolidation (Kittywhiskers Van Gogh)
06f5431 merge bitcoin#30231: bump time-machine to f0bb724211872cd6158fce6162e0b8c73efed126 (Kittywhiskers Van Gogh)
5b292ee merge bitcoin#29846: replace GCC unaligned VMOV patch with binutils patch (Kittywhiskers Van Gogh)
4d1f7dc merge bitcoin#29828: remove `gcc-toolchain static` from Windows build (Kittywhiskers Van Gogh)
f321d3d merge bitcoin#29673: use GCC 11 in macOS build env (Kittywhiskers Van Gogh)
d570e2d merge bitcoin#29695: build GCC with --enable-standard-branch-protection (Kittywhiskers Van Gogh)
c965943 merge bitcoin#29651: bump time-machine to dc4842797bfdc5f9f3f5f725bf189c2b68bd6b5a (Kittywhiskers Van Gogh)
59a125a merge bitcoin#27897: use GCC 12.3.0 to build releases (Kittywhiskers Van Gogh)
a701b06 merge bitcoin#29078: Bump guix time-machine to unlock riscv64 metal (Kittywhiskers Van Gogh)
d4b10a3 merge bitcoin#28786: switch to 6.1 kernel headers over 5.15 (Kittywhiskers Van Gogh)
c371870 merge bitcoin#28580: update time-machine (Kittywhiskers Van Gogh)
d36c9b6 merge bitcoin#28759: update signapple to latest master (Kittywhiskers Van Gogh)
38c71d8 merge bitcoin#28370: remove GCC 10 workaround from NSIS (Kittywhiskers Van Gogh)

Pull request description:

  ## Additional Information

  * Dependent on #6382
  * Dependency for #6384

  ## Breaking Changes

  None expected

  ## Checklist

  - [x] I have performed a self-review of my own code
  - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)**
  - [x] I have added or updated relevant unit/integration/functional/e2e tests **(note: N/A)**
  - [x] I have made corresponding changes to the documentation **(note: N/A)**
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  UdjinM6:
    utACK 91b7ef8

Tree-SHA512: 0cfb436a430cf4b624a48a9928ecac9cd5c50e88e51ed04e7d1d0100968af8be1183364f035ac75153781a5e1616aa2f6fadabf0a1c03ec4b66dedea544b77ad
Fabcien added a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 29, 2024
Summary:
```
Rather than invasively patching GCC. Given we have binutils 2.38
available, we can patch it to flip the default for
`-muse-unaligned-vector-move`.
```

Backport of [[bitcoin/bitcoin#29846 | core#29846]].

Depends on D17235.

Test Plan: Run the guix windows build

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D17236
roqqit pushed a commit to doged-io/doged that referenced this pull request Dec 2, 2024
Summary:
```
Rather than invasively patching GCC. Given we have binutils 2.38
available, we can patch it to flip the default for
`-muse-unaligned-vector-move`.
```

Backport of [[bitcoin/bitcoin#29846 | core#29846]].

Depends on D17235.

Test Plan: Run the guix windows build

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D17236
knst added a commit to knst/dash that referenced this pull request Dec 26, 2024
@bitcoin bitcoin locked and limited conversation to collaborators Apr 17, 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