Description
Bugzilla Link | 41779 |
Version | 8.0 |
OS | Windows NT |
Attachments | A C++ program that makes function calls through function pointers |
Reporter | LLVM Bugzilla Contributor |
CC | @efriedma-quic,@rnk |
Extended Description
I was testing LLVM Control Flow Integrity (CFI) on x64 Windows 10. The c++ source code attached makes a function call through a function pointer in an intensive loop. Which function will be called is based on the parity of a random integer. With CFI enabled (using flags -fsanitize=cfi and -flto), such function calls should be compiled to indirect calls. This works perfectly in Linux, but I got a compilation error in Windows using the same command:
C:\Users\Xiaoyang\Dropbox\CFIBenchmarks\fptr>clang++ -fsanitize=cfi -flto -o fptr.exe fptr.cpp
C:\Users\Xiaoyang\AppData\Local\Temp\fptr-3c8ec9.o : fatal error LNK1107: invalid or corrupt file: cannot read at 0x1CB0
clang++.exe: error: linker command failed with exit code 1107 (use -v to see invocation)
If I remove the CFI and link-time optimization flags, I can successfully compile and run this program:
C:\Users\Xiaoyang\Dropbox\CFIBenchmarks\fptr>clang++ fptr.cpp -o fptr.exe
C:\Users\Xiaoyang\Dropbox\CFIBenchmarks\fptr>fptr.exe
49893 odd numbers
50107 even numbers
I got this error in both LLVM 8.0.0 and 7.0.1.