@@ -1356,20 +1356,34 @@ func (ctxt *Link) hostlink() {
1356
1356
case objabi .Hwindows :
1357
1357
if windowsgui {
1358
1358
argv = append (argv , "-mwindows" )
1359
+ if usingClangForMSVC {
1360
+ argv = append (argv , "-Wl,/SUBSYSTEM:WINDOWS" )
1361
+ }
1359
1362
} else {
1360
1363
argv = append (argv , "-mconsole" )
1364
+ if usingClangForMSVC {
1365
+ argv = append (argv , "-Wl,/SUBSYSTEM:CONSOLE" )
1366
+ }
1361
1367
}
1362
- // Mark as having awareness of terminal services, to avoid
1363
- // ancient compatibility hacks.
1364
- argv = append (argv , "-Wl,--tsaware" )
1368
+ // The linker of MSVC have defferent flags from the linker of Mingw/GCC,
1369
+ // and some flags for Mingw/GCC are not supported by MSVC.
1370
+ if usingClangForMSVC {
1371
+ argv = append (argv , "-Wl,/TSAWARE" )
1372
+ argv = append (argv , "-Wl,/NXCOMPAT" )
1373
+ } else {
1374
+ // Mark as having awareness of terminal services, to avoid
1375
+ // ancient compatibility hacks.
1376
+ argv = append (argv , "-Wl,--tsaware" )
1377
+
1378
+ // Enable DEP
1379
+ argv = append (argv , "-Wl,--nxcompat" )
1365
1380
1366
- // Enable DEP
1367
- argv = append (argv , "-Wl,--nxcompat" )
1381
+ argv = append (argv , fmt .Sprintf ("-Wl,--major-os-version=%d" , PeMinimumTargetMajorVersion ))
1382
+ argv = append (argv , fmt .Sprintf ("-Wl,--minor-os-version=%d" , PeMinimumTargetMinorVersion ))
1383
+ argv = append (argv , fmt .Sprintf ("-Wl,--major-subsystem-version=%d" , PeMinimumTargetMajorVersion ))
1384
+ argv = append (argv , fmt .Sprintf ("-Wl,--minor-subsystem-version=%d" , PeMinimumTargetMinorVersion ))
1385
+ }
1368
1386
1369
- argv = append (argv , fmt .Sprintf ("-Wl,--major-os-version=%d" , PeMinimumTargetMajorVersion ))
1370
- argv = append (argv , fmt .Sprintf ("-Wl,--minor-os-version=%d" , PeMinimumTargetMinorVersion ))
1371
- argv = append (argv , fmt .Sprintf ("-Wl,--major-subsystem-version=%d" , PeMinimumTargetMajorVersion ))
1372
- argv = append (argv , fmt .Sprintf ("-Wl,--minor-subsystem-version=%d" , PeMinimumTargetMinorVersion ))
1373
1387
case objabi .Haix :
1374
1388
argv = append (argv , "-pthread" )
1375
1389
// prevent ld to reorder .text functions to keep the same
0 commit comments