Skip to content

Document how to use MSAN#13298

Draft
edwintorok wants to merge 2 commits intoocaml:trunkfrom
edwintorok:private/edvint/msan-doc-only
Draft

Document how to use MSAN#13298
edwintorok wants to merge 2 commits intoocaml:trunkfrom
edwintorok:private/edvint/msan-doc-only

Conversation

@edwintorok
Copy link
Copy Markdown
Contributor

Split from #13290.

Back in 2018 tools/ci/inria/sanitizers/script claimed that MSAN output is impossible to debug.
clang has improved a lot since then, and in fact with clang-18 on Fedora40 it only reports 2 bug, both of which I was able to track down.

First of all zstd has to be disabled with -fsanitize=memory, because all external libraries would have to be compiled with -fsanitize=memory, otherwise the instrumentation won't see the writes performed by these and consider all memory written to by these functions uninitialized.

With these 2 changes the testsuite now passes.

I've included some compile flag improvements as well, the manual recommends -O1 or higher, not -O0.

ocamlopt has to be kept disabled, it'd need a similar solution to TSAN to enable it (ocamlopt would have to emit calls to instrumentation functions compatible with Clang's, otherwise it won't see any of the writes from OCaml and consider them uninitialized).

I've kept the memory sanitizer commented out for now, but if desired it could be enabled.

Draft, because it conflicts with the other sanitizer CI PRs and needs to be rebased once they are merged.

Tested with clang-18.1.6 on Fedora 40.

According https://github.com/google/sanitizers/wiki/MemorySanitizer#using-instrumented-libraries
all the code in the program must be built with it, otherwise false
positives are reported.
Disable zstd when compiling with the memory sanitizer, because this is
an external library, that is unlikely to have been compiled with it.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
Signed-off-by: Edwin Török <edwin.torok@cloud.com>
@edwintorok
Copy link
Copy Markdown
Contributor Author

clang14 from Ubuntu22 might be too old for this, there is a false positive from calling stat there, might need a newer clang before it can be enabled by default (works fine with clang-18 on Fedora40).

@gasche
Copy link
Copy Markdown
Member

gasche commented Jul 24, 2024

(Is this still a draft?)

@edwintorok
Copy link
Copy Markdown
Contributor Author

Yes, I have a private/edvint/msan-doc-only.2 that is an update of this one, but it is not quite ready yet (in that branch I split the sanitizer script into 3, one for each sanitizer, but that makes it difficult to review, so I'll add some CLI flags/env vars instead). I'll try to find some time to work on this later this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants