Fix an out-of-bounds shift in emitLegacyZExt by using a slightly more
complicated dwarf expression to create the zext mask.
This addresses a UBSan diagnostic seen when compiling compiler-rt
(llvm.org/PR47927).
rdar://70307714
Differential D89838
[DebugInfo] Fix legacy ZExt emission when FromBits >= 64 (PR47927) vsk on Oct 20 2020, 5:11 PM. Authored by
Details Fix an out-of-bounds shift in emitLegacyZExt by using a slightly more This addresses a UBSan diagnostic seen when compiling compiler-rt rdar://70307714
Diff Detail
Event TimelineComment Actions Some nits below but in general looks good to me.
Comment Actions Ummm the default expression-stack type is address-sized, and I'm not aware that we support machines with address sizes > 64 bits? Comment Actions @probinson thanks for catching this. Would it be appropriate to use two DW_OP_bit_pieces to implement the zext, like: DW_OP_breg5 RDI+0, DW_OP_bit_piece 64 0, DW_OP_lit0, DW_OP_bit_piece 64 64?
Comment Actions From http://lab.llvm.org:8011/#/builders/70/builds/418 3%] Linking CXX shared library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.scudo-i386.so [ 93%] Built target RTXrayPROFILING.x86_64 clang: /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp:485: void llvm::DwarfExpression::addExpression(llvm::DIExpressionCursor&&, unsigned int): Assertion `SizeInBits >= OffsetInBits - FragmentOffset && "size underflow"' failed. PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/./bin/clang -DVISIBILITY_HIDDEN -Wall -Wno-unused-parameter -O2 -g -DNDEBUG -m64 -fno-lto -std=c11 -fPIC -fno-builtin -fvisibility=hidden -o CMakeFiles/clang_rt.builtins-x86_64.dir/fixunsxfti.c.o -c /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/builtins/fixunsxfti.c 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module '/b/sanitizer-x86_64-linux-autoconf/build/llvm-project/compiler-rt/lib/builtins/fixunsxfti.c'. 4. Running pass 'X86 Assembly Printer' on function '@__fixunsxfti' [ 93%] Built target clang_rt.ubsan_standalone_cxx-x86_64-symbols [ 93%] Linking CXX static library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.scudo_minimal-x86_64.a [ 93%] Built target clang_rt.asan_cxx-x86_64-symbols [ 93%] Linking CXX static library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.scudo-x86_64.a [ 93%] Built target clang_rt.builtins-i386 Scanning dependencies of target clang_rt.xray-profiling-x86_64 -- The C compiler identification is Clang 12.0.0 [ 93%] Built target clang_rt.ubsan_standalone-x86_64-symbols [ 93%] Linking CXX static library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.scudo_minimal-i386.a -- The C compiler identification is Clang 12.0.0 Scanning dependencies of target RTHwasan_dynamic_version_script_dummy.x86_64 Scanning dependencies of target RTUbsan_dynamic_version_script_dummy.x86_64 [ 93%] Built target clang_rt.msan_cxx-x86_64-symbols [ 93%] Built target clang_rt.dfsan-x86_64-symbols Scanning dependencies of target RTUbsan_dynamic_version_script_dummy.i386 [ 93%] Built target clang_rt.hwasan_cxx-x86_64-symbols [ 93%] Linking CXX static library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.xray-profiling-x86_64.a [ 93%] Built target clang_rt.tsan_cxx-x86_64-symbols [ 93%] Building CXX object lib/hwasan/CMakeFiles/RTHwasan_dynamic_version_script_dummy.x86_64.dir/dummy.cpp.o [ 93%] Linking CXX shared library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.scudo_minimal-i386.so Scanning dependencies of target dfsan [ 93%] Building CXX object lib/ubsan/CMakeFiles/RTUbsan_dynamic_version_script_dummy.x86_64.dir/dummy.cpp.o [ 93%] Building CXX object lib/ubsan/CMakeFiles/RTUbsan_dynamic_version_script_dummy.i386.dir/dummy.cpp.o [ 93%] Built target dfsan [ 93%] Built target clang_rt.hwasan-x86_64-symbols [ 93%] Built target clang_rt.scudo-dynamic-x86_64 [ 93%] Built target RTScudoCUnitTest.i386 [ 93%] Built target clang_rt.ubsan_minimal-x86_64-symbols [ 93%] Built target clang_rt.scudo_minimal-dynamic-x86_64 [ 93%] Linking CXX static library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.stats-x86_64.a Scanning dependencies of target ubsan-minimal [ 93%] Built target RTHwasan_dynamic_version_script_dummy.x86_64 [ 93%] Built target clang_rt.scudo_minimal-x86_64 [ 93%] Built target clang_rt.scudo-x86_64 [ 93%] Built target clang_rt.scudo-i386 [ 93%] Built target RTUbsan_dynamic_version_script_dummy.x86_64 -- The CXX compiler identification is Clang 12.0.0 -- The CXX compiler identification is Clang 12.0.0 [ 93%] Built target ubsan-minimal [ 93%] Built target RTUbsan_dynamic_version_script_dummy.i386 -- Check for working C compiler: /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/./bin/clang [ 93%] Built target clang_rt.xray-profiling-x86_64 Scanning dependencies of target clang_rt.hwasan-dynamic-x86_64 -- Check for working C compiler: /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/./bin/clang [ 93%] Built target clang_rt.scudo_minimal-i386 [ 93%] Built target clang_rt.scudo-dynamic-i386 Scanning dependencies of target clang_rt.ubsan_standalone-dynamic-x86_64 Scanning dependencies of target clang_rt.ubsan_standalone-dynamic-i386 [ 93%] Linking CXX shared library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.hwasan-x86_64.so [ 93%] Built target clang_rt.scudo_minimal-dynamic-i386 [ 93%] Linking CXX static library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.scudo_standalone_cxx-x86_64.a [ 93%] Linking CXX shared library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.ubsan_standalone-x86_64.so [ 93%] Linking CXX shared library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.ubsan_standalone-i386.so Scanning dependencies of target scudo [ 93%] Built target clang_rt.stats-x86_64 [ 93%] Built target scudo [ 93%] Built target clang_rt.scudo_standalone_cxx-x86_64 [ 93%] Built target RTXrayFDR.x86_64 -- Check for working C compiler: /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/./bin/clang -- works -- Detecting C compiler ABI info [ 93%] Built target clang_rt.ubsan_standalone-dynamic-x86_64 -- Check for working C compiler: /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/./bin/clang -- works -- Detecting C compiler ABI info [ 93%] Built target clang_rt.ubsan_standalone-dynamic-i386 [ 93%] Built target clang_rt.hwasan-dynamic-x86_64 Scanning dependencies of target clang_rt.xray-fdr-x86_64 Scanning dependencies of target RTXRay.test.x86_64 Scanning dependencies of target ubsan Scanning dependencies of target hwasan [ 93%] Linking CXX static library libRTXRay.test.x86_64.a [ 93%] Linking CXX static library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.xray-fdr-x86_64.a [ 93%] Built target ubsan [ 93%] Built target hwasan [ 93%] Linking CXX static library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.scudo_standalone_cxx-i386.a [ 93%] Built target clang_rt.xray-fdr-x86_64 [ 93%] Linking CXX static library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.scudo_standalone-x86_64.a Scanning dependencies of target xray [ 93%] Built target RTXRay.test.x86_64 -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compiler ABI info - done -- Detecting C compile features [ 93%] Built target xray [ 93%] Built target clang_rt.scudo_standalone_cxx-i386 [ 93%] Built target clang_rt.scudo_standalone-x86_64 [ 93%] Linking CXX static library /b/sanitizer-x86_64-linux-autoconf/build/tsan_debug_build/lib/clang/12.0.0/lib/linux/libclang_rt.scudo_standalone-i386.a [ 93%] Built target clang_rt.scudo_standalone-i386 Scanning dependencies of target scudo_standalone [ 93%] Built target scudo_standalone #0 0x000055654593162c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/llvm/lib/Support/Unix/Signals.inc:567:3 #1 0x000055654592f434 llvm::sys::RunSignalHandlers() /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/llvm/lib/Support/Signals.cpp:71:20 #2 0x000055654592fc59 llvm::sys::CleanupOnSignal(unsigned long) /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/llvm/lib/Support/Unix/Signals.inc:361:31 #3 0x00005565458acaa8 HandleCrash /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:73:27 #4 0x00005565458acaa8 CrashRecoverySignalHandler(int) /b/sanitizer-x86_64-linux-autoconf/build/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:388:62 #5 0x00007f9755ae2730 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12730) #6 0x00007f97553c87bb raise (/lib/x86_64-linux-gnu/libc.so.6+0x377bb) #7 0x00007f97553b3535 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22535) #8 0x00007f97553b340f (/lib/x86_64-linux-gnu/libc.so.6+0x2240f) #9 0x00007f97553c1102 (/lib/x86_64-linux-gnu/libc.so.6+0x30102) #10 0x00005565463e90ef llvm::DwarfExpression::addExpression(llvm::DIExpr |
I think this is a good middle ground solution.
Perhaps if one wanted to be more generic and do something about the current inability to encode arbitrarily large constants in the Dwarf expression one could make a generic DwarfExpression method that takes an APInt and encodes it with a shift and or sequence.