GJDuck/LowFat

Clang sometimes crashes with LowFat enabled

GJDuck opened this issue · 0 comments

Reported by Hu Hong:

Clang sometimes crashes with LowFat enabled. For example, the program:

#include <future>
int main () {
    return std::async([]{return 1;}).get();
}

will cause clang/LLVM to crash if LowFat is enabled:

$ clang++ -fsanitize=lowfat -std=c++11 -c crash.cpp
fatal error: error in backend: Cannot select: 0x593c230: i64 = X86ISD::WrapperRIP 
TargetGlobalTLSAddress:i64<i8** @_ZSt15__once_callable> 0 [TF=10]
  0x5875d20: i64 = TargetGlobalTLSAddress<i8** @_ZSt15__once_callable> 0 [TF=10]
In function: ...

The same crash occurs with unmodified clang/LLVM with the large code model enabled:

$ clang++-4.0 -std=c++11 -c crash.cpp -mcmodel=large
fatal error: error in backend: Cannot select: 0x46cdbd8: i64 = X86ISD::WrapperRIP 
TargetGlobalTLSAddress:i64<i8** @_ZSt15__once_callable> 0 [TF=10]
  0x46cd830: i64 = TargetGlobalTLSAddress<i8** @_ZSt15__once_callable> 0 [TF=10]
In function: ...

This suggests that the bug is in clang/LLVM itself and not LowFat (LowFat merely enables the large code model enabled when the -fsanitize=lowfat flag is present). The bug also appears in later versions of LLVM, and has been reported before:

http://lists.llvm.org/pipermail/llvm-bugs/2016-March/045572.html

The following options will work-around the problem, but also mean that globals will not be instrumented:

-mcmodel=small -mllvm -lowfat-no-replace-globals