Skip to content

Support MemorySanitizer build#1988

Open
kzall0c wants to merge 1 commit intonamhyung:masterfrom
kzall0c:msan
Open

Support MemorySanitizer build#1988
kzall0c wants to merge 1 commit intonamhyung:masterfrom
kzall0c:msan

Conversation

@kzall0c
Copy link
Copy Markdown
Contributor

@kzall0c kzall0c commented Jan 8, 2025

Uninitialized values occur when stack- or heap-allocated memory is read before it is written. MSan detects cases

  • Uninitialized value was used in a conditional branch.
  • Uninitialized pointer was used for memory accesses.
  • Uninitialized value was passed or returned from a function call.
  • Uninitialized data was passed into some libc calls.
$ git clone https://github.com/llvm/llvm-project.git $ cd ~/llvm-project/
$ mkdir build/ && cd build

$ CC=clang CXX=clang++ cmake -G Ninja ../llvm \
    -DLLVM_ENABLE_PROJECTS="clang;compiler-rt" \
    -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
    -DCOMPILER_RT_BUILD_SANITIZERS=ON \
    -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
    -DLLVM_ENABLE_LIBCXX=ON \
    -DLLVM_TARGETS_TO_BUILD="X86" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_C_COMPILER_TARGET=x86_64-unknown-linux-gnu

$ ninja

$ cd ~/uftrace/
$ ./configure CC=$HOME/llvm-project/build/bin/clang

$ make MSAN=1

$ cd tests/
$ ./runtest.py -c=$HOME/llvm-project/build/bin/clang

Uninitialized values occur when stack- or heap-allocated memory is read
before it is written. MSan detects cases
* Uninitialized value was used in a conditional branch.
* Uninitialized pointer was used for memory accesses.
* Uninitialized value was passed or returned from a function call.
* Uninitialized data was passed into some libc calls.

$ git clone https://github.com/llvm/llvm-project.git
$ cd ~/llvm-project/
$ mkdir build/ && cd build

$ CC=clang CXX=clang++ cmake -G Ninja ../llvm \
    -DLLVM_ENABLE_PROJECTS="clang;compiler-rt" \
    -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
    -DCOMPILER_RT_BUILD_SANITIZERS=ON \
    -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
    -DLLVM_ENABLE_LIBCXX=ON \
    -DLLVM_TARGETS_TO_BUILD="X86" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_C_COMPILER_TARGET=x86_64-unknown-linux-gnu

$ ninja

$ cd ~/uftrace/
$ ./configure CC=$HOME/llvm-project/build/bin/clang

$ make MSAN=1

$ cd tests/
$ ./runtest.py -c=$HOME/llvm-project/build/bin/clang

Signed-off-by: Yunseong Kim <yskelg@gmail.com>
Comment thread Makefile
DBGINFO_CFLAGS += $(ASAN_CFLAGS)
TRACEEVENT_CFLAGS += $(ASAN_CFLAGS)
TEST_CFLAGS += $(ASAN_CFLAGS)
SAN=$(DEFAULT_SANITIZERS)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It could be SAN=all.

Comment thread Makefile
ifeq ($(SAN), all)
SAN_CFLAGS := -O0 -g -fsanitize=$(DEFAULT_SANITIZERS)
else ifeq ($(MSAN), 1)
SAN_CFLAGS := -O0 -g -fsanitize=$(SAN) -fsanitize-memory-track-origins
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It seems it should be used when memory sanitizer is requested (even with others). What about this?

else ifneq ($(findstring memory, $(SAN)), )
  SAN_CFLAGS := -O0 -g -fsanitize=$(SAN) -fsanitize-memory-track-origins

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