Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CFI] Compilation error in Windows #41124

Open
llvmbot opened this issue May 7, 2019 · 1 comment
Open

[CFI] Compilation error in Windows #41124

llvmbot opened this issue May 7, 2019 · 1 comment
Labels
bugzilla Issues migrated from bugzilla compiler-rt:cfi Control Flow Integrity platform:windows

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented May 7, 2019

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.

@efriedma-quic
Copy link
Collaborator

It looks like clang is trying to perform LTO using link.exe, which is never going to work. The Microsoft linker doesn't support plugins like binutils.

"-fuse-ld=lld-link" should get you past that error. I guess it's a clang driver bug that -flto doesn't imply that.

Not sure if you'll run into any other issues.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@Endilll Endilll added compiler-rt:cfi Control Flow Integrity platform:windows labels Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla compiler-rt:cfi Control Flow Integrity platform:windows
Projects
None yet
Development

No branches or pull requests

3 participants