This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Fix legacy ZExt emission when FromBits >= 64 (PR47927)
ClosedPublic

Authored by vsk on Oct 20 2020, 5:11 PM.

Details

Summary

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

Diff Detail

Event Timeline

vsk created this revision.Oct 20 2020, 5:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2020, 5:11 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
vsk requested review of this revision.Oct 20 2020, 5:11 PM

Some nits below but in general looks good to me.

llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
658

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.

llvm/test/DebugInfo/X86/legacy-zext.ll
9

I guess it does not matter much for what we want to test here but shouldn't !9 be a 128-bit type for this to make sense?

Ummm the default expression-stack type is address-sized, and I'm not aware that we support machines with address sizes > 64 bits?
(DWARF 5 does have a typed stack, but IIUC this path is not used for DWARF 5.)

vsk added a comment.Oct 21 2020, 8:47 AM

Ummm the default expression-stack type is address-sized, and I'm not aware that we support machines with address sizes > 64 bits?
(DWARF 5 does have a typed stack, but IIUC this path is not used for DWARF 5.)

@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?

llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
658

Yes. Fwiw, I did try adding an emitUnsigned(APInt) API to DwarfExpression, but decided to not pursue that direction because the patch become very large. Ideally there'd be a simpler fix that serves.

llvm/test/DebugInfo/X86/legacy-zext.ll
9

Yes, !9 should be a 128-bit type. I'll fix this in the next revision.

vsk updated this revision to Diff 299709.Oct 21 2020, 8:57 AM
  • Use DW_OP_bit_piece to implement the legacy zext.
vsk updated this revision to Diff 299722.Oct 21 2020, 9:30 AM
  • Actually fix the size of the DILocalVar.
vsk added a comment.Oct 27 2020, 10:41 AM

Friendly ping.

aprantl accepted this revision.Oct 27 2020, 6:45 PM
This revision is now accepted and ready to land.Oct 27 2020, 6:45 PM
This revision was landed with ongoing or failed builds.Oct 28 2020, 12:06 PM
This revision was automatically updated to reflect the committed changes.

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
vsk added a comment.Oct 28 2020, 6:55 PM

I'll revert.