Skip to content

Fix docs about uninitialized bytes #5

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

Merged
merged 1 commit into from
Feb 26, 2022
Merged

Fix docs about uninitialized bytes #5

merged 1 commit into from
Feb 26, 2022

Conversation

taiki-e
Copy link
Owner

@taiki-e taiki-e commented Feb 26, 2022

Based on the feedback from @RalfJung.

@taiki-e taiki-e mentioned this pull request Feb 26, 2022
@@ -18,7 +18,7 @@ See [P1478R1][p1478r1] for more.
- If the alignment of the type being copied is the same as the pointer width, `atomic_load` is possible to produce an assembly roughly equivalent to the case of using volatile read + atomic fence on many platforms. (e.g., [aarch64](https://github.com/taiki-e/atomic-memcpy/blob/HEAD/tests/asm-test/asm/aarch64-unknown-linux-gnu/atomic_memcpy_load_align8), [riscv64](https://github.com/taiki-e/atomic-memcpy/blob/main/tests/asm-test/asm/riscv64gc-unknown-linux-gnu/atomic_memcpy_load_align8). See [`tests/asm-test/asm`][asm-test] directory for more).
- If the alignment of the type being copied is smaller than the pointer width, there will be some performance degradation. However, it is implemented in such a way that it does not cause extreme performance degradation at least on x86_64. (See [the implementation comments of `atomic_load`][implementation] for more.) It is possible that there is still room for improvement, especially on non-x86_64 platforms.
- Optimization for the case where the alignment of the type being copied is larger than the pointer width has not yet been fully investigated. It is possible that there is still room for improvement, especially on 32-bit platforms where `AtomicU64` is available.
- If the type being copied contains uninitialized bytes (e.g., padding), it is incompatible with `-Zmiri-check-number-validity`. This will probably not be resolved until something like `AtomicMaybeUninit` is supported. **Note:** Due to [Miri does not track uninitialized bytes on a per byte basis for partially initialized scalars][rust-lang/rust#69488], Miri may report this case as an access to an uninitialized byte, regardless of whether the uninitialized byte is actually accessed or not.
- If the type being copied contains uninitialized bytes (e.g., padding) [it is undefined behavior because the copy goes through integers][undefined-behavior]. This problem will probably not be resolved until something like `AtomicMaybeUninit` is supported.
Copy link
Owner Author

@taiki-e taiki-e Feb 26, 2022

Choose a reason for hiding this comment

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

I suppose the currently available (sound) workaround is to use inline assembly (#6), but that's hard to write/maintain, and not compatible with Miri (and sanitizers).

Choose a reason for hiding this comment

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

Yeah...

The new text LGTM!

@taiki-e
Copy link
Owner Author

taiki-e commented Feb 26, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 26, 2022

Build succeeded:

@bors bors bot merged commit ee987b5 into main Feb 26, 2022
@bors bors bot deleted the doc branch February 26, 2022 09:58
taiki-e added a commit that referenced this pull request Feb 2, 2025
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==3334==ERROR: AddressSanitizer: SEGV on unknown address 0x02000d2ef240 (pc 0x555e01b0afc7 bp 0x7ffc430de1b0 sp 0x7ffc430de100 T0)
==3334==The signal is caused by a READ memory access.
    #0 0x555e01b0afc7  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-04c46d82177f025f+0x186fc7) (BuildId: 29923f56aa27c9d06e08f73052eb3efbd82fedaf)
    #1 0x7fdf4de2a1c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
    #2 0x7fdf4de2a28a  (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
    #3 0x555e01a56014  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-04c46d82177f025f+0xd2014) (BuildId: 29923f56aa27c9d06e08f73052eb3efbd82fedaf)

==3334==Register values:
rax = 0x000001ff8d2f7240  rbx = 0x00007ffc430de100  rcx = 0x0000000000000000  rdx = 0x000000008fff6fff
rdi = 0x00007fdf4be09010  rsi = 0x0000000000000000  rbp = 0x00007ffc430de1b0  rsp = 0x00007ffc430de100
 r8 = 0x00000ffc697b9200   r9 = 0x0000000000000000  r10 = 0xafffff00000fff01  r11 = 0x4000000000000000
r12 = 0x00007ffc430de2d8  r13 = 0x0000000000000001  r14 = 0x00007fdf4be09000  r15 = 0x00000ffbe97c1200
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-04c46d82177f025f+0x186fc7) (BuildId: 29923f56aa27c9d06e08f73052eb3efbd82fedaf)
==3334==ABORTING
error: test failed, to rerun pass `-p atomic-memcpy --lib`

Caused by:
  process didn't exit successfully: `/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-04c46d82177f025f` (exit status: 1)
note: test exited abnormally; to see the full output pass --nocapture to the harness.
```

```
MemorySanitizer init done
MemorySanitizer:DEADLYSIGNAL
==3315==ERROR: MemorySanitizer: SEGV on unknown address 0x6fff3618a3d8 (pc 0x55a3c90d218a bp 0x000000000000 sp 0x7fff3618a1b0 T3315)
==3315==The signal is caused by a READ memory access.
    #0 0x55a3c90d218a  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158+0x15f18a) (BuildId: eb746f488bb9238cde720cedbf7039f80464d20d)
    #1 0x55a3c90d1b56  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158+0x15eb56) (BuildId: eb746f488bb9238cde720cedbf7039f80464d20d)
    #2 0x55a3c903f0ec  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158+0xcc0ec) (BuildId: eb746f488bb9238cde720cedbf7039f80464d20d)
    #3 0x7fd98962a1c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
    #4 0x7fd98962a28a  (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
    #5 0x55a3c8fcc214  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158+0x59214) (BuildId: eb746f488bb9238cde720cedbf7039f80464d20d)

==3315==Register values:
rax = 0x0000000080000003  rbx = 0x0000500000000000  rcx = 0x00006fff3618a3d8  rdx = 0x0000100000000000
rdi = 0x00007fff3618a3d0  rsi = 0x00002fff3618a3d0  rbp = 0x0000000000000000  rsp = 0x00007fff3618a1b0
 r8 = 0x00006fff3618a3d0   r9 = 0x0000000000000000  r10 = 0x000055a3c8f8f0bf  r11 = 0x0000000000000206
r12 = 0x0000500000000000  r13 = 0x00002fff3618a3a0  r14 = 0x00007fff3618a3d0  r15 = 0xffffffffffffef60
MemorySanitizer can not provide additional info.
SUMMARY: MemorySanitizer: SEGV (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158+0x15f18a) (BuildId: eb746f488bb9238cde720cedbf7039f80464d20d)
==3315==ABORTING
error: test failed, to rerun pass `-p atomic-memcpy --lib`

Caused by:
  process didn't exit successfully: `/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158` (exit status: 1)
note: test exited abnormally; to see the full output pass --nocapture to the harness.
```
taiki-e added a commit that referenced this pull request Feb 2, 2025
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==3334==ERROR: AddressSanitizer: SEGV on unknown address 0x02000d2ef240 (pc 0x555e01b0afc7 bp 0x7ffc430de1b0 sp 0x7ffc430de100 T0)
==3334==The signal is caused by a READ memory access.
    #0 0x555e01b0afc7  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-04c46d82177f025f+0x186fc7) (BuildId: 29923f56aa27c9d06e08f73052eb3efbd82fedaf)
    #1 0x7fdf4de2a1c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
    #2 0x7fdf4de2a28a  (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
    #3 0x555e01a56014  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-04c46d82177f025f+0xd2014) (BuildId: 29923f56aa27c9d06e08f73052eb3efbd82fedaf)

==3334==Register values:
rax = 0x000001ff8d2f7240  rbx = 0x00007ffc430de100  rcx = 0x0000000000000000  rdx = 0x000000008fff6fff
rdi = 0x00007fdf4be09010  rsi = 0x0000000000000000  rbp = 0x00007ffc430de1b0  rsp = 0x00007ffc430de100
 r8 = 0x00000ffc697b9200   r9 = 0x0000000000000000  r10 = 0xafffff00000fff01  r11 = 0x4000000000000000
r12 = 0x00007ffc430de2d8  r13 = 0x0000000000000001  r14 = 0x00007fdf4be09000  r15 = 0x00000ffbe97c1200
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-04c46d82177f025f+0x186fc7) (BuildId: 29923f56aa27c9d06e08f73052eb3efbd82fedaf)
==3334==ABORTING
error: test failed, to rerun pass `-p atomic-memcpy --lib`

Caused by:
  process didn't exit successfully: `/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-04c46d82177f025f` (exit status: 1)
note: test exited abnormally; to see the full output pass --nocapture to the harness.
```

```
MemorySanitizer init done
MemorySanitizer:DEADLYSIGNAL
==3315==ERROR: MemorySanitizer: SEGV on unknown address 0x6fff3618a3d8 (pc 0x55a3c90d218a bp 0x000000000000 sp 0x7fff3618a1b0 T3315)
==3315==The signal is caused by a READ memory access.
    #0 0x55a3c90d218a  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158+0x15f18a) (BuildId: eb746f488bb9238cde720cedbf7039f80464d20d)
    #1 0x55a3c90d1b56  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158+0x15eb56) (BuildId: eb746f488bb9238cde720cedbf7039f80464d20d)
    #2 0x55a3c903f0ec  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158+0xcc0ec) (BuildId: eb746f488bb9238cde720cedbf7039f80464d20d)
    #3 0x7fd98962a1c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
    #4 0x7fd98962a28a  (/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId: 6d64b17fbac799e68da7ebd9985ddf9b5cb375e6)
    #5 0x55a3c8fcc214  (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158+0x59214) (BuildId: eb746f488bb9238cde720cedbf7039f80464d20d)

==3315==Register values:
rax = 0x0000000080000003  rbx = 0x0000500000000000  rcx = 0x00006fff3618a3d8  rdx = 0x0000100000000000
rdi = 0x00007fff3618a3d0  rsi = 0x00002fff3618a3d0  rbp = 0x0000000000000000  rsp = 0x00007fff3618a1b0
 r8 = 0x00006fff3618a3d0   r9 = 0x0000000000000000  r10 = 0x000055a3c8f8f0bf  r11 = 0x0000000000000206
r12 = 0x0000500000000000  r13 = 0x00002fff3618a3a0  r14 = 0x00007fff3618a3d0  r15 = 0xffffffffffffef60
MemorySanitizer can not provide additional info.
SUMMARY: MemorySanitizer: SEGV (/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158+0x15f18a) (BuildId: eb746f488bb9238cde720cedbf7039f80464d20d)
==3315==ABORTING
error: test failed, to rerun pass `-p atomic-memcpy --lib`

Caused by:
  process didn't exit successfully: `/home/runner/work/atomic-memcpy/atomic-memcpy/target/x86_64-unknown-linux-gnu/release/deps/atomic_memcpy-0e0b4cc066b47158` (exit status: 1)
note: test exited abnormally; to see the full output pass --nocapture to the harness.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants