-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
CC: @minux @ianlancetaylor @crawshaw
cmd/link and debug/pe share no common code, but they should - they do the same thing. If package debug/pe is worth its weight, it should be used by cmd/link. I accept that this was impossible to do when cmd/link was a C program, but now cmd/link is written in Go.
I also tried to use debug/pe in github.com/alexbrainman/goissue10776/pedump, and it is not very useful. I endup coping and changing some debug/pe code.
I also think there is some luck of PE format knowledge between us. So improving debug/pe structure and documentation should help with that.
I tried to rewrite src/cmd/link/internal/ld/ldpe.go by using debug/pe (see CL 14289). I had to extend debug/pe for that task. Here is the list of externally visible changes I had to do:
- PE relocations have SymbolTableIndex field that is an index into symbols table. But File.Symbols slice has Aux lines removed as it is built, so SymbolTableIndex cannot be used to index into File.Symbols. We cannot change File.Symbols behavior. So I propose we introduce File.COFFSymbols slice that is like File.Symbols, but with Aux lines left untouched.
- I have introduced StringTable that was used to convert long names in PE symbol table and PE section table into Go strings.
- I have also introduced Section.Relocs to access PE relocations.
I propose we add the above things to debug/pe and use new debug/pe to rewrite ldpe.go and pe.go in cmd/link/internal/ld.
Alex
PS: You can google for pecoff.doc for PE detials.