Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MemorySanitizer build #1988

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Support MemorySanitizer build #1988

wants to merge 1 commit into from

Conversation

yskelg
Copy link
Contributor

@yskelg yskelg 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>
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.

endif

ifneq ($(SAN),)
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