-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile, cmd/link: generate dwarf type info in compiler #52209
Comments
Change https://go.dev/cl/398735 mentions this issue: |
There is no user visible change here (except that debug info is better), so this doesn't have to go through the proposal process. The linker/compiler/runtime team can decide what to do here. CC @golang/runtime |
I will send CL tree to implement it formally. |
Change https://go.dev/cl/399059 mentions this issue: |
Change https://go.dev/cl/399294 mentions this issue: |
Change https://go.dev/cl/399062 mentions this issue: |
Change https://go.dev/cl/399295 mentions this issue: |
Change https://go.dev/cl/399063 mentions this issue: |
Change https://go.dev/cl/399064 mentions this issue: |
Change https://go.dev/cl/399296 mentions this issue: |
Change https://go.dev/cl/399297 mentions this issue: |
Change https://go.dev/cl/399298 mentions this issue: |
Change https://go.dev/cl/399301 mentions this issue: |
Change https://go.dev/cl/399302 mentions this issue: |
@zhouguangyuan0718 thanks for writing this up and sending a first set of patches. Let me know when they are ready for review. Moving type generation from linker to compiler is definitely a worthy project. If I were doing this work myself, there are some other cleanups I would also consider folding in as well. Specifically:
With that said, these cleanups are independent and can be tackled separately at some future time. |
Change https://go.dev/cl/399275 mentions this issue: |
@thanm thanks for your reply. I'm glad to know it is a worthy project. I want to cleanups something, too. I didn't add duplicate code in compiler, I moved some code from linker to cmd/internal/dwarf. We can use them in both compiler and linker. In the future, it can be unified more easy. |
I took a very quick skim. In general looks to be moving in the right direction. I am not sure about https://go-review.googlesource.com/c/go/+/399302 however-- what is the purpose of making DWARF type die symbols into aux symbols attached to type symbols? If the type DIE symbol is an aux, it means you can't look it up by name. This seems to me that it will force a lot of rewriting/post-processing in the linker. |
Sorry, maybe I use a incorrect combine of aux and pkgDef for dwarf sym? It seems I can still look it up by name now. And I can also get them by aux of a type symbol.
According to the understanding I described above, I hope that all the dwarf type can be collected by using aux sym of reachable gotype and traverse the relocs of them at last. May be it is more fast than name lookup. If I missed something which can prevent doing as this, I will put them in data. |
Change https://go.dev/cl/399877 mentions this issue: |
It doesn't really make sense to have a symbol that is both aux and pkgdef -- the primary reason we make the other DWARF sub-symbols (ex: DWARFLINES, DWARFFCN) is that we never have to look them up by name. Better to have the DWARF type DIE symbols just be regular named symbols. |
Thank you for explanation. Maybe dealing with the reloction of them correctly is a little dificult. I met many problem about relocations at the beginning. Particularly, some dwarf type symbol are nameless and duplicate. However, I will try to make them as regular symbols continue. The other thing I can't do with certainty is CL 399877. Should I do it like this? Or put them into cmd/compile/internal/typecheck/builtin, then fix mkbuiltin.go and deal with them by a common way? Could you give me some advice? |
Change https://go.dev/cl/400874 mentions this issue: |
Hi! @thanm , I have refactored my work tree. I remove much transitional code. And make changes aggregated in every cl. I think it will be more easy to review. |
Dwarf type info can be generated based on the abstract type. We can make it to be independent of specific implement. And define a TypeContext interface to provide some base method during dwarf type info generating. For golang#52209 Change-Id: I4d8fd3c19bcb9a22cdb037fb5f2b05e1a5907e23
Implement cmd/internal/dwarf.Type interface fpr cmd/compile/internal/types.Type with a wrapper. For golang#52209 Change-Id: I46ce4735bfcf900d9e17c14b6f69ea542eac0a8a
…r dwCtxt Only generate type info for types defined in current compile unit. So only emit a reloc for subtype when reference it. For golang#52209 Change-Id: If723e0d9588c1e82cf1a129ac4c8ec7eb3b1d98
To generate dwarf type info in compiler, I copy some functions in cmd/link/internal/ld/dwarf.go to cmd/internal/dwarf, and refactor them to be independent of linker. No functional change now. They will be used in compiler later. And the duplicate code in linker will be removed at last. For golang#52209 Change-Id: I10c9bbaf530f84f3fe4d94687a9325b665a7a9ce
cmd/link/internal/ld/dwarf.go:/^func.newtype --> cmd/internal/dwarf/dwarf.go:/^func.NewType And refactor it to adapt Type interface. newtype in cmd/link/internal/ld/dwarf.go will be removed at last. For golang#52209 Change-Id: Ie95eff712418ee454a9c3887dcd7e7488a42b011
Generate dwarf type info and dump it to objfile. It is not be used in linker now. Some types need to be synthesized. I will resolve it in next CLs. For golang#52209 Change-Id: Ie7c67197f930462ae4474f291e02d3009b6651bc
These functions are copied from cmd\link\internal\ld\dwarf.go. Refactor them to adapt Type and TypeContext interface. For golang#52209 Change-Id: I27831f65f998f5bc100182f598be25870ac916da
These code is also copied and refactored from cmd/link/internal/ld/dwarf.go For golang#52209 Change-Id: I58f6c401898c2d3350fdf51d17ca059ec829dfa5
To synthesize dwarf type in compiler, the prototype of string, map, slice, channel is needed. It can't be easily got when compile the code out of runtime. So use add them to builtin so we can get the prototype information. More detailed explanation: When a map(eg: map[int]int) is used, we need more dwarf type info than we can see in language level. The pseudo type hash<int,int>, bucket<int,int>, []val<int> and []key<int> will be generated for debug more easy. They are "template" type, we need to fill them when a map is instantiated. And we can't define these type directly by exist go runtime type. So they should be added to buitin for filling the "template" when generating the dwarf type info of them. So does others. See golang#52209 (comment) For golang#52209 Change-Id: Ifcb1e15d2300323980b320673adb67df2ee07956
Now, we can synthesize types in compiler. And all the dwarf type sym can be kept by relocs. subtype in linker can be removed now. There is some undifined relocs to runtime type in dwarf type. These relocs are added by compiler, it don't know the corresponding runtime type will be defined or not. So skip them in relocsym. For golang#52209 Change-Id: Ief7683f8d9033ebf0f682f582e2fffde63587bf0
It's time to begin using the dwarf type info generated by compiler in linker. For golang#52209 Change-Id: Ic12f4ed1f510454880d6ef9c8608b405c5404a92
Now, all the dwarf type info is generated in compiler, it is not necessary to keep these code in linker, remove it. For golang#52209 Change-Id: I9cfe253bd4b4ea7d93d0c4cfbf6d309f566f4552
…fo when -linkshared Now, all the dwarf type can be generated by compiler, when using static link, every compiler unit generate its own dwarf type die. when using -linkshared, all the types current compile unit need can be collected. So we can generate corresponding dwarf type info for it and subtypes of it. For synthesizetype, we also need to keep the type info of them when linkshared For golang#52209 Change-Id: Ia70ba39708ce710c45d923d5b86dac91d7e9d616
Thanks. I'll take a look once I clear up some time. |
Change https://go.dev/cl/402258 mentions this issue: |
Change https://go.dev/cl/403334 mentions this issue: |
Still tied up with pre-release-freeze development work. Hope to look at this next week. |
Change https://go.dev/cl/404217 mentions this issue: |
Thanks, and I wonder if it is possible to be merged into 1.19? If it is possible, I will do the remain things as soon as possible. |
Change https://go.dev/cl/404734 mentions this issue: |
Change https://go.dev/cl/404754 mentions this issue: |
Change https://go.dev/cl/404755 mentions this issue: |
Change https://go.dev/cl/405455 mentions this issue: |
@thanm , Sorry for delay. I have rebased and solved confliction. Then I solved some comments. Can we continue to review these and make it more closer to merging? |
One observation is that all of the types of a go program appear in compile units called |
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:
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:
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:
Costs
Longer. But it will not much because of parallel compile. And maybe we can get a shorter link time.
No cost.
Above
Yes.
Update 2022.5.10:
List an intial version todo list for formal modification:
The text was updated successfully, but these errors were encountered: