Issue 104393
Summary [stack guard] Stack guard overhead on Windows platform
Labels new issue
Assignees
Reporter wenqinI
    ## Background
Recently I found the stack guard will bring obviously bigger overhead on Windows than Linux or MacOS, for Speedometer3 (a popular WEB/browser benchmark), it shows about **6-7%** performance improvement with `\GS-` flag on Windows, but just **~1%** improvement with `-fno-stack-protector` on Linux or MacOS.

Under such a background, I did some more research on this, it shows that compared with Linux platform there is more operations stack guard do on Windows platform.

In summary, Windows did 3 more operations:

1. Instead of inlining stack check into caller, Windows platform implement stack check by calling a function.
2. More instructions for checking higher 16 bits is 0 or not in security cookie.
3. More instructions for XOR the rsp register for cookie.

## POC
At current stage, I though the operation 1 and 2 mentioned above may not really help on improving security, so I tried to remove them by  customizing LLVM, it shows **~3%** performance improvement for Speedometer3.

Here is dsm code for a function inside chromium, with `/GS-` flag or custimozed LLVM.

![image](https://github.com/user-attachments/assets/5f1f5001-5a5d-4aff-a8e4-29cddbac149a)


I also filed an [issue](https://issues.chromium.org/issues/352371722) in chromium issue tracker, please check more details in it if you're interested in.

## What could we do
If this approach makes sense, I will clean up the code for LLVM on my local and plan to submit a PR which could ship this feature behind a flag (like `/GS-Unixalike`), WDYT?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to