This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Enable building with UBSAN + clang-cl on windows
ClosedPublic

Authored by dwang on May 25 2023, 3:40 PM.

Details

Summary

Currently both ASAN and UBSAN are supported on Windows but only ASAN is enabled in LLVM build system. This patch enables the option to build LLVM with UBSAN on windows.

Tested with clang-cl released in LLVM16.

Diff Detail

Event Timeline

dwang created this revision.May 25 2023, 3:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2023, 3:40 PM
dwang requested review of this revision.May 25 2023, 3:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2023, 3:40 PM
dwang updated this revision to Diff 526109.May 26 2023, 10:14 AM
  • Update ubsan_ignorelist to exempt false-positives for 0-sized objects. Build crashes if those files are not exempted.
  • Refine HandleLLVMOptions.cmake
dwang retitled this revision from Enable building with UBSAN + enable_ubsan_clang_cl on windows to [CMake] Enable building with UBSAN + enable_ubsan_clang_cl on windows.May 26 2023, 10:25 AM
dwang edited the summary of this revision. (Show Details)
dwang added reviewers: andrewng, chandlerc.
dwang retitled this revision from [CMake] Enable building with UBSAN + enable_ubsan_clang_cl on windows to [CMake] Enable building with UBSAN on windows.May 26 2023, 10:30 AM
dwang edited the summary of this revision. (Show Details)
dwang retitled this revision from [CMake] Enable building with UBSAN on windows to [CMake] Enable building with UBSAN + clang on windows.May 26 2023, 10:33 AM
dwang edited the summary of this revision. (Show Details)
dwang retitled this revision from [CMake] Enable building with UBSAN + clang on windows to [CMake] Enable building with UBSAN + clang-cl on windows.
dwang edited the summary of this revision. (Show Details)
dwang edited the summary of this revision. (Show Details)May 26 2023, 10:39 AM

Apart from the two nits, the CMake changes LGTM, although I haven't tested the patch myself. I'm not particularly familiar with UBSAN, so can't really comment on the other changes to ubsan_ignorelist.txt.

llvm/cmake/modules/HandleLLVMOptions.cmake
969

Perhaps supported by clang-cl?

llvm/utils/sanitizers/ubsan_ignorelist.txt
24 ↗(On Diff #526109)

Should add newline to the end of the file for "UNIX" consumers.

dwang updated this revision to Diff 529085.Jun 6 2023, 4:31 PM

fix error message & newline at end of file

dwang added a reviewer: ychen.Jun 6 2023, 4:53 PM
dwang marked 2 inline comments as done.Jun 6 2023, 5:04 PM

For the ubsan ignore list, the newly added files reported ubsan crashes similiar to the one reported in: https://github.com/llvm/llvm-project/issues/61775

pgousseau added inline comments.
llvm/cmake/modules/HandleLLVMOptions.cmake
971

Could we add a succint comment to explain -D_ITERATOR_DEBUG_LEVEL=0 ? Is it for performance or to workaround a bug?

dwang added inline comments.Jun 8 2023, 10:17 AM
llvm/cmake/modules/HandleLLVMOptions.cmake
971

This was a workaround for debug level mismatch between UBSAN runtime and another module. Somehow the bug does not reproduce on latest master branch anymore. I will remove this.

dwang updated this revision to Diff 530056.Jun 9 2023, 12:43 PM

Workaround UBSAN false-positive on 0-sized objects with __declspec(empty_bases)

dwang marked an inline comment as done.EditedJun 9 2023, 12:49 PM

For the UBSAN crashes, I found an alternative workaround here: https://github.com/llvm/llvm-project/issues/31914. Since the errors only reproduce on windows, this seems like a cleaner fix.
I have pushed an update to outline the necessary changes.

This revision is now accepted and ready to land.Jun 12 2023, 8:08 AM

@pgousseau Thanks for the review!
Can you maybe commit this patch for me? I do not have push permission.

dwang updated this revision to Diff 530613.Jun 12 2023, 11:33 AM
  • format code
dwang updated this revision to Diff 530696.Jun 12 2023, 4:09 PM

rebase against main

This revision was landed with ongoing or failed builds.Jun 13 2023, 2:18 AM
This revision was automatically updated to reflect the committed changes.