codeview: Use switch_to_section for .debug$S and .debug$T
Ensures correct assembler section tracking in CodeView debug info generation.
This commit modifies the CodeView debug info generation to use switch_to_section for .debug$S and .debug$T sections. Previously, directly manipulating the assembler’s section could lead to incorrect state tracking (in_section), causing errors like ‘can’t resolve .debug$T - .Ltext0’. Using switch_to_section maintains the correct current section, resolving these issues and ensuring proper debug information generation.
In Details
The CodeView backend's write_custom_types and codeview_debug_finish functions now use targetm.asm_out.switch_to_section instead of directly calling targetm.asm_out.named_section. This change is crucial because named_section updates the assembler's internal section state without updating GCC's in_section variable. This discrepancy can lead to output being directed to the wrong section, causing link-time errors, particularly when generating debug information with -gcodeview -g.
- CodeView
- A proprietary debug information format developed by Microsoft, commonly used with Windows executables. GCC supports generating CodeView debug information.
- .debug$S
- A section in CodeView debug information that typically stores type information.
- .debug$T
- A section in CodeView debug information that typically stores type information, often related to C++ templates or other complex types.
- switch_to_section
- A GCC internal function that attempts to switch the assembler's current output section, while also updating GCC's internal tracking of the current section (
in_section). - in_section
- An internal GCC variable that tracks the assembler's currently active output section.