Skip to content

Commit c316e93

Browse files
authored
Merge pull request #83521 from Steelskin/fabrice/utils-update-debug-flags
utils: Update debug flags
2 parents e9f19fc + e2d82f1 commit c316e93

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

utils/build.ps1

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,19 @@ function Build-CMakeProject {
13661366
Add-KeyValueIfNew $Defines CMAKE_ASM_COMPILER $ASM
13671367
Add-KeyValueIfNew $Defines CMAKE_ASM_FLAGS @("--target=$($Platform.Triple)")
13681368
Add-KeyValueIfNew $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "/MD"
1369+
1370+
if ($DebugInfo) {
1371+
$ASMDebugFlags = if ($CDebugFormat -eq "dwarf") {
1372+
if ($UseGNUDriver) { @("-gdwarf") } else { @("-clang:-gdwarf") }
1373+
} else {
1374+
if ($UseGNUDriver) { @("-gcodeview") } else { @("-clang:-gcodeview") }
1375+
}
1376+
1377+
# CMake does not set a default value for the ASM compiler debug
1378+
# information format flags with non-MSVC compilers, so we explicitly
1379+
# set a default here.
1380+
Add-FlagsDefine $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_Embedded $ASMDebugFlags
1381+
}
13691382
}
13701383

13711384
if ($UseASM_MASM) {
@@ -1505,25 +1518,31 @@ function Build-CMakeProject {
15051518
Add-FlagsDefine $Defines CMAKE_Swift_FLAGS_RELWITHDEBINFO "-O"
15061519
}
15071520

1521+
$LinkerFlags = if ($UseGNUDriver) {
1522+
@("-Xlinker", "/INCREMENTAL:NO", "-Xlinker", "/OPT:REF", "-Xlinker", "/OPT:ICF")
1523+
} else {
1524+
@("/INCREMENTAL:NO", "/OPT:REF", "/OPT:ICF")
1525+
}
1526+
15081527
if ($DebugInfo) {
15091528
if ($UseASM -or $UseC -or $UseCXX) {
15101529
# Prefer `/Z7` over `/ZI`
1530+
# By setting the debug information format, the appropriate C/C++
1531+
# flags will be set for codeview debug information format so there
1532+
# is no need to set them explicitly above.
15111533
Add-KeyValueIfNew $Defines CMAKE_MSVC_DEBUG_INFORMATION_FORMAT Embedded
15121534
Add-KeyValueIfNew $Defines CMAKE_POLICY_DEFAULT_CMP0141 NEW
1513-
if ($UseASM) {
1514-
# The ASM compiler does not support `/Z7` so we use `/Zi` instead.
1515-
Add-FlagsDefine $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_Embedded "-Zi"
1516-
}
15171535

1518-
if ($UseGNUDriver) {
1519-
Add-FlagsDefine $Defines CMAKE_EXE_LINKER_FLAGS @("-Xlinker", "-debug")
1520-
Add-FlagsDefine $Defines CMAKE_SHARED_LINKER_FLAGS @("-Xlinker", "-debug")
1536+
$LinkerFlags += if ($UseGNUDriver) {
1537+
@("-Xlinker", "/DEBUG")
15211538
} else {
1522-
Add-FlagsDefine $Defines CMAKE_EXE_LINKER_FLAGS @("/debug")
1523-
Add-FlagsDefine $Defines CMAKE_SHARED_LINKER_FLAGS @("/debug")
1539+
@("/DEBUG")
15241540
}
15251541
}
15261542
}
1543+
1544+
Add-FlagsDefine $Defines CMAKE_EXE_LINKER_FLAGS $LinkerFlags
1545+
Add-FlagsDefine $Defines CMAKE_SHARED_LINKER_FLAGS $LinkerFlags
15271546
}
15281547

15291548
Android {
@@ -1541,8 +1560,8 @@ function Build-CMakeProject {
15411560
if ($UseC) {
15421561
Add-KeyValueIfNew $Defines CMAKE_C_COMPILER_TARGET $Platform.Triple
15431562

1544-
$CFLAGS = @("--sysroot=${AndroidSysroot}")
1545-
if ($DebugInfo -and ($CDebugFormat -eq "dwarf")) {
1563+
$CFLAGS = @("--sysroot=${AndroidSysroot}", "-ffunction-sections", "-fdata-sections")
1564+
if ($DebugInfo) {
15461565
$CFLAGS += @("-gdwarf")
15471566
}
15481567
Add-FlagsDefine $Defines CMAKE_C_FLAGS $CFLAGS
@@ -1551,8 +1570,8 @@ function Build-CMakeProject {
15511570
if ($UseCXX) {
15521571
Add-KeyValueIfNew $Defines CMAKE_CXX_COMPILER_TARGET $Platform.Triple
15531572

1554-
$CXXFLAGS = @("--sysroot=${AndroidSysroot}")
1555-
if ($DebugInfo -and ($CDebugFormat -eq "dwarf")) {
1573+
$CXXFLAGS = @("--sysroot=${AndroidSysroot}", "-ffunction-sections", "-fdata-sections")
1574+
if ($DebugInfo) {
15561575
$CXXFLAGS += @("-gdwarf")
15571576
}
15581577
Add-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFLAGS
@@ -2417,7 +2436,6 @@ function Build-Runtime([Hashtable] $Platform) {
24172436
SWIFT_NATIVE_SWIFT_TOOLS_PATH = ([IO.Path]::Combine((Get-ProjectBinaryCache $BuildPlatform Compilers), "bin"));
24182437
SWIFT_PATH_TO_LIBDISPATCH_SOURCE = "$SourceCache\swift-corelibs-libdispatch";
24192438
SWIFT_PATH_TO_STRING_PROCESSING_SOURCE = "$SourceCache\swift-experimental-string-processing";
2420-
CMAKE_SHARED_LINKER_FLAGS = if ($Platform.OS -eq [OS]::Windows) { @("/INCREMENTAL:NO", "/OPT:REF", "/OPT:ICF") } else { @() };
24212439
})
24222440
}
24232441

@@ -2874,7 +2892,7 @@ function Test-XCTest {
28742892
-Src $SourceCache\swift-corelibs-xctest `
28752893
-Bin (Get-ProjectBinaryCache $BuildPlatform XCTest) `
28762894
-Platform $BuildPlatform `
2877-
-UseBuiltCompilers Swift `
2895+
-UseBuiltCompilers C,CXX,Swift `
28782896
-SwiftSDK $null `
28792897
-BuildTargets default,check-xctest `
28802898
-Defines @{

0 commit comments

Comments
 (0)