[llvm] [RFC] Emit dwarf data for signature-changed or new functions (PR #157349)

Vladislav Dzhidzhoev via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 23 05:08:57 PDT 2025


dzhidzhoev wrote:

> I am not really familiar with DW_AT_trampoline.

Honestly, I'm not familiar with trampolines as well, I am just curious whether they may come in handy in that case.

> First, let us say the function 'foo' has its signature changed. With the above, we will have two DW_TAG_subprogram's which has the same name 'foo'. This will cause confusion. One option is to directly replace the _old_ signatures with _new_ signature. But the existing DW_TAG_subprogram has been parsed/used in many tools. Changing signature might cause issues for those tools.

AFAIK, debuggers/tools do not rely that much on DW_AT_name, as it is a source-language name (and it's not guaranteed to be unique, as, for example, for overloaded functions in C++). To distinguish between different compiled functions, DW_AT_linkage_name should be used.
I think, regardless of what tag is used for new/updated functions (DW_TAG_subprogram+DW_AT_trampoline or DW_TAG_inlined_subprogram), DISubprograms for these functions should have proper "linkageName:" set, matching the function name in LLVM (it can be done here https://github.com/yonghong-song/llvm-project/blob/15c7a0e17bf964c9f0474c1bd4225acc9f2034bf/llvm/lib/Transforms/Utils/EmitChangedFuncDebugInfo.cpp#L306).


> Second, some tools may not be aware of DW_AT_trampoline so they may parse DW_TAG_subprogram the same as other existing DW_TAG_subprogram's and this may have some side effects on their results.

It could be a case. In order to avoid that, I'd change EmitChangedFuncDebugInfo in the following way:
1. When a mismatch between function arguments/return type and original DISubprogram's arguments/return type is detected, a new "trampoline" DISubprogram should be created, which will have updated arguments/return type.
2. A new "trampoline" DISubprogram should be attached to the function _instead_ of the original one (but the trampoline subprogram preserves the name/linkage name of the original subprogram in targetFuncName field).
3. All DILocations of the function should be updated in the way as if the original DISubprogram is "inlined" into the "trampoline" DISubprogram, simliarly to what is done in llvm/lib/Transforms/Utils/InlineFunction.cpp:{fixupLineNumbers, fixupAssignments} (probably we can just reuse functions of InlineFunction.cpp).
4. As the result, we should have the following DIEs:
- An abstract DIE for the original DISubprogram with original arguments/return type.
- Concrete DIE for the "trampoline" DISubprogram, having DW_AT_linkage_name, DW_AT_low_pc, DW_AT_high_pc corresponding to the function with modified arguments/return type, and with a children DW_TAG_inlined_subproutine, which will refer to abstract DIE of the original DISubprogram.
If DISubprogram and the related metadata is updated according to (1)-(3), no changes will be needed to achieve (4), IMO.

That's how I would approach that, but I'd also ask for the opinion of more experienced community members :)

https://github.com/llvm/llvm-project/pull/157349


More information about the llvm-commits mailing list