Thanks to visit codestin.com
Credit goes to github.com

Skip to content

reenable msan sanitizer workflow #1589

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

Merged
merged 24 commits into from
May 3, 2023
Merged

reenable msan sanitizer workflow #1589

merged 24 commits into from
May 3, 2023

Conversation

dmah42
Copy link
Member

@dmah42 dmah42 commented Apr 27, 2023

No description provided.

@LebedevRI
Copy link
Collaborator

Yup, i do not see where you custom-build libc++. That is really necessary for MSan.
Roughly, you need

$ git clone --depth=1 https://github.com/llvm/llvm-project
$ mkdir <llvm-build> && cd <llvm-build>
$ cmake -GNinja ../llvm-project/runtimes/ -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_USE_SANITIZER=MemoryWithOrigins
$ ninja cxx cxxabi unwind
$ cd benchmark-build-dir
$ CC=clang CXX=clang++ CXXFLAGS="-fsanitize=memory -fsanitize-memory-track-origins -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls -stdlib=libc++ -L<llvm-build>/lib -lc++abi -Isystem<llvm-build>/include -Isystem<llvm-build>/include/c++/v1 -Wl,-rpath,<llvm-build>/lib" cmake <...> ..

@dmah42
Copy link
Member Author

dmah42 commented Apr 27, 2023

something like https://github.com/google/benchmark/blob/main/.github/libcxx-setup.sh ?

we used to have this, but with it the sanitizer workflow timed out because the libc++ build is way too slow. maybe it's worth trying just for msan.

@LebedevRI
Copy link
Collaborator

something like https://github.com/google/benchmark/blob/main/.github/libcxx-setup.sh ?

Close, but my snippet is the more modern version of that incantation.

we used to have this, but with it the sanitizer workflow timed out because the libc++ build is way too slow. maybe it's worth trying just for msan.

Unless the whole LLVM gets built accidentally, i don't believe that should be slow at all, maybe 10 extra minutes.

@dmah42
Copy link
Member Author

dmah42 commented Apr 27, 2023

note: LLVM build is at 30% after 12m.

@dmah42
Copy link
Member Author

dmah42 commented Apr 27, 2023

msan debug failure is the same as when we didn't build libc++ with msan (unless i messed up the linking somehow)

#make -C llvm-build -j3 cxx cxxabi
#sudo make -C llvm-build install-cxx install-cxxabi
#cd ..
cd ./llvm-project
Copy link
Collaborator

Choose a reason for hiding this comment

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

cd ./llvm-project/runtimes/

@LebedevRI
Copy link
Collaborator

msan debug failure is the same as when we didn't build libc++ with msan (unless i messed up the linking somehow)

You have noticed that the libc++ build itself failed, right?

@dmah42
Copy link
Member Author

dmah42 commented Apr 27, 2023

msan debug failure is the same as when we didn't build libc++ with msan (unless i messed up the linking somehow)

You have noticed that the libc++ build itself failed, right?

gah, no i didn't. i guess the script should return an error status.

# Checkout LLVM sources
#git clone --depth=1 https://github.com/llvm/llvm-project.git llvm-project
#
git clone --depth=1 https://github.com/llvm/llvm-project.git llvm-project
Copy link
Collaborator

Choose a reason for hiding this comment

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

One more thing to note, it is rather issue-prone to use libc++ from trunk,
e.g. because nowadays they only guarantee building libc++ with clang
from the same revision or so, so building with older clang may fail,
and i'm not sure that will be caught at cmake time.
So it would be best to checkout some specific tag.

-DLLVM_USE_SANITIZER=${LIBCXX_SANITIZER} \
-DLLVM_BUILD_32_BITS=${BUILD_32_BITS} \
-DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi;libunwind' \
-S llvm -B llvm-build -G "Unix Makefiles"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, i guess it's -S . now.

Copy link
Member Author

Choose a reason for hiding this comment

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

yep. working on it. can't test locally so i'm iterating here :(

@dmah42
Copy link
Member Author

dmah42 commented Apr 27, 2023

ok it builds much faster (yay) but still fails with the same error in sysinfo.

@LebedevRI
Copy link
Collaborator

ok it builds much faster (yay) but still fails with the same error in sysinfo.

Nice!
I'd suggest to drop the install stuff, and explicitly add -stdlib=libc++ -L<llvm-build>/lib -lc++abi -Isystem<llvm-build>/include -Isystem<llvm-build>/include/c++/v1 -Wl,-rpath,<llvm-build>/lib to CXXFLAGS.

@dmah42
Copy link
Member Author

dmah42 commented Apr 28, 2023

welp. msan passes, now asan is failing. it looks like an odr violation in libcxx so i tried suppression but failed. concerned that it is odr violation but coming from something in our code (the output tests maybe?)

@LebedevRI
Copy link
Collaborator

Could you try passing -DBUILD_SHARED_LIBS=OFF (!) for sanitizer build jobs?

run: |
"${GITHUB_WORKSPACE}/.github/libcxx-setup.sh"
echo "EXTRA_CXX_FLAGS=\"-stdlib=libc++\"" >> $GITHUB_ENV
echo "EXTRA_CXX_FLAGS=-stdlib=libc++ -L ${GITHUB_WORKSPACE}/llvm-build/lib -lc++abi -Isystem${GITHUB_WORKSPACE}/llvm-build/include -Isystem${GITHUB_WORKSPACE}/llvm-build/include/c++/v1 -Wl,-rpath,${GITHUB_WORKSPACE}/llvm-build/lib" >> $GITHUB_ENV
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, last guess:
Prepend -nostdlibc++ before -stdlib=libc++ here.

run: |
"${GITHUB_WORKSPACE}/.github/libcxx-setup.sh"
echo "EXTRA_CXX_FLAGS=\"-stdlib=libc++\"" >> $GITHUB_ENV
echo "EXTRA_CXX_FLAGS=-nostdlibc++ -stdlib=libc++ -L ${GITHUB_WORKSPACE}/llvm-build/lib -lc++abi -Isystem${GITHUB_WORKSPACE}/llvm-build/include -Isystem${GITHUB_WORKSPACE}/llvm-build/include/c++/v1 -Wl,-rpath,${GITHUB_WORKSPACE}/llvm-build/lib" >> $GITHUB_ENV
Copy link
Collaborator

Choose a reason for hiding this comment

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

Err, i guess it's apparently -nostdlib++, without the c letter.
Also, are you sure about the space after -L?

@LebedevRI
Copy link
Collaborator

Ok, final guess: add -fsanitize-address-use-odr-indicator to global CXXFLAGS, when building both the libc++ and benchmark.

@LebedevRI
Copy link
Collaborator

@dmah42 sorry for so much back-n-forth here.

@dmah42
Copy link
Member Author

dmah42 commented Apr 28, 2023

@dmah42 sorry for so much back-n-forth here.

no problem. I'm at a loss so I'm happy for guidance.

@LebedevRI
Copy link
Collaborator

Ok, final guess: add -fsanitize-address-use-odr-indicator to global CXXFLAGS, when building both the libc++ and benchmark.

@@ -23,7 +23,7 @@ jobs:
- name: configure msan env
if: matrix.sanitizer == 'msan'
run: |
echo "EXTRA_FLAGS=-g -O2 -fno-omit-frame-pointer -fsanitize=memory -fsanitize-memory-track-origins" >> $GITHUB_ENV
echo "EXTRA_FLAGS=-g -O2 -fno-omit-frame-pointer -fsanitize=memory -fsanitize-memory-track-origins -fsanitize-address-use-odr-indicator" >> $GITHUB_ENV
Copy link
Collaborator

Choose a reason for hiding this comment

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

It should be for if: matrix.sanitizer == 'asan' block, though

Copy link
Member Author

Choose a reason for hiding this comment

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

ugh. i forgot what i was doing over the weekend. sorry.

Copy link
Member Author

Choose a reason for hiding this comment

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

this is the default for non-windows so i can drop it anyway

@LebedevRI
Copy link
Collaborator

I see. Do we really need to custom-build libc++ for non-msan? Because that isn't really necessary.
Can we just not do that instead?

@dmah42
Copy link
Member Author

dmah42 commented May 3, 2023

I see. Do we really need to custom-build libc++ for non-msan? Because that isn't really necessary. Can we just not do that instead?

they're all passing in the current state.. maybe just don't use the custom libc++ for asan (as it seems to have the issue)? or find the way to suppress the warning correctly.

@LebedevRI
Copy link
Collaborator

I see. Do we really need to custom-build libc++ for non-msan? Because that isn't really necessary. Can we just not do that instead?

they're all passing in the current state.. maybe just don't use the custom libc++ for asan (as it seems to have the issue)? or find the way to suppress the warning correctly.

That's what i'm suggesting, yes.

@dmah42 dmah42 marked this pull request as ready for review May 3, 2023 13:25
LebedevRI
LebedevRI previously approved these changes May 3, 2023
Copy link
Collaborator

@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

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

Yay, ship it! (probably should be squash-merged)
Thank you.

@dmah42 dmah42 merged commit fba5dd1 into main May 3, 2023
@dmah42
Copy link
Member Author

dmah42 commented May 3, 2023

thanks for all the help!

@dmah42 dmah42 deleted the msan branch May 3, 2023 15:55
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