-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
Background
I have focused on dynamic link (plugin,linkshared,buildemode-shared) in golang for two years. I noticed that the dynlink library can't be debuged. And I know that the reason of it is the dwarf type info is generated in linker.
Related issues:
#38378
#44982
Later, I saw this in #47788 (comment).
@thanm said:
One thing we can do that would make the problem more tractable in general would be to move DWARF type DIE generation out of the linker and into the compiler (this is an idea that we've toyed with the in the past but haven't gotten to). Doing that would definitely help for the "link shared against libstd.so" use case.
Thanks for @thanm , I have tried to implement generating dwarf type info in compile for a long time. Now it can work, though it is a very very initial version. I think it is the correct time to submit a proposal about it, and maybe I can improve it and contribute it to go community.
Proposal
The dwarf type info can be generated in compiler instead of linker. My initial version implement it with this way:
- We can collect all the types (global var, local var, const and the type which runtime type should be keeped) used in current compile unit.
- Do "defgotype" like the linker now. And we don't need to decode the infomation from binary like linker, we only need to get the info from types.Type struct in compile.
- Synthesize map type, chan type and soon. Because some proto type (runtime.hchan, runtime.hmap...) are not in current compile unit, we must make some "stub" type of them.
- Before dumpobj in compiler, convert all the type dies to LSym and put them to data section.
I will send a CL to share my very very initial prototype.
If this proposal is a little likely to be accepted, I will implement it continue. I think thers is much things todo.
TODO:
- Clarify the dwarf symbol name and type name.
- Use aux sym for typedef sym instead of lookup it by name.
- Investigate why fixedbugs/ssue30908.go failed. It seems like there is some different duplicate dwarf symbols.
- Distinguish linkshared and static link. For linkshared, generate completely dwarf types for every compile unit. For static link, only generate dwarf types that defined in current compile unit.Then the user who use -linkshared, They could debug the dynlink library.
Costs
- What is the compile time cost?
Longer. But it will not much because of parallel compile. And maybe we can get a shorter link time. - What is the run time cost?
No cost. - Can you describe a possible implementation?
Above - Do you have a prototype? (This is not required.)
Yes.
Update 2022.5.10:
List an intial version todo list for formal modification:
- Implement some base interface for dwarf in compiler
- generate dwarf info sym for the type (except the type need to be synthesized) defined in current compile unit in compier.
- Create some type description for synthesize type in compiler, thus we can generate and synthesize more type info in compiler.
- add some util functiong for synthesizing type.
- synthesize ptr, hchan, hmap, string and slice in compiler.
- use the dwarf sym generated in compiler in linker.
- cleanup some redundancy and duplicate code
- generate whole dwarf type info in compiler for dynlink.
- do not generate the types which must be emited by runtime
- add a new reloc type for using aux symbol for type info
- refactor and optimize the DWDIE struct to reduce the pointer
- unify the die create way in internal/dwarf
- add testcases for these cls