Skip to content

Conversation

kzall0c
Copy link
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 <[email protected]>
DBGINFO_CFLAGS += $(ASAN_CFLAGS)
TRACEEVENT_CFLAGS += $(ASAN_CFLAGS)
TEST_CFLAGS += $(ASAN_CFLAGS)
SAN=$(DEFAULT_SANITIZERS)
Copy link
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.

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
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