[libc-commits] [libc] Create a poor-developer's msan for libc wide read functions. (PR #170586)
via libc-commits
libc-commits at lists.llvm.org
Wed Jan 14 15:23:51 PST 2026
================
@@ -0,0 +1,98 @@
+// For performance, some vector-based libc functions read data outside of, but
+// adjacent to, the input address. For example, string_length can read both
+// before and after the data in its src parameter. As part of the
+// implementation, it is allowed to do this. However, the code must take care
+// to avoid address errors. The sanitizers can't distinguish between "the
+// implementation" and user-code, and so report an error. Therefore we can't use
+// them to check if functions like thees have memory errors.
+//
+// This test uses mprotect to simulate address sanitization. Tests that read too
+// far outside data will segfault.
+//
+// It creates three adjacent pages in memory. The outer two are mprotected
+// unreadable, the middle usable normally. By placing test data at the edges
+// between the middle page and the others, we can test for bad accesses.
+
+#include <cstddef>
+#include <type_traits>
+#include <vector>
+
+#include <assert.h>
+#include <sys/mman.h>
+#include <unistd.h>
----------------
Sterling-Augustine wrote:
Finally got back to this. PTAL.
Biggest change is that our cpp support doesn't support certain alignment calls. Fixed by just going big.
https://github.com/llvm/llvm-project/pull/170586
More information about the libc-commits
mailing list