| ... | ... | @@ -1170,10 +1170,6 @@ fn addCCArgs( |
| 1170 | 1170 | if (ext == .cpp) { |
| 1171 | 1171 | try argv.append("-nostdinc++"); |
| 1172 | 1172 | } |
| 1173 | | try argv.appendSlice(&[_][]const u8{ |
| 1174 | | "-nostdinc", |
| 1175 | | "-fno-spell-checking", |
| 1176 | | }); |
| 1177 | 1173 | |
| 1178 | 1174 | // We don't ever put `-fcolor-diagnostics` or `-fno-color-diagnostics` because in passthrough mode |
| 1179 | 1175 | // we want Clang to infer it, and in normal mode we always want it off, which will be true since |
| ... | ... | @@ -1219,6 +1215,11 @@ fn addCCArgs( |
| 1219 | 1215 | |
| 1220 | 1216 | switch (ext) { |
| 1221 | 1217 | .c, .cpp, .h => { |
| 1218 | try argv.appendSlice(&[_][]const u8{ |
| 1219 | "-nostdinc", |
| 1220 | "-fno-spell-checking", |
| 1221 | }); |
| 1222 | |
| 1222 | 1223 | // According to Rich Felker libc headers are supposed to go before C language headers. |
| 1223 | 1224 | // However as noted by @dimenus, appending libc headers before c_headers breaks intrinsics |
| 1224 | 1225 | // and other compiler specific items. |
| ... | ... | @@ -1260,6 +1261,75 @@ fn addCCArgs( |
| 1260 | 1261 | try argv.append("-Xclang"); |
| 1261 | 1262 | try argv.append("-detailed-preprocessing-record"); |
| 1262 | 1263 | } |
| 1264 | |
| 1265 | // windows.h has files such as pshpack1.h which do #pragma packing, triggering a clang warning. |
| 1266 | // So for this target, we disable this warning. |
| 1267 | if (target.os.tag == .windows and target.abi.isGnu()) { |
| 1268 | try argv.append("-Wno-pragma-pack"); |
| 1269 | } |
| 1270 | |
| 1271 | if (!comp.bin_file.options.strip) { |
| 1272 | try argv.append("-g"); |
| 1273 | } |
| 1274 | |
| 1275 | if (comp.haveFramePointer()) { |
| 1276 | try argv.append("-fno-omit-frame-pointer"); |
| 1277 | } else { |
| 1278 | try argv.append("-fomit-frame-pointer"); |
| 1279 | } |
| 1280 | |
| 1281 | if (comp.sanitize_c) { |
| 1282 | try argv.append("-fsanitize=undefined"); |
| 1283 | try argv.append("-fsanitize-trap=undefined"); |
| 1284 | } |
| 1285 | |
| 1286 | switch (comp.bin_file.options.optimize_mode) { |
| 1287 | .Debug => { |
| 1288 | // windows c runtime requires -D_DEBUG if using debug libraries |
| 1289 | try argv.append("-D_DEBUG"); |
| 1290 | try argv.append("-Og"); |
| 1291 | |
| 1292 | if (comp.bin_file.options.link_libc) { |
| 1293 | try argv.append("-fstack-protector-strong"); |
| 1294 | try argv.append("--param"); |
| 1295 | try argv.append("ssp-buffer-size=4"); |
| 1296 | } else { |
| 1297 | try argv.append("-fno-stack-protector"); |
| 1298 | } |
| 1299 | }, |
| 1300 | .ReleaseSafe => { |
| 1301 | // See the comment in the BuildModeFastRelease case for why we pass -O2 rather |
| 1302 | // than -O3 here. |
| 1303 | try argv.append("-O2"); |
| 1304 | if (comp.bin_file.options.link_libc) { |
| 1305 | try argv.append("-D_FORTIFY_SOURCE=2"); |
| 1306 | try argv.append("-fstack-protector-strong"); |
| 1307 | try argv.append("--param"); |
| 1308 | try argv.append("ssp-buffer-size=4"); |
| 1309 | } else { |
| 1310 | try argv.append("-fno-stack-protector"); |
| 1311 | } |
| 1312 | }, |
| 1313 | .ReleaseFast => { |
| 1314 | try argv.append("-DNDEBUG"); |
| 1315 | // Here we pass -O2 rather than -O3 because, although we do the equivalent of |
| 1316 | // -O3 in Zig code, the justification for the difference here is that Zig |
| 1317 | // has better detection and prevention of undefined behavior, so -O3 is safer for |
| 1318 | // Zig code than it is for C code. Also, C programmers are used to their code |
| 1319 | // running in -O2 and thus the -O3 path has been tested less. |
| 1320 | try argv.append("-O2"); |
| 1321 | try argv.append("-fno-stack-protector"); |
| 1322 | }, |
| 1323 | .ReleaseSmall => { |
| 1324 | try argv.append("-DNDEBUG"); |
| 1325 | try argv.append("-Os"); |
| 1326 | try argv.append("-fno-stack-protector"); |
| 1327 | }, |
| 1328 | } |
| 1329 | |
| 1330 | if (target_util.supports_fpic(target) and comp.bin_file.options.pic) { |
| 1331 | try argv.append("-fPIC"); |
| 1332 | } |
| 1263 | 1333 | }, |
| 1264 | 1334 | .so, .assembly, .ll, .bc, .unknown => {}, |
| 1265 | 1335 | } |
| ... | ... | @@ -1285,75 +1355,6 @@ fn addCCArgs( |
| 1285 | 1355 | try argv.append("-ffreestanding"); |
| 1286 | 1356 | } |
| 1287 | 1357 | |
| 1288 | | // windows.h has files such as pshpack1.h which do #pragma packing, triggering a clang warning. |
| 1289 | | // So for this target, we disable this warning. |
| 1290 | | if (target.os.tag == .windows and target.abi.isGnu()) { |
| 1291 | | try argv.append("-Wno-pragma-pack"); |
| 1292 | | } |
| 1293 | | |
| 1294 | | if (!comp.bin_file.options.strip) { |
| 1295 | | try argv.append("-g"); |
| 1296 | | } |
| 1297 | | |
| 1298 | | if (comp.haveFramePointer()) { |
| 1299 | | try argv.append("-fno-omit-frame-pointer"); |
| 1300 | | } else { |
| 1301 | | try argv.append("-fomit-frame-pointer"); |
| 1302 | | } |
| 1303 | | |
| 1304 | | if (comp.sanitize_c) { |
| 1305 | | try argv.append("-fsanitize=undefined"); |
| 1306 | | try argv.append("-fsanitize-trap=undefined"); |
| 1307 | | } |
| 1308 | | |
| 1309 | | switch (comp.bin_file.options.optimize_mode) { |
| 1310 | | .Debug => { |
| 1311 | | // windows c runtime requires -D_DEBUG if using debug libraries |
| 1312 | | try argv.append("-D_DEBUG"); |
| 1313 | | try argv.append("-Og"); |
| 1314 | | |
| 1315 | | if (comp.bin_file.options.link_libc) { |
| 1316 | | try argv.append("-fstack-protector-strong"); |
| 1317 | | try argv.append("--param"); |
| 1318 | | try argv.append("ssp-buffer-size=4"); |
| 1319 | | } else { |
| 1320 | | try argv.append("-fno-stack-protector"); |
| 1321 | | } |
| 1322 | | }, |
| 1323 | | .ReleaseSafe => { |
| 1324 | | // See the comment in the BuildModeFastRelease case for why we pass -O2 rather |
| 1325 | | // than -O3 here. |
| 1326 | | try argv.append("-O2"); |
| 1327 | | if (comp.bin_file.options.link_libc) { |
| 1328 | | try argv.append("-D_FORTIFY_SOURCE=2"); |
| 1329 | | try argv.append("-fstack-protector-strong"); |
| 1330 | | try argv.append("--param"); |
| 1331 | | try argv.append("ssp-buffer-size=4"); |
| 1332 | | } else { |
| 1333 | | try argv.append("-fno-stack-protector"); |
| 1334 | | } |
| 1335 | | }, |
| 1336 | | .ReleaseFast => { |
| 1337 | | try argv.append("-DNDEBUG"); |
| 1338 | | // Here we pass -O2 rather than -O3 because, although we do the equivalent of |
| 1339 | | // -O3 in Zig code, the justification for the difference here is that Zig |
| 1340 | | // has better detection and prevention of undefined behavior, so -O3 is safer for |
| 1341 | | // Zig code than it is for C code. Also, C programmers are used to their code |
| 1342 | | // running in -O2 and thus the -O3 path has been tested less. |
| 1343 | | try argv.append("-O2"); |
| 1344 | | try argv.append("-fno-stack-protector"); |
| 1345 | | }, |
| 1346 | | .ReleaseSmall => { |
| 1347 | | try argv.append("-DNDEBUG"); |
| 1348 | | try argv.append("-Os"); |
| 1349 | | try argv.append("-fno-stack-protector"); |
| 1350 | | }, |
| 1351 | | } |
| 1352 | | |
| 1353 | | if (target_util.supports_fpic(target) and comp.bin_file.options.pic) { |
| 1354 | | try argv.append("-fPIC"); |
| 1355 | | } |
| 1356 | | |
| 1357 | 1358 | try argv.appendSlice(comp.clang_argv); |
| 1358 | 1359 | } |
| 1359 | 1360 | |