[compiler-rt] r340983 - [hwasan] get rid of some macros, remove the fixed shadow mapping
Evgenii Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 31 09:49:27 PDT 2018
This code is not used by default but we want to turn it on in the future.
On Thu, Aug 30, 2018 at 7:40 PM, Kostya Serebryany <kcc at google.com> wrote:
> I've reproduced this on a 14.04 VM.
> Probably something to do with OLD linkers.
> Anyway, we don't need any of this code on Linux, so I've submitted r341158
> to #ifdef it out.
>
>
>
> On Thu, Aug 30, 2018 at 7:36 PM <douglas.yung at sony.com> wrote:
>>
>> Hi Kostya,
>>
>>
>>
>> On my machine, using ld.bfd (GNU ld (GNU Binutils for Ubuntu) 2.24) the
>> build still fails with the same error.
>>
>>
>>
>> Douglas Yung
>>
>>
>>
>> From: Yung, Douglas
>> Sent: Thursday, August 30, 2018 19:25
>> To: 'Kostya Serebryany'; Evgeniy Stepanov
>> Cc: LLVM Commits
>> Subject: RE: [compiler-rt] r340983 - [hwasan] get rid of some macros,
>> remove the fixed shadow mapping
>>
>>
>>
>> Aside from an extra ‘#’ character before the #endif, it does seem to work.
>>
>>
>>
>> I’ll try using a non-gold linker to see if it makes a difference without
>> your changes as well.
>>
>>
>>
>> Douglas Yung
>>
>>
>>
>> From: Kostya Serebryany [mailto:kcc at google.com]
>> Sent: Thursday, August 30, 2018 19:11
>> To: Yung, Douglas; Evgeniy Stepanov
>> Cc: LLVM Commits
>> Subject: Re: [compiler-rt] r340983 - [hwasan] get rid of some macros,
>> remove the fixed shadow mapping
>>
>>
>>
>> Doesn't reproduce on a newer debian with the exact same cmake command...
>>
>> Let me start a 14.04 VM...
>>
>> Perhaps, there is something incompatible with the older GOLD.
>>
>>
>>
>> Could you please try the patch below and see if it helps?
>>
>> +Evgeniy Stepanov to check if we still need this code on Android.
>>
>> Index: lib/hwasan/hwasan_dynamic_shadow.cc
>>
>> ===================================================================
>>
>> --- lib/hwasan/hwasan_dynamic_shadow.cc (revision 341145)
>>
>> +++ lib/hwasan/hwasan_dynamic_shadow.cc (working copy)
>>
>> @@ -58,6 +58,7 @@
>>
>>
>>
>> } // namespace __hwasan
>>
>>
>>
>> +#if SANITIZER_ANDROID
>>
>> extern "C" {
>>
>>
>>
>> INTERFACE_ATTRIBUTE void __hwasan_shadow();
>>
>> @@ -124,3 +125,13 @@
>>
>> }
>>
>>
>>
>> } // namespace __hwasan
>>
>> +#else
>>
>> +namespace __hwasan {
>>
>> +
>>
>> +uptr FindDynamicShadowStart(uptr shadow_size_bytes) {
>>
>> + return MapDynamicShadow(shadow_size_bytes);
>>
>> +}
>>
>> +
>>
>> +} // namespace __hwasan
>>
>> +#
>>
>> +#endif // SANITIZER_ANDROID
>>
>>
>>
>>
>>
>>
>>
>> On Thu, Aug 30, 2018 at 6:54 PM <douglas.yung at sony.com> wrote:
>>
>> Hi Kostya,
>>
>>
>>
>> Our linux machine is running Ubuntu 14.04.4 LTS with clang 3.7.1 and does
>> the following:
>>
>>
>>
>> · mkdir build
>>
>> · cd build
>>
>> · cmake -G Ninja -DCMAKE_C_COMPILER=clang
>> -DCMAKE_CXX_COMPILER=clang++ -DLLVM_USE_LINKER=gold
>> -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_INCLUDE_EXAMPLES=OFF
>> -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_VERSION_SUFFIX= -DLLVM_BUILD_RUNTIME=ON
>> -DLLVM_LIT_ARGS=--verbose --no-progress-bar --xunit-xml-output=xunit.xml
>> -DCMAKE_BUILD_TYPE=Release ../llvm
>>
>> · ninja all
>>
>>
>>
>> That should do it.
>>
>>
>>
>> From: Kostya Serebryany [mailto:kcc at google.com]
>> Sent: Thursday, August 30, 2018 18:45
>> To: Yung, Douglas
>> Cc: LLVM Commits
>> Subject: Re: [compiler-rt] r340983 - [hwasan] get rid of some macros,
>> remove the fixed shadow mapping
>>
>>
>>
>> Looking...
>>
>> Meanwhile, how do I reproduce your build?
>>
>>
>>
>> On Thu, Aug 30, 2018 at 6:03 PM <douglas.yung at sony.com> wrote:
>>
>> Hi Kostya,
>>
>> Your commit is breaking our internal linux builder that uses clang 3.7.1
>> to build:
>>
>> FAILED: : && /usr/lib/ccache/clang++ -fPIC -fPIC
>> -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -Wextra
>> -Wno-unused-parameter -Wwrite-strings -Wcast-qual
>> -Wmissing-field-initializers -pedantic -Wno-long-long
>> -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor
>> -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections
>> -Wall -std=c++11 -O3 -Wl,-z,defs -Wl,-z,nodelete -fuse-ld=gold -m64
>> -nodefaultlibs
>> -Wl,--version-script,/home/siadmin/jenkins/w/opensource/opensource_build/build/projects/compiler-rt/lib/hwasan/clang_rt.hwasan-dynamic-x86_64.vers
>> -shared -Wl,-soname,libclang_rt.hwasan-x86_64.so -o
>> lib/clang/8.0.0/lib/linux/libclang_rt.hwasan-x86_64.so
>> projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic.x86_64.dir/hwasan.cc.o
>> projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic.x86_64.dir/hwasan_allocator.cc.o
>> projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic.x86_64.dir/hwasan_dynamic_shadow.cc.o
>> projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic.x86_64.dir/hwasan_interceptors.cc.o
>> projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic.x86_64.dir/hwasan_linux.cc.o
>> projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic.x86_64.dir/hwasan_poisoning.cc.o
>> projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic.x86_64.dir/hwasan_report.cc.o
>> projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic.x86_64.dir/hwasan_thread.cc.o
>> projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic.x86_64.dir/hwasan_new_delete.cc.o
>> projects/compiler-rt/lib/interception/CMakeFiles/RTInterception.x86_64.dir/interception_linux.cc.o
>> projects/compiler-rt/lib/interception/CMakeFiles/RTInterception.x86_64.dir/interception_mac.cc.o
>> projects/compiler-rt/lib/interception/CMakeFiles/RTInterception.x86_64.dir/interception_win.cc.o
>> projects/compiler-rt/lib/interception/CMakeFiles/RTInterception.x86_64.dir/interception_type_test.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_allocator.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_common.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_deadlock_detector1.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_deadlock_detector2.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_errno.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_file.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_flags.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_flag_parser.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_fuchsia.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_libc.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_libignore.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_linux.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_linux_s390.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_mac.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_openbsd.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_persistent_allocator.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_platform_limits_linux.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_platform_limits_netbsd.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_platform_limits_openbsd.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_platform_limits_posix.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_platform_limits_solaris.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_posix.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_printf.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_procmaps_common.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_procmaps_bsd.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_procmaps_linux.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_procmaps_mac.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_procmaps_solaris.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_rtems.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_solaris.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_stoptheworld_mac.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_suppressions.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_tls_get_addr.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_thread_registry.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_win.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_linux_x86_64.S.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_linux_mips64.S.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.x86_64.dir/sanitizer_termination.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.x86_64.dir/sanitizer_common_libcdep.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.x86_64.dir/sanitizer_allocator_checks.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.x86_64.dir/sanitizer_linux_libcdep.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.x86_64.dir/sanitizer_mac_libcdep.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.x86_64.dir/sanitizer_posix_libcdep.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibc.x86_64.dir/sanitizer_stoptheworld_linux_libcdep.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonCoverage.x86_64.dir/sancov_flags.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonCoverage.x86_64.dir/sanitizer_coverage_fuchsia.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonCoverage.x86_64.dir/sanitizer_coverage_libcdep_new.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonCoverage.x86_64.dir/sanitizer_coverage_win_sections.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_allocator_report.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_stackdepot.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_stacktrace.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_stacktrace_libcdep.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_stacktrace_printer.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_stacktrace_sparc.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_symbolizer.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_symbolizer_libbacktrace.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_symbolizer_libcdep.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_symbolizer_mac.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_symbolizer_markup.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_symbolizer_posix_libcdep.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_symbolizer_report.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_symbolizer_win.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_unwind_linux_libcdep.cc.o
>> projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizer.x86_64.dir/sanitizer_unwind_win.cc.o
>> projects/compiler-rt/lib/ubsan/CMakeFiles/RTUbsan.x86_64.dir/ubsan_diag.cc.o
>> projects/compiler-rt/lib/ubsan/CMakeFiles/RTUbsan.x86_64.dir/ubsan_init.cc.o
>> projects/compiler-rt/lib/ubsan/CMakeFiles/RTUbsan.x86_64.dir/ubsan_flags.cc.o
>> projects/compiler-rt/lib/ubsan/CMakeFiles/RTUbsan.x86_64.dir/ubsan_handlers.cc.o
>> projects/compiler-rt/lib/ubsan/CMakeFiles/RTUbsan.x86_64.dir/ubsan_monitor.cc.o
>> projects/compiler-rt/lib/ubsan/CMakeFiles/RTUbsan.x86_64.dir/ubsan_value.cc.o
>> projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan_dynamic_version_script_dummy.x86_64.dir/dummy.cc.o
>> -lstdc++ -lgcc_s -lc -ldl -lrt -lm -lpthread -Wl,-rpath,"\$ORIGIN/../lib" &&
>> :
>>
>> /home/siadmin/jenkins/w/opensource/opensource_build/llvm/projects/compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cc:121:
>> error: undefined reference to '__hwasan_shadow'
>>
>> /home/siadmin/jenkins/w/opensource/opensource_build/llvm/projects/compiler-rt/lib/hwasan/hwasan_dynamic_shadow.cc:124:
>> error: undefined reference to '__hwasan_shadow'
>> clang: error: linker command failed with exit code 1 (use -v to see
>> invocation)
>>
>> Can you take a look?
>>
>> Douglas Yung
>>
>> > -----Original Message-----
>> > From: llvm-commits [mailto:llvm-commits-bounces at lists.llvm.org] On
>> > Behalf Of Kostya Serebryany via llvm-commits
>> > Sent: Wednesday, August 29, 2018 15:42
>> > To: llvm-commits at lists.llvm.org
>> > Subject: [compiler-rt] r340983 - [hwasan] get rid of some macros,
>> > remove the fixed shadow mapping
>> >
>> > Author: kcc
>> > Date: Wed Aug 29 15:42:16 2018
>> > New Revision: 340983
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=340983&view=rev
>> > Log:
>> > [hwasan] get rid of some macros, remove the fixed shadow mapping
>> >
>> > Modified:
>> > compiler-rt/trunk/lib/hwasan/hwasan.cc
>> > compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc
>> > compiler-rt/trunk/lib/hwasan/hwasan_dynamic_shadow.cc
>> > compiler-rt/trunk/lib/hwasan/hwasan_linux.cc
>> > compiler-rt/trunk/lib/hwasan/hwasan_mapping.h
>> > compiler-rt/trunk/lib/hwasan/hwasan_poisoning.cc
>> > compiler-rt/trunk/lib/hwasan/hwasan_report.cc
>> > compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
>> >
>> > Modified: compiler-rt/trunk/lib/hwasan/hwasan.cc
>> > URL: http://llvm.org/viewvc/llvm-project/compiler-
>> > rt/trunk/lib/hwasan/hwasan.cc?rev=340983&r1=340982&r2=340983&view=diff
>> > =======================================================================
>> > =======
>> > --- compiler-rt/trunk/lib/hwasan/hwasan.cc (original)
>> > +++ compiler-rt/trunk/lib/hwasan/hwasan.cc Wed Aug 29 15:42:16 2018
>> > @@ -167,12 +167,6 @@ void __hwasan_shadow_init() {
>> > if (hwasan_shadow_inited) return;
>> > if (!InitShadow()) {
>> > Printf("FATAL: HWAddressSanitizer cannot mmap the shadow
>> > memory.\n");
>> > - if (HWASAN_FIXED_MAPPING) {
>> > - Printf("FATAL: Make sure to compile with -fPIE and to link with
>> > -pie.\n");
>> > - Printf("FATAL: Disabling ASLR is known to cause this error.\n");
>> > - Printf("FATAL: If running under GDB, try "
>> > - "'set disable-randomization off'.\n");
>> > - }
>> > DumpProcessMap();
>> > Die();
>> > }
>> > @@ -230,12 +224,12 @@ void __hwasan_init() {
>> >
>> > void __hwasan_print_shadow(const void *p, uptr sz) {
>> > uptr ptr_raw = UntagAddr(reinterpret_cast<uptr>(p));
>> > - uptr shadow_first = MEM_TO_SHADOW(ptr_raw);
>> > - uptr shadow_last = MEM_TO_SHADOW(ptr_raw + sz - 1);
>> > + uptr shadow_first = MemToShadow(ptr_raw);
>> > + uptr shadow_last = MemToShadow(ptr_raw + sz - 1);
>> > Printf("HWASan shadow map for %zx .. %zx (pointer tag %x)\n",
>> > ptr_raw,
>> > ptr_raw + sz, GetTagFromPointer((uptr)p));
>> > for (uptr s = shadow_first; s <= shadow_last; ++s)
>> > - Printf(" %zx: %x\n", SHADOW_TO_MEM(s), *(tag_t *)s);
>> > + Printf(" %zx: %x\n", ShadowToMem(s), *(tag_t *)s);
>> > }
>> >
>> > sptr __hwasan_test_shadow(const void *p, uptr sz) {
>> > @@ -245,11 +239,11 @@ sptr __hwasan_test_shadow(const void *p,
>> > if (ptr_tag == 0)
>> > return -1;
>> > uptr ptr_raw = UntagAddr(reinterpret_cast<uptr>(p));
>> > - uptr shadow_first = MEM_TO_SHADOW(ptr_raw);
>> > - uptr shadow_last = MEM_TO_SHADOW(ptr_raw + sz - 1);
>> > + uptr shadow_first = MemToShadow(ptr_raw);
>> > + uptr shadow_last = MemToShadow(ptr_raw + sz - 1);
>> > for (uptr s = shadow_first; s <= shadow_last; ++s)
>> > if (*(tag_t*)s != ptr_tag)
>> > - return SHADOW_TO_MEM(s) - ptr_raw;
>> > + return ShadowToMem(s) - ptr_raw;
>> > return -1;
>> > }
>> >
>> > @@ -305,7 +299,7 @@ template <ErrorAction EA, AccessType AT,
>> > __attribute__((always_inline, nodebug)) static void CheckAddress(uptr
>> > p) {
>> > tag_t ptr_tag = GetTagFromPointer(p);
>> > uptr ptr_raw = p & ~kAddressTagMask;
>> > - tag_t mem_tag = *(tag_t *)MEM_TO_SHADOW(ptr_raw);
>> > + tag_t mem_tag = *(tag_t *)MemToShadow(ptr_raw);
>> > if (UNLIKELY(ptr_tag != mem_tag)) {
>> > SigTrap<0x20 * (EA == ErrorAction::Recover) +
>> > 0x10 * (AT == AccessType::Store) + LogSize>(p);
>> > @@ -319,8 +313,8 @@ __attribute__((always_inline, nodebug))
>> > CHECK_NE(0, sz);
>> > tag_t ptr_tag = GetTagFromPointer(p);
>> > uptr ptr_raw = p & ~kAddressTagMask;
>> > - tag_t *shadow_first = (tag_t *)MEM_TO_SHADOW(ptr_raw);
>> > - tag_t *shadow_last = (tag_t *)MEM_TO_SHADOW(ptr_raw + sz - 1);
>> > + tag_t *shadow_first = (tag_t *)MemToShadow(ptr_raw);
>> > + tag_t *shadow_last = (tag_t *)MemToShadow(ptr_raw + sz - 1);
>> > for (tag_t *t = shadow_first; t <= shadow_last; ++t)
>> > if (UNLIKELY(ptr_tag != *t)) {
>> > SigTrap<0x20 * (EA == ErrorAction::Recover) +
>> >
>> > Modified: compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc
>> > URL: http://llvm.org/viewvc/llvm-project/compiler-
>> > rt/trunk/lib/hwasan/hwasan_allocator.cc?rev=340983&r1=340982&r2=340983&
>> > view=diff
>> > =======================================================================
>> > =======
>> > --- compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc (original)
>> > +++ compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc Wed Aug 29
>> > 15:42:16 2018
>> > @@ -178,7 +178,7 @@ static bool PointerAndMemoryTagsMatch(vo
>> > CHECK(tagged_ptr);
>> > tag_t ptr_tag =
>> > GetTagFromPointer(reinterpret_cast<uptr>(tagged_ptr));
>> > tag_t mem_tag = *reinterpret_cast<tag_t *>(
>> > - MEM_TO_SHADOW(UntagPtr(tagged_ptr)));
>> > + MemToShadow(reinterpret_cast<uptr>(UntagPtr(tagged_ptr))));
>> > return ptr_tag == mem_tag;
>> > }
>> >
>> >
>> > Modified: compiler-rt/trunk/lib/hwasan/hwasan_dynamic_shadow.cc
>> > URL: http://llvm.org/viewvc/llvm-project/compiler-
>> > rt/trunk/lib/hwasan/hwasan_dynamic_shadow.cc?rev=340983&r1=340982&r2=34
>> > 0983&view=diff
>> > =======================================================================
>> > =======
>> > --- compiler-rt/trunk/lib/hwasan/hwasan_dynamic_shadow.cc (original)
>> > +++ compiler-rt/trunk/lib/hwasan/hwasan_dynamic_shadow.cc Wed Aug 29
>> > 15:42:16 2018
>> > @@ -58,8 +58,6 @@ static uptr MapDynamicShadow(uptr shadow
>> >
>> > } // namespace __hwasan
>> >
>> > -#if HWASAN_PREMAP_SHADOW
>> > -
>> > extern "C" {
>> >
>> > INTERFACE_ATTRIBUTE void __hwasan_shadow();
>> > @@ -117,15 +115,11 @@ void __hwasan_shadow();
>> >
>> > } // extern "C"
>> >
>> > -#endif // HWASAN_PREMAP_SHADOW
>> > -
>> > namespace __hwasan {
>> >
>> > uptr FindDynamicShadowStart(uptr shadow_size_bytes) {
>> > -#if HWASAN_PREMAP_SHADOW
>> > if (IsPremapShadowAvailable())
>> > return FindPremappedShadowStart(shadow_size_bytes);
>> > -#endif
>> > return MapDynamicShadow(shadow_size_bytes);
>> > }
>> >
>> >
>> > Modified: compiler-rt/trunk/lib/hwasan/hwasan_linux.cc
>> > URL: http://llvm.org/viewvc/llvm-project/compiler-
>> > rt/trunk/lib/hwasan/hwasan_linux.cc?rev=340983&r1=340982&r2=340983&view
>> > =diff
>> > =======================================================================
>> > =======
>> > --- compiler-rt/trunk/lib/hwasan/hwasan_linux.cc (original)
>> > +++ compiler-rt/trunk/lib/hwasan/hwasan_linux.cc Wed Aug 29 15:42:16
>> > 2018
>> > @@ -157,7 +157,7 @@ bool InitShadow() {
>> > kHighMemEnd = GetHighMemEnd();
>> >
>> > // Determine shadow memory base offset.
>> > - InitializeShadowBaseAddress(MEM_TO_SHADOW_SIZE(kHighMemEnd));
>> > + InitializeShadowBaseAddress(MemToShadowSize(kHighMemEnd));
>> >
>> > // Place the low memory first.
>> > if (SHADOW_OFFSET) {
>> > @@ -166,20 +166,20 @@ bool InitShadow() {
>> > } else {
>> > // LowMem covers as much of the first 4GB as possible.
>> > kLowMemEnd = (1UL << 32) - 1;
>> > - kLowMemStart = MEM_TO_SHADOW(kLowMemEnd) + 1;
>> > + kLowMemStart = MemToShadow(kLowMemEnd) + 1;
>> > }
>> >
>> > // Define the low shadow based on the already placed low memory.
>> > - kLowShadowEnd = MEM_TO_SHADOW(kLowMemEnd);
>> > - kLowShadowStart = SHADOW_OFFSET ? SHADOW_OFFSET :
>> > MEM_TO_SHADOW(kLowMemStart);
>> > + kLowShadowEnd = MemToShadow(kLowMemEnd);
>> > + kLowShadowStart = SHADOW_OFFSET ? SHADOW_OFFSET :
>> > MemToShadow(kLowMemStart);
>> >
>> > // High shadow takes whatever memory is left up there (making sure
>> > it is not
>> > // interfering with low memory in the fixed case).
>> > - kHighShadowEnd = MEM_TO_SHADOW(kHighMemEnd);
>> > - kHighShadowStart = Max(kLowMemEnd, MEM_TO_SHADOW(kHighShadowEnd)) +
>> > 1;
>> > + kHighShadowEnd = MemToShadow(kHighMemEnd);
>> > + kHighShadowStart = Max(kLowMemEnd, MemToShadow(kHighShadowEnd)) + 1;
>> >
>> > // High memory starts where allocated shadow allows.
>> > - kHighMemStart = SHADOW_TO_MEM(kHighShadowStart);
>> > + kHighMemStart = ShadowToMem(kHighShadowStart);
>> >
>> > // Check the sanity of the defined memory ranges (there might be
>> > gaps).
>> > CHECK_EQ(kHighMemStart % GetMmapGranularity(), 0);
>> >
>> > Modified: compiler-rt/trunk/lib/hwasan/hwasan_mapping.h
>> > URL: http://llvm.org/viewvc/llvm-project/compiler-
>> > rt/trunk/lib/hwasan/hwasan_mapping.h?rev=340983&r1=340982&r2=340983&vie
>> > w=diff
>> > =======================================================================
>> > =======
>> > --- compiler-rt/trunk/lib/hwasan/hwasan_mapping.h (original)
>> > +++ compiler-rt/trunk/lib/hwasan/hwasan_mapping.h Wed Aug 29 15:42:16
>> > 2018
>> > @@ -16,6 +16,7 @@
>> > #define HWASAN_MAPPING_H
>> >
>> > #include "sanitizer_common/sanitizer_internal_defs.h"
>> > +#include "hwasan_interface_internal.h"
>> >
>> > // Typical mapping on Linux/x86_64 with fixed shadow mapping:
>> > // || [0x080000000000, 0x7fffffffffff] || HighMem ||
>> > @@ -47,37 +48,28 @@
>> > // || [0x007477480000, 0x007bbebc7fff] || LowShadow ||
>> > // || [0x000000000000, 0x00747747ffff] || LowMem ||
>> >
>> > -static constexpr __sanitizer::u64 kDefaultShadowSentinel =
>> > ~(__sanitizer::u64)0;
>> > +static constexpr u64 kDefaultShadowSentinel = ~(u64)0;
>> >
>> > // Reasonable values are 4 (for 1/16th shadow) and 6 (for 1/64th).
>> > -constexpr __sanitizer::uptr kShadowScale = 4;
>> > -constexpr __sanitizer::uptr kShadowAlignment = 1ULL << kShadowScale;
>> > +constexpr uptr kShadowScale = 4;
>> > +constexpr uptr kShadowAlignment = 1ULL << kShadowScale;
>> >
>> > -#if SANITIZER_ANDROID
>> > -# define HWASAN_FIXED_MAPPING 0
>> > -#else
>> > -# define HWASAN_FIXED_MAPPING 1
>> > -#endif
>> > -
>> > -#if HWASAN_FIXED_MAPPING
>> > -# define SHADOW_OFFSET (0)
>> > -# define HWASAN_PREMAP_SHADOW 0
>> > -#else
>> > -# define SHADOW_OFFSET (__hwasan_shadow_memory_dynamic_address)
>> > -# define HWASAN_PREMAP_SHADOW 1
>> > -#endif
>> > +#define SHADOW_OFFSET (__hwasan_shadow_memory_dynamic_address)
>> >
>> > #define SHADOW_GRANULARITY (1ULL << kShadowScale)
>> >
>> > -#define MEM_TO_SHADOW(mem) (((uptr)(mem) >> kShadowScale) +
>> > SHADOW_OFFSET)
>> > -#define SHADOW_TO_MEM(shadow) (((uptr)(shadow) - SHADOW_OFFSET) <<
>> > kShadowScale)
>> > -
>> > -#define MEM_TO_SHADOW_SIZE(size) ((uptr)(size) >> kShadowScale)
>> > -
>> > -#define MEM_IS_APP(mem) MemIsApp((uptr)(mem))
>> > -
>> > namespace __hwasan {
>> >
>> > +inline uptr MemToShadow(uptr untagged_addr) {
>> > + return (untagged_addr >> kShadowScale) + SHADOW_OFFSET;
>> > +}
>> > +inline uptr ShadowToMem(uptr shadow_addr) {
>> > + return (shadow_addr - SHADOW_OFFSET) << kShadowScale;
>> > +}
>> > +inline uptr MemToShadowSize(uptr size) {
>> > + return size >> kShadowScale;
>> > +}
>> > +
>> > bool MemIsApp(uptr p);
>> >
>> > } // namespace __hwasan
>> >
>> > Modified: compiler-rt/trunk/lib/hwasan/hwasan_poisoning.cc
>> > URL: http://llvm.org/viewvc/llvm-project/compiler-
>> > rt/trunk/lib/hwasan/hwasan_poisoning.cc?rev=340983&r1=340982&r2=340983&
>> > view=diff
>> > =======================================================================
>> > =======
>> > --- compiler-rt/trunk/lib/hwasan/hwasan_poisoning.cc (original)
>> > +++ compiler-rt/trunk/lib/hwasan/hwasan_poisoning.cc Wed Aug 29
>> > 15:42:16 2018
>> > @@ -22,8 +22,8 @@ namespace __hwasan {
>> > uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) {
>> > CHECK(IsAligned(p, kShadowAlignment));
>> > CHECK(IsAligned(size, kShadowAlignment));
>> > - uptr shadow_start = MEM_TO_SHADOW(p);
>> > - uptr shadow_size = MEM_TO_SHADOW_SIZE(size);
>> > + uptr shadow_start = MemToShadow(p);
>> > + uptr shadow_size = MemToShadowSize(size);
>> > internal_memset((void *)shadow_start, tag, shadow_size);
>> > return AddTagToPointer(p, tag);
>> > }
>> >
>> > Modified: compiler-rt/trunk/lib/hwasan/hwasan_report.cc
>> > URL: http://llvm.org/viewvc/llvm-project/compiler-
>> > rt/trunk/lib/hwasan/hwasan_report.cc?rev=340983&r1=340982&r2=340983&vie
>> > w=diff
>> > =======================================================================
>> > =======
>> > --- compiler-rt/trunk/lib/hwasan/hwasan_report.cc (original)
>> > +++ compiler-rt/trunk/lib/hwasan/hwasan_report.cc Wed Aug 29 15:42:16
>> > 2018
>> > @@ -151,7 +151,7 @@ void ReportInvalidFree(StackTrace *stack
>> > ScopedErrorReportLock l;
>> > uptr untagged_addr = UntagAddr(tagged_addr);
>> > tag_t ptr_tag = GetTagFromPointer(tagged_addr);
>> > - tag_t *tag_ptr =
>> > reinterpret_cast<tag_t*>(MEM_TO_SHADOW(untagged_addr));
>> > + tag_t *tag_ptr =
>> > reinterpret_cast<tag_t*>(MemToShadow(untagged_addr));
>> > tag_t mem_tag = *tag_ptr;
>> > Decorator d;
>> > Printf("%s", d.Error());
>> > @@ -187,7 +187,7 @@ void ReportTagMismatch(StackTrace *stack
>> > untagged_addr, pc);
>> >
>> > tag_t ptr_tag = GetTagFromPointer(tagged_addr);
>> > - tag_t *tag_ptr =
>> > reinterpret_cast<tag_t*>(MEM_TO_SHADOW(untagged_addr));
>> > + tag_t *tag_ptr =
>> > reinterpret_cast<tag_t*>(MemToShadow(untagged_addr));
>> > tag_t mem_tag = *tag_ptr;
>> > Printf("%s", d.Access());
>> > Printf("%s of size %zu at %p tags: %02x/%02x (ptr/mem)\n",
>> >
>> > Modified: compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
>> > URL: http://llvm.org/viewvc/llvm-project/compiler-
>> > rt/trunk/lib/hwasan/hwasan_thread.cc?rev=340983&r1=340982&r2=340983&vie
>> > w=diff
>> > =======================================================================
>> > =======
>> > --- compiler-rt/trunk/lib/hwasan/hwasan_thread.cc (original)
>> > +++ compiler-rt/trunk/lib/hwasan/hwasan_thread.cc Wed Aug 29 15:42:16
>> > 2018
>> > @@ -54,15 +54,15 @@ void HwasanThread::SetThreadStackAndTls(
>> >
>> > int local;
>> > CHECK(AddrIsInStack((uptr)&local));
>> > - CHECK(MEM_IS_APP(stack_bottom_));
>> > - CHECK(MEM_IS_APP(stack_top_ - 1));
>> > + CHECK(MemIsApp(stack_bottom_));
>> > + CHECK(MemIsApp(stack_top_ - 1));
>> > }
>> >
>> > void HwasanThread::Init() {
>> > SetThreadStackAndTls();
>> > if (stack_bottom_) {
>> > - CHECK(MEM_IS_APP(stack_bottom_));
>> > - CHECK(MEM_IS_APP(stack_top_ - 1));
>> > + CHECK(MemIsApp(stack_bottom_));
>> > + CHECK(MemIsApp(stack_top_ - 1));
>> > }
>> > }
>> >
>> >
>> >
>> > _______________________________________________
>> > llvm-commits mailing list
>> > llvm-commits at lists.llvm.org
>> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list