From aa8020ac132f3d115c6caf955481f91be08b5474 Mon Sep 17 00:00:00 2001 From: Fabien Sanglard Date: Fri, 9 Aug 2024 18:19:11 -0700 Subject: [PATCH] Always generate PDB for Windows executable Test: NA Bug: 350154912 Change-Id: I0a4ebfb62643eb2c8d2b20992e728bcb8b5219a9 --- cc/builder.go | 11 +++++++++++ cc/config/x86_windows_host.go | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/cc/builder.go b/cc/builder.go index a05a16dcb..cd535c1e8 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -22,6 +22,7 @@ import ( "fmt" "path/filepath" "runtime" + "slices" "strconv" "strings" @@ -910,6 +911,16 @@ func transformObjToDynamicBinary(ctx android.ModuleContext, "ldFlags": flags.globalLdFlags + " " + flags.localLdFlags, "crtEnd": strings.Join(crtEnd.Strings(), " "), } + + // On Windows, we always generate a PDB file + // --strip-debug is needed to also keep COFF symbols which are needed when + // we patch binaries with symbol_inject. + if ctx.Windows() { + pdb := outputFile.ReplaceExtension(ctx, "pdb") + args["ldFlags"] = args["ldFlags"] + " -Wl,--strip-debug -Wl,--pdb=" + pdb.String() + " " + implicitOutputs = append(slices.Clone(implicitOutputs), pdb) + } + if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CXX_LINKS") { rule = ldRE args["implicitOutputs"] = strings.Join(implicitOutputs.Strings(), ",") diff --git a/cc/config/x86_windows_host.go b/cc/config/x86_windows_host.go index 1e61b01d0..ea7d3426a 100644 --- a/cc/config/x86_windows_host.go +++ b/cc/config/x86_windows_host.go @@ -43,6 +43,10 @@ var ( "-mno-ms-bitfields", "--sysroot ${WindowsGccRoot}/${WindowsGccTriple}", + + // Windows flags to generate PDB + "-g", + "-gcodeview", } windowsIncludeFlags = []string{