Skip to content

Commit e4b1afd

Browse files
committed
More atomics notes
1 parent 5ace057 commit e4b1afd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/custom-target.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ You can pretty much copy that output into your file. Start with a few modificati
5252
- Fill `llvm-target` with [the triple that LLVM expects][llvm-target-triple]
5353
- Decide on a panicking strategy. A bare metal implementation will likely use
5454
`"panic-strategy": "abort"`. If you decide not to `abort` on panicking, unless you [tell Cargo
55-
to][eh_personality], you must define an [eh_personality] function.
55+
to][eh_personality] per-project, you must define an [eh_personality] function.
5656
- Configure atomics. Pick the first option that describes your target:
5757
- I have a single-core processor, no threads, [**no interrupts**][interrupts-note], or any way for
5858
multiple things to be happening in parallel: if you are **sure** that is the case, such as WASM
5959
(for now), you may set `"singlethread": true`. This will configure LLVM to convert all atomic
60-
operations to use their single threaded counterparts.
60+
operations to use their single threaded counterparts. Incorrectly using this option may result
61+
in UB if using threads or interrupts.
6162
- I have native atomic operations: set `max-atomic-width` to the biggest type in bits that your
6263
target can operate on atomically. For example, many ARM cores have 32-bit atomic operations. You
6364
may set `"max-atomic-width": 32` in that case.
@@ -66,7 +67,9 @@ You can pretty much copy that output into your file. Start with a few modificati
6667
[atomic][libcalls-atomic] and [sync][libcalls-atomic] functions expected by LLVM as
6768
`#[no_mangle] unsafe extern "C"`. These functions have been standardized by gcc, so the [gcc
6869
documentation][gcc-sync] may have more notes. Missing functions will cause a linker error, while
69-
incorrectly implemented functions will possibly cause UB.
70+
incorrectly implemented functions will possibly cause UB. For example, if you have a
71+
single-core, single-thread processor with interrupts, you can implement these functions to
72+
disable interrupts, perform the regular operation, and then re-enable them.
7073
- I have no native atomic operations: you'll have to do some unsafe work to manually ensure
7174
synchronization in your code. You must set `"max-atomic-width": 0`.
7275
- Change the linker if integrating with an existing toolchain. For example, if you're using a

0 commit comments

Comments
 (0)