This is an archive of the discontinued LLVM Phabricator instance.

[HWASan] Build separate LAM runtime on x86_64.
ClosedPublic

Authored by morehouse on May 11 2021, 4:35 PM.

Details

Summary

Since we have both aliasing mode and Intel LAM on x86_64, we need to
choose the mode at either run time or compile time. This patch
implements the plumbing to build both and choose between them at
compile time.

Diff Detail

Event Timeline

morehouse created this revision.May 11 2021, 4:35 PM
morehouse requested review of this revision.May 11 2021, 4:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2021, 4:35 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
morehouse added a subscriber: kcc.
morehouse updated this revision to Diff 344596.May 11 2021, 4:46 PM
  • Add comment regarding new prctl() API.

Would it be simple if module constructor of initialized code just sets some global or call init function to switch HWASAN into LAM so we can have the same runtime?

compiler-rt/lib/hwasan/hwasan_linux.cpp
125

Do we use this way to enable INTEL_LAM ?

Would it be simple if module constructor of initialized code just sets some global or call init function to switch HWASAN into LAM so we can have the same runtime?

I have another patch that does this. It is actually much more complicated than this. The tradeoff is that we lose most of our constexpr stuff. kAddressTagShift, kNumBits, and even heap size become non-constexpr and need to be loaded on callbacks. Significant changes to the primary also need to be made to handle non-constant heap sizes.

Considering we want to optimize in future patches with, for example, a custom calling convention, we may need to switch back to constexpr stuff in the future anyway.

compiler-rt/lib/hwasan/hwasan_linux.cpp
125

prctl is what the current public LAM patch uses: https://lore.kernel.org/linux-mm/20210205151631.43511-12-kirill.shutemov@linux.intel.com/

Kirill said the API is subject to change, but he wasn't sure when we'll know what the final API is. So for now we're using what the only interface we know about and can test in QEMU.

eugenis added inline comments.May 12 2021, 3:54 PM
compiler-rt/lib/hwasan/CMakeLists.txt
171

I wonder if "lam" would look better as an arch suffix:

libclang_rt.hwasan-x86_64-lam  (or x86_64_lam)

unless it creates complications that I don't yet see.

compiler-rt/lib/hwasan/hwasan_linux.cpp
153

Could we put this stuff undef INTEL_LAM? I don't want this experimental calls to be done on non-LAM targets, where it is known not to work.

morehouse added inline comments.May 13 2021, 8:48 AM
compiler-rt/lib/hwasan/CMakeLists.txt
171

Just spent 30 minutes trying this. It seems to be more complicated since adding _lam to ${arch} requires all the RT* object libraries to be built with a _lam suffix, including non-hwasan ones.

If you still want to do this, I can keep working on it and upload a new diff, but I think it will be more complex.

morehouse updated this revision to Diff 345174.May 13 2021, 9:14 AM
morehouse marked an inline comment as done.
  • Guard new prctl() API under INTEL_LAM.
This revision is now accepted and ready to land.May 13 2021, 11:46 AM
morehouse updated this revision to Diff 345282.May 13 2021, 2:10 PM
  • Rebase onto D102288.
  • Refactor to make LAM the default runtime.
  • Use alias runtime if specified.
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2021, 2:10 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
vitalybuka accepted this revision.May 13 2021, 2:39 PM
This revision was landed with ongoing or failed builds.May 17 2021, 9:19 AM
This revision was automatically updated to reflect the committed changes.
gulfem added a subscriber: gulfem.May 17 2021, 11:46 AM

We started seeing test failures in our Windows builds in Fuchsia after this patch.

FAILED: compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o 
C:\b\s\w\ir\x\w\staging\llvm_build\.\bin\clang++.exe --target=aarch64-unknown-linux-gnu --sysroot=C:/b/s/w/ir/x/w/cipd/linux  -DHWASAN_WITH_INTERCEPTORS=1 -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -IC:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/.. --target=aarch64-unknown-linux-gnu -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -ffile-prefix-map=C:/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins=../staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins -ffile-prefix-map=C:/b/s/w/ir/x/w/llvm-project/= -no-canonical-prefixes -Wall -std=c++14 -Wno-unused-parameter -O2 -g -DNDEBUG    -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -fPIC -ffreestanding -DHWASAN_ALIASING_MODE -UNDEBUG -MD -MT compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o -MF compiler-rt\lib\hwasan\CMakeFiles\RTHwasanAliases.aarch64.dir\hwasan_interceptors.cpp.o.d -o compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o -c C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
In file included from C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp:18:
C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan.h:41:6: error: Aliasing mode is only supported on x86_64

The error message to the full build:
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/build/stdout

The CMake commands:
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/configure/execution_details

@morehouse do you have any idea?

We started seeing test failures in our Windows builds in Fuchsia after this patch.

FAILED: compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o 
C:\b\s\w\ir\x\w\staging\llvm_build\.\bin\clang++.exe --target=aarch64-unknown-linux-gnu --sysroot=C:/b/s/w/ir/x/w/cipd/linux  -DHWASAN_WITH_INTERCEPTORS=1 -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -IC:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/.. --target=aarch64-unknown-linux-gnu -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -ffile-prefix-map=C:/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins=../staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins -ffile-prefix-map=C:/b/s/w/ir/x/w/llvm-project/= -no-canonical-prefixes -Wall -std=c++14 -Wno-unused-parameter -O2 -g -DNDEBUG    -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -fPIC -ffreestanding -DHWASAN_ALIASING_MODE -UNDEBUG -MD -MT compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o -MF compiler-rt\lib\hwasan\CMakeFiles\RTHwasanAliases.aarch64.dir\hwasan_interceptors.cpp.o.d -o compiler-rt/lib/hwasan/CMakeFiles/RTHwasanAliases.aarch64.dir/hwasan_interceptors.cpp.o -c C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
In file included from C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan_interceptors.cpp:18:
C:/b/s/w/ir/x/w/llvm-project/compiler-rt/lib/hwasan/hwasan.h:41:6: error: Aliasing mode is only supported on x86_64

The error message to the full build:
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/build/stdout

The CMake commands:
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket.appspot.com/8846968772132677360/+/u/clang/configure/execution_details

@morehouse do you have any idea?

Looks like the same issue I fixed in https://reviews.llvm.org/rGd97bab651185. Let me know if you have the issue after that commit.

Looks like the same issue I fixed in https://reviews.llvm.org/rGd97bab651185. Let me know if you have the issue after that commit.

Thanks, that resolved the build issue.