This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Refactor memintrinsic interceptors
ClosedPublic

Authored by melver on May 26 2023, 3:32 AM.

Details

Summary

This moves memintrinsic interceptors (memcpy/memmove/memset) into a new
file sanitizer_common_interceptors_memintrinsics.inc.

This is in preparation of redefining builtins, however, we must be
careful to not redefine builtins in TUs that define interceptors of the
same name.

In all cases except for MSan, memintrinsic interceptors were moved to a
new TU $tool_interceptors_memintrinsics.cpp. In the case of MSan, it
turns out this is not yet necessary (as shown by the later patch
introducing memcpy tests).

NFC.

Depends on D151551

Diff Detail

Event Timeline

melver created this revision.May 26 2023, 3:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2023, 3:32 AM
Herald added subscribers: Enna1, dberris. · View Herald Transcript
melver requested review of this revision.May 26 2023, 3:32 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 26 2023, 3:32 AM
Herald added subscribers: llvm-commits, Restricted Project. · View Herald Transcript

What's the failure mode if we accidentally include redefine into sanitizer_common_interceptors_memintrinsics.inc?

What's the failure mode if we accidentally include redefine into sanitizer_common_interceptors_memintrinsics.inc?

I reworked the builtin redefinitions patch. I added a compile-time check in https://reviews.llvm.org/D151152.

This revision is now accepted and ready to land.May 26 2023, 11:04 AM
This revision was landed with ongoing or failed builds.May 30 2023, 3:02 AM
This revision was automatically updated to reflect the committed changes.
haowei added a subscriber: haowei.May 30 2023, 9:27 AM

Hi

This patch breaks Fuchsia's clang build in building runtimes-aarch64-unknown-fuchsia step. Part of Error message:

FAILED: compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.x86_64.dir/asan_interceptors_memintrinsics.cpp.obj 
/b/s/w/ir/x/w/staging/llvm_build/./bin/clang++ --target=x86_64-unknown-fuchsia --sysroot=/b/s/w/ir/x/w/sdk/arch/x64/sysroot -DASAN_DYNAMIC=1 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/asan/.. --target=x86_64-unknown-fuchsia -I/b/s/w/ir/x/w/sdk/pkg/sync/include -I/b/s/w/ir/x/w/sdk/pkg/fdio/include -fPIC -fno-semantic-interposition -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 -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-x86_64-unknown-fuchsia-bins=../staging/llvm_build/runtimes/runtimes-x86_64-unknown-fuchsia-bins -ffile-prefix-map=/b/s/w/ir/x/w/llvm-llvm-project/= -no-canonical-prefixes -Wall -Wno-unused-parameter -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -Wno-format -ftls-model=initial-exec -MD -MT compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.x86_64.dir/asan_interceptors_memintrinsics.cpp.obj -MF compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.x86_64.dir/asan_interceptors_memintrinsics.cpp.obj.d -o compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.x86_64.dir/asan_interceptors_memintrinsics.cpp.obj -c /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
In file included from /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp:78:
/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:229:3: error: use of undeclared identifier 'ASAN_INTERCEPT_FUNC'
  INIT_MEMSET;
  ^

Full error can be found at https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8779679021892159153/+/u/clang/build/stdout
Could you take a look? If it takes too long to fix forward, could you revert your change first? Thanks.

Hi

This patch breaks Fuchsia's clang build in building runtimes-aarch64-unknown-fuchsia step. Part of Error message:

FAILED: compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.x86_64.dir/asan_interceptors_memintrinsics.cpp.obj 
/b/s/w/ir/x/w/staging/llvm_build/./bin/clang++ --target=x86_64-unknown-fuchsia --sysroot=/b/s/w/ir/x/w/sdk/arch/x64/sysroot -DASAN_DYNAMIC=1 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/asan/.. --target=x86_64-unknown-fuchsia -I/b/s/w/ir/x/w/sdk/pkg/sync/include -I/b/s/w/ir/x/w/sdk/pkg/fdio/include -fPIC -fno-semantic-interposition -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 -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/b/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-x86_64-unknown-fuchsia-bins=../staging/llvm_build/runtimes/runtimes-x86_64-unknown-fuchsia-bins -ffile-prefix-map=/b/s/w/ir/x/w/llvm-llvm-project/= -no-canonical-prefixes -Wall -Wno-unused-parameter -O2 -g -DNDEBUG -std=c++17 -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -Wno-format -ftls-model=initial-exec -MD -MT compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.x86_64.dir/asan_interceptors_memintrinsics.cpp.obj -MF compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.x86_64.dir/asan_interceptors_memintrinsics.cpp.obj.d -o compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.x86_64.dir/asan_interceptors_memintrinsics.cpp.obj -c /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
In file included from /b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp:78:
/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:229:3: error: use of undeclared identifier 'ASAN_INTERCEPT_FUNC'
  INIT_MEMSET;
  ^

Full error can be found at https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8779679021892159153/+/u/clang/build/stdout
Could you take a look? If it takes too long to fix forward, could you revert your change first? Thanks.

https://reviews.llvm.org/rG8c5ad4a0e297 should fix it.