On Mon, 24 Oct 2022, Mark Harmstone wrote:

Both current lld and the next version of ld have an option -pdb, which
creates a PDB file which Microsoft's debuggers can use. This patch adds
a -gcodeview option, which passes this to the linker.

I do intend to expand this so it also creates the .debug$S and .debug$T
sections which would make this useful - I submitted patches for this a
while back, but they need to be rewritten to parse the DWARF DIEs rather
than using debug_hooks.

Clang also has -gcodeview, but AFAICS only uses it for .debug$S and
.debug$T, and doesn't use it for linker options (though IMO it probably
should).

That's true - in Clang, this option doesn't affect linking, it only affects code generation.

(FWIW, if I understand it correctly, Clang also does support generating both DWARF and CodeView at the same time - I think that would require passing something like "-g -gdwarf-4 -gcodeview" at the same time - but I don't have experience with playing with such setups.)

Another vague oddity in how this option is handled in Clang, is that if I only pass "-gcodeview" to the compiler, it doesn't actually generate any debug info (it just changes preference, in case I would request debug info separately), while one has to pass e.g. "-g -gcodeview" for it to do what's expected. I'm not sure if this is the same with dwarf, or if passing "-gdwarf-4" is enough for actually enabling generating dwarf debug info too. In any case, I don't think this aspect needs to be matched closely (unless dwarf does the same), as any existing users of PDB generation do use "-g -gcodeview", so as long as that case works, there shouldn't be any interop issues.

---
gcc/common.opt      | 4 ++++
gcc/doc/invoke.texi | 7 +++++++
gcc/gcc.cc          | 4 ++++
gcc/opts.cc         | 3 +++
4 files changed, 18 insertions(+)

@@ -4608,6 +4608,10 @@ driver_handle_option (struct gcc_options *opts,
      do_save = false;
      break;

+    case OPT_gcodeview:
+      add_infile ("-pdb=", "*");
+      break;

Hmm, what does this end up passing to the linker in the end - does it just pass "-pdb="? (What does the "*" parameter do here?) If that's the case - that sounds reasonable - assuming that if a user passes an extra -Wl,--pdb,myspecificname.pdb, that would take precedence (i.e. be passed after the compiler's default one).

// Martin

Reply via email to