-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/link: windows cgo executables missing some DWARF information #10776
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
Comments
Does PE's .o format have a way to put DWARF information into the object? |
I don't know. But we're not talking about some "general" PE's .o format. We're using mingw here, so it is about what mingw requires. I am certain mingw compiled .o files do contain DWARF information. When we build cgo with hostlink=internal, we get .o files produced by mingw that contain DWARF. I can see C symbols during debugging. But I don't know what the format is. I tried to see why we don't generate DWARF symbols, and I didn't get very far. I have applied this change:
to restore writing of DWARF sections for when Linkmode == LinkExternal. And I can see Go DWARF info is stored in the exe now:
But DWARF info looks corrupted (see objdump warnings). And gdb complains about it too:
I tried reading DWARF info with our debug/dwarf package (similar to TestDWARF in debug/pe), and it does not complain about anything. I don't have any great ideas about this. Perhaps next step would be to understand why gdb and objdump complain. So I need to download their source and build them. Do you have anything better? Alex |
DWARF goes into PE exactly as for ELF: in sections with special names that the debugger looks for. The debug/pe package can even find the DWARF info. @alexbrainman To make this work for external linking, you really can't skip the generation of the external reloc. I'm going to move this to unplanned. It would be great if somebody wants to work on it, but I think it's too late for 1.5. |
My latest investigations are here https://go-review.googlesource.com/#/c/13571 Alex |
Adding Go1.6 label. I believe this was working in go1.4, but is broken now. In the hope that others will help .. Alex |
Looks like help did not arrive. |
Looks like this didn't land in Go 1.6... Any hopes for Go 1.7? |
I didn't have time to work on this. Alex |
I am not sure about Max OSX, but yes it is currently broken on Windows.
Correct.
Correct.
I do not know of any documentation, but https://golang.org/pkg/cmd/link/. But (the way I understand it), the -linkmode flag specifies if cmd/link links final executable itself (internal), or calling external linker - gcc (external). This current issue (issue #10776) is that when -linkmode=external is used, final executable does not includes DWARF information - it means it cannot be debugged properly. Also -linkmode=external setting is default - if you don't pass -linkmode flag, then it will be set to external on Windows. So any Windows cgo executable have no debug information by default. I hope it helps. Alex |
@alexbrainman We can pick internal or external linking mode until after all the input files have been seen. But from a quick look, I don't think the three values you mention are actually used in any way until after the link mode is set anyhow. That is, they are currently set in |
Peinit is called from archinit: https://github.com/golang/go/blob/master/src/cmd/link/internal/amd64/obj.go#L145-L156 I can, probably, add code in Asmbpe that sets HEADR, FlagTextAddr, FlagRound as well as PESECTHEADR, PESECTALIGN and PEFILEALIGN, but I am not sure what other global variables or state did I miss. Sounds too easy to break in the future. I was hoping we could move call to archinit after loadlib or something. Or maybe split archinit into 2 parts. Or maybe call archinit twice - before loadlib call and after. Thank you. Alex |
Calling Anyhow, This kind of code is definitely easy to break. That is the nature of our current linker: we set values in one place and use them in another, and it's hard to see the connections between the two and it's hard to be certain that the place where we set the value always runs before the place where we use the value. Perhaps we need to add a set-once, use-many type that gives an error on a second set or on a set after a use. |
I had a quick look and I think ld.HEADR, ld.FlagTextAddr, ld.FlagDataAddr and ld.FlagRound can be made private, they are set in archinit and then used in ld package only. Might make this whole thing look less scary. Alex |
CL https://golang.org/cl/36983 mentions this issue. |
CL https://golang.org/cl/36978 mentions this issue. |
CL https://golang.org/cl/36979 mentions this issue. |
CL https://golang.org/cl/36977 mentions this issue. |
CL https://golang.org/cl/36975 mentions this issue. |
CL https://golang.org/cl/36980 mentions this issue. |
CL https://golang.org/cl/36976 mentions this issue. |
CL https://golang.org/cl/36974 mentions this issue. |
CL https://golang.org/cl/36973 mentions this issue. |
CL https://golang.org/cl/36981 mentions this issue. |
CL https://golang.org/cl/36982 mentions this issue. |
For #10776. Change-Id: I7931558257c1f6b895e4d44b46d320a54de0d677 Reviewed-on: https://go-review.googlesource.com/36973 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This is what gcc does when it generates object files. And it is easier to count everything, when it starts from 0. Make go linker do the same. gcc also does not output IMAGE_OPTIONAL_HEADER or PE64_IMAGE_OPTIONAL_HEADER for object files. Perhaps we should do the same, but not in this CL. For #10776. Change-Id: I9789c337648623b6cfaa7d18d1ac9cef32e180dc Reviewed-on: https://go-review.googlesource.com/36974 Reviewed-by: Ian Lance Taylor <iant@golang.org>
For #10776. Change-Id: Id64a7e35c7cdcd9be16cbe3358402fa379090e36 Reviewed-on: https://go-review.googlesource.com/36975 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This is what gcc does when it generates object files. And pecoff.doc says: "for simplicity, compilers should set this to zero". It is easier to count everything, when it starts from 0. Make go linker do the same. For #10776. Change-Id: Iffa4b3ad86160624ed34adf1c6ba13feba34c658 Reviewed-on: https://go-review.googlesource.com/36976 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Introduce a slice that keeps long pe section names as we add them. It will be used later to output pe symbol table and dwarf relocations. For #10776. Change-Id: I02f808a456393659db2354031baf1d4f9e0b2d61 Reviewed-on: https://go-review.googlesource.com/36977 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
dwarf relocations refer to dwarf section symbols, so dwarf section symbols must be present in pe symbol table before we write dwarf relocations. .ctors pe section already refer to .text symbol. Write all pe section name symbols into symbol table, so we can use them whenever we need them. This CL also simplified some code. For #10776. Change-Id: I9b8c680ea75904af90c797a06bbb1f4df19e34b6 Reviewed-on: https://go-review.googlesource.com/36978 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
The symbols get in a way when using external linker. They are not associated with a section. And linker fails when generating relocations for them. __image_base__ and _image_base__ have been added long time ago. I do not think they are needed anymore. If I delete them, all tests still PASS. I tried going back to the commit that added them to see if I can reproduce original error, but I cannot build it. I don't have hg version of go repo, and my gcc is complaining about cc source code. I wasted too much time with this, so I decided to leave them only for internal linker. That is what they were originally added for. For #10776. Change-Id: Ibb72b04f3864947c782f964a7badc69f4b074e25 Reviewed-on: https://go-review.googlesource.com/36979 Reviewed-by: Ian Lance Taylor <iant@golang.org>
dwarf writing code assumes that dwarf sections follow .data and .bss, not .ctors. Make pe section writing code match that assumption. For #10776. Change-Id: I128c3ad125f7d0db19e922f165704a054b2af7ba Reviewed-on: https://go-review.googlesource.com/36980 Reviewed-by: Ian Lance Taylor <iant@golang.org>
No functional changes. For #10776. Change-Id: If9a5ef832af116c5802b06a38e0c050d7363f2d5 Reviewed-on: https://go-review.googlesource.com/36981 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
For #10776. Change-Id: I11dd441d8e5d6316889ffa8418df8b58c57c677d Reviewed-on: https://go-review.googlesource.com/36982 Reviewed-by: Ian Lance Taylor <iant@golang.org>
In issue #4069 @minux said:
I don't know the details. I am just creating this so we don't forget.
Alex
The text was updated successfully, but these errors were encountered: