Commit e1e1836
authored
[CodeGen] Inline stack guard check on Windows (#136290)
This patch optimizes the Windows security cookie check mechanism by
moving the comparison inline and only calling __security_check_cookie
when the check fails. This reduces the overhead of making a DLL call
for every function return.
Previously, we implemented this optimization through a machine pass
(X86WinFixupBufferSecurityCheckPass) in PR #95904 submitted by
@mahesh-attarde. We have reverted that pass in favor of this new
approach. Also we have abandoned the AArch64 specific implementation
of same pass in PR #121938 in favor of this more general solution.
The old machine instruction pass approach:
- Scanned the generated code to find __security_check_cookie calls
- Modified these calls by splitting basic blocks
- Added comparison logic and conditional branching
- Required complex block management and live register computation
The new approach:
- Implements the same optimization during instruction selection
- Directly emits the comparison and conditional branching
- No need for post-processing or basic block manipulation
- Disables optimization at -Oz.
Thanks @tamaspetz, @efriedma-quic and @arsenm for their help.1 parent cc17f68 commit e1e1836
File tree
12 files changed
+333
-313
lines changed- llvm
- lib
- CodeGen/SelectionDAG
- Target/X86
- test
- CodeGen
- AArch64/GlobalISel
- X86
- DebugInfo/COFF
12 files changed
+333
-313
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3037 | 3037 | | |
3038 | 3038 | | |
3039 | 3039 | | |
3040 | | - | |
3041 | | - | |
| 3040 | + | |
| 3041 | + | |
| 3042 | + | |
3042 | 3043 | | |
3043 | 3044 | | |
3044 | 3045 | | |
| |||
3047 | 3048 | | |
3048 | 3049 | | |
3049 | 3050 | | |
3050 | | - | |
3051 | | - | |
| 3051 | + | |
| 3052 | + | |
3052 | 3053 | | |
3053 | 3054 | | |
3054 | 3055 | | |
| |||
3059 | 3060 | | |
3060 | 3061 | | |
3061 | 3062 | | |
3062 | | - | |
3063 | | - | |
| 3063 | + | |
| 3064 | + | |
| 3065 | + | |
| 3066 | + | |
| 3067 | + | |
| 3068 | + | |
| 3069 | + | |
| 3070 | + | |
3064 | 3071 | | |
3065 | 3072 | | |
3066 | 3073 | | |
| |||
3101 | 3108 | | |
3102 | 3109 | | |
3103 | 3110 | | |
3104 | | - | |
3105 | | - | |
3106 | | - | |
3107 | | - | |
| 3111 | + | |
| 3112 | + | |
| 3113 | + | |
3108 | 3114 | | |
3109 | 3115 | | |
3110 | 3116 | | |
| |||
3126 | 3132 | | |
3127 | 3133 | | |
3128 | 3134 | | |
3129 | | - | |
3130 | | - | |
| 3135 | + | |
| 3136 | + | |
| 3137 | + | |
3131 | 3138 | | |
3132 | | - | |
3133 | | - | |
3134 | | - | |
3135 | | - | |
3136 | | - | |
| 3139 | + | |
| 3140 | + | |
| 3141 | + | |
| 3142 | + | |
| 3143 | + | |
| 3144 | + | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
| 3180 | + | |
| 3181 | + | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
3137 | 3198 | | |
3138 | 3199 | | |
3139 | 3200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1877 | 1877 | | |
1878 | 1878 | | |
1879 | 1879 | | |
1880 | | - | |
| 1880 | + | |
1881 | 1881 | | |
1882 | 1882 | | |
1883 | 1883 | | |
| |||
1950 | 1950 | | |
1951 | 1951 | | |
1952 | 1952 | | |
1953 | | - | |
1954 | | - | |
| 1953 | + | |
1955 | 1954 | | |
1956 | 1955 | | |
1957 | 1956 | | |
| |||
1973 | 1972 | | |
1974 | 1973 | | |
1975 | 1974 | | |
1976 | | - | |
1977 | | - | |
| 1975 | + | |
1978 | 1976 | | |
1979 | 1977 | | |
1980 | 1978 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
89 | 88 | | |
90 | 89 | | |
91 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | 76 | | |
80 | 77 | | |
81 | 78 | | |
| |||
195 | 192 | | |
196 | 193 | | |
197 | 194 | | |
198 | | - | |
199 | 195 | | |
200 | 196 | | |
201 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
554 | 554 | | |
555 | 555 | | |
556 | 556 | | |
557 | | - | |
558 | 557 | | |
559 | 558 | | |
560 | 559 | | |
| |||
0 commit comments