gas: Mark weak functions as external in DWARF
Discussion on correctly marking weak functions as external in DWARF debug information generated by GAS.
This discussion revolves around a patch for the GNU Assembler (gas) that aims to correctly represent weak functions in DWARF debug information. The proposed change modifies the DWARF generation logic to treat weak functions (using S_IS_WEAK) the same way as external functions (using S_IS_EXTERNAL) when emitting the DW_AT_external attribute. This ensures that debuggers and other tools accurately identify these functions as external, resolving PR 29517. A test case is included to verify the fix.
- reviewer
Reviews and approves the patch, finding the logic for marking weak functions as external in DWARF debug info to be correct.
“This part certainly is okay, but ...”
- proposer
Proposes modifying DWARF generation in GAS to include weak functions when determining `have_efunc` and setting `DW_AT_external`.
“if (S_IS_EXTERNAL (symp) || S_IS_WEAK (symp)) have_efunc = true; else have_lfunc = true;”
In Details
This patch for gas addresses DWARF debugging information generation for weak functions. Specifically, it modifies out_debug_abbrev and out_debug_info to consider symbols marked with S_IS_WEAK as equivalent to S_IS_EXTERNAL when setting the DW_AT_external attribute. This ensures that weak functions are correctly flagged as external entities in the generated debug information, resolving a problem (PR 29517) where they might otherwise be misinterpreted. A new test case dwarf-3-func-weak.d is added.
- gas
- The GNU Assembler, part of the GNU Binutils package, responsible for converting assembly language code into machine code.
- DWARF
- Debugging With Attributed Record Formats, a standardized debugging data format used by many compilers and debuggers.
- weak function
- A function that has a default definition but can be overridden by another definition elsewhere. The linker typically resolves weak symbols to the strongest available definition.
- external symbol
- A symbol that is defined in a different compilation unit (e.g., another object file or library) and must be resolved by the linker.
- DW_AT_external
- A DWARF attribute indicating that a symbol (e.g., a function or variable) is external, meaning it is defined elsewhere.
- PR 29517
- A reference to a specific bug report (Problem Report) filed in the GNU Binutils issue tracker.