Skip to content

Commit cbab5ad

Browse files
authored
Rollup merge of rust-lang#114412 - RalfJung:libc-symbols, r=pnkfelix
document our assumptions about symbols provided by the libc LLVM makes assumptions about `memcmp`, `memmove`, and `memset` that go beyond what the C standard guarantees -- see https://reviews.llvm.org/D86993. Since we use LLVM, we are inheriting these assumptions. With rust-lang#114382 we are also making a similar assumption about `memcmp`, so I added that to the list. Fixes rust-lang/unsafe-code-guidelines#426.
2 parents a23f216 + fb4ac63 commit cbab5ad

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

library/core/src/lib.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@
2020
// FIXME: Fill me in with more detail when the interface settles
2121
//! This library is built on the assumption of a few existing symbols:
2222
//!
23-
//! * `memcpy`, `memcmp`, `memset`, `strlen` - These are core memory routines which are
24-
//! often generated by LLVM. Additionally, this library can make explicit
25-
//! calls to these functions. Their signatures are the same as found in C.
26-
//! These functions are often provided by the system libc, but can also be
27-
//! provided by the [compiler-builtins crate](https://crates.io/crates/compiler_builtins).
23+
//! * `memcpy`, `memmove`, `memset`, `memcmp`, `bcmp`, `strlen` - These are core memory routines
24+
//! which are generated by Rust codegen backends. Additionally, this library can make explicit
25+
//! calls to `strlen`. Their signatures are the same as found in C, but there are extra
26+
//! assumptions about their semantics: For `memcpy`, `memmove`, `memset`, `memcmp`, and `bcmp`, if
27+
//! the `n` parameter is 0, the function is assumed to not be UB. Furthermore, for `memcpy`, if
28+
//! source and target pointer are equal, the function is assumed to not be UB.
29+
//! (Note that these are [standard assumptions](https://reviews.llvm.org/D86993) among compilers.)
30+
//! These functions are often provided by the system libc, but can also be provided by the
31+
//! [compiler-builtins crate](https://crates.io/crates/compiler_builtins).
32+
//! Note that the library does not guarantee that it will always make these assumptions, so Rust
33+
//! user code directly calling the C functions should follow the C specification! The advice for
34+
//! Rust user code is to call the functions provided by this library instead (such as
35+
//! `ptr::copy`).
2836
//!
2937
//! * `rust_begin_panic` - This function takes four arguments, a
3038
//! `fmt::Arguments`, a `&'static str`, and two `u32`'s. These four arguments

0 commit comments

Comments
 (0)