Skip to content

Commit 767fc49

Browse files
committed
utils: Update debug flags
* Always build with debug information on Android, even when `CDebugFormat` is set to `codeview` * Move the Windows ASM debug flags to the ASM section. * Add the Windows linker flags in the common Windows section, and always add the common Windows linker flags. * Add `-ffunction-sections` and `-fdata-sections` for Android.
1 parent 573607f commit 767fc49

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

utils/build.ps1

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,27 @@ function Build-CMakeProject {
13671367
Add-KeyValueIfNew $Defines CMAKE_ASM_COMPILER $ASM
13681368
Add-KeyValueIfNew $Defines CMAKE_ASM_FLAGS @("--target=$($Platform.Triple)")
13691369
Add-KeyValueIfNew $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "/MD"
1370+
1371+
if ($DebugInfo) {
1372+
$ASMDebugFlags = if ($CDebugFormat -eq "dwarf") {
1373+
if ($UseGNUDriver) {
1374+
@("-gdwarf")
1375+
} else {
1376+
@("-clang:-gdwarf")
1377+
}
1378+
} else {
1379+
if ($UseGNUDriver) {
1380+
@("-gcodeview")
1381+
} else {
1382+
@("-clang:-gcodeview")
1383+
}
1384+
}
1385+
1386+
# CMake does not set a default value for the ASM compiler debug
1387+
# information format flags with non-MSVC compilers, so we explicitly
1388+
# set a default here.
1389+
Add-FlagsDefine $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_Embedded $ASMDebugFlags
1390+
}
13701391
}
13711392

13721393
if ($UseASM_MASM) {
@@ -1506,25 +1527,31 @@ function Build-CMakeProject {
15061527
Add-FlagsDefine $Defines CMAKE_Swift_FLAGS_RELWITHDEBINFO "-O"
15071528
}
15081529

1530+
$LinkerFlags = if ($UseGNUDriver) {
1531+
@("-Xlinker", "/INCREMENTAL:NO", "-Xlinker", "/OPT:REF", "-Xlinker", "/OPT:ICF")
1532+
} else {
1533+
@("/INCREMENTAL:NO", "/OPT:REF", "/OPT:ICF")
1534+
}
1535+
15091536
if ($DebugInfo) {
15101537
if ($UseASM -or $UseC -or $UseCXX) {
15111538
# Prefer `/Z7` over `/ZI`
1539+
# By setting the debug information format, the appropriate C/C++
1540+
# flags will be set for codeview debug information format so there
1541+
# is no need to set them explicitly above.
15121542
Add-KeyValueIfNew $Defines CMAKE_MSVC_DEBUG_INFORMATION_FORMAT Embedded
15131543
Add-KeyValueIfNew $Defines CMAKE_POLICY_DEFAULT_CMP0141 NEW
1514-
if ($UseASM) {
1515-
# The ASM compiler does not support `/Z7` so we use `/Zi` instead.
1516-
Add-FlagsDefine $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_Embedded "-Zi"
1517-
}
15181544

1519-
if ($UseGNUDriver) {
1520-
Add-FlagsDefine $Defines CMAKE_EXE_LINKER_FLAGS @("-Xlinker", "-debug")
1521-
Add-FlagsDefine $Defines CMAKE_SHARED_LINKER_FLAGS @("-Xlinker", "-debug")
1545+
$LinkerFlags += if ($UseGNUDriver) {
1546+
@("-Xlinker", "/DEBUG")
15221547
} else {
1523-
Add-FlagsDefine $Defines CMAKE_EXE_LINKER_FLAGS @("/debug")
1524-
Add-FlagsDefine $Defines CMAKE_SHARED_LINKER_FLAGS @("/debug")
1548+
@("/DEBUG")
15251549
}
15261550
}
15271551
}
1552+
1553+
Add-FlagsDefine $Defines CMAKE_EXE_LINKER_FLAGS $LinkerFlags
1554+
Add-FlagsDefine $Defines CMAKE_SHARED_LINKER_FLAGS $LinkerFlags
15281555
}
15291556

15301557
Android {
@@ -1542,8 +1569,8 @@ function Build-CMakeProject {
15421569
if ($UseC) {
15431570
Add-KeyValueIfNew $Defines CMAKE_C_COMPILER_TARGET $Platform.Triple
15441571

1545-
$CFLAGS = @("--sysroot=${AndroidSysroot}")
1546-
if ($DebugInfo -and ($CDebugFormat -eq "dwarf")) {
1572+
$CFLAGS = @("--sysroot=${AndroidSysroot}", "-ffunction-sections", "-fdata-sections")
1573+
if ($DebugInfo) {
15471574
$CFLAGS += @("-gdwarf")
15481575
}
15491576
Add-FlagsDefine $Defines CMAKE_C_FLAGS $CFLAGS
@@ -1552,8 +1579,8 @@ function Build-CMakeProject {
15521579
if ($UseCXX) {
15531580
Add-KeyValueIfNew $Defines CMAKE_CXX_COMPILER_TARGET $Platform.Triple
15541581

1555-
$CXXFLAGS = @("--sysroot=${AndroidSysroot}")
1556-
if ($DebugInfo -and ($CDebugFormat -eq "dwarf")) {
1582+
$CXXFLAGS = @("--sysroot=${AndroidSysroot}", "-ffunction-sections", "-fdata-sections")
1583+
if ($DebugInfo) {
15571584
$CXXFLAGS += @("-gdwarf")
15581585
}
15591586
Add-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFLAGS
@@ -2410,7 +2437,6 @@ function Build-Runtime([Hashtable] $Platform) {
24102437
SWIFT_NATIVE_SWIFT_TOOLS_PATH = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildPlatform Compilers), "bin"));
24112438
SWIFT_PATH_TO_LIBDISPATCH_SOURCE = "$SourceCache\swift-corelibs-libdispatch";
24122439
SWIFT_PATH_TO_STRING_PROCESSING_SOURCE = "$SourceCache\swift-experimental-string-processing";
2413-
CMAKE_SHARED_LINKER_FLAGS = if ($Platform.OS -eq [OS]::Windows) { @("/INCREMENTAL:NO", "/OPT:REF", "/OPT:ICF") } else { @() };
24142440
})
24152441
}
24162442

0 commit comments

Comments
 (0)